TransMatrix: Transition Matrix Estimation

Description Usage Arguments Examples

View source: R/MarkovChain.R

Description

This function allows you to estimate transition matrices (probabilities or counts) for up-to-fifth-order discrete Markov chains. For n-order Markov chains with n greater than 1, you can access the estimated transition matrices through nested lists.

Usage

1
TransMatrix(sequence, order = 1, probs = TRUE)

Arguments

sequence

A vector of integers representing the sequence. The sequence must be in the form of 1,2,3,...

order

Integer from 1 to 5. Order of the Markov chain. By default is set to 1.

probs

Logical. If TRUE probability matrices are returned, otherwise count matrices are returned. By default is set to TRUE.

Examples

1
2
3
4
5
seq <- sample(c(1,2,3,4), size = 1000, replace = TRUE)
TransMatrix(seq, order = 1, probs = TRUE)
TransMatrix(seq, order = 2, probs = FALSE)
mc <- TransMatrix(seq, order = 4, probs = TRUE)
mc[[1]][[2]][[3]] # through nested lists you can access to the estimated transition matrices

Example output

          1         2         3         4
1 0.2175732 0.2845188 0.2468619 0.2510460
2 0.2254545 0.3200000 0.2581818 0.1963636
3 0.2460938 0.2578125 0.2539062 0.2421875
4 0.2707424 0.2314410 0.2707424 0.2270742
[[1]]
   1  2  3  4
1  9 16 12 15
2 15 22 16 15
3 15 18 15 11
4 16 11 22 11

[[2]]
   1  2  3  4
1 11 20 18 13
2 20 24 24 20
3 15 19 19 18
4 15 17  9 13

[[3]]
   1  2  3  4
1 16 17 14 16
2 12 25 18 11
3 12 17 16 20
4 14 14 16 18

[[4]]
   1  2  3  4
1 16 15 15 16
2 15 17 13  8
3 21 12 15 13
4 16 11 15 10

     1         2         3         4
1 0.25 0.2500000 0.0000000 0.5000000
2 0.00 0.6666667 0.3333333 0.0000000
3 0.25 0.5000000 0.0000000 0.2500000
4 0.00 0.2857143 0.1428571 0.5714286

MCTM documentation built on May 1, 2019, 6:28 p.m.

Related to TransMatrix in MCTM...