This is a simple function that will simulate a time-homogeneous Markov chain; that is, a Markov chain with constant transition probabilities.

sim_markov_chain(x0, p, n_cycles = 85)

Arguments

x0

The state vector at model cycle 0 (i.e., the initial state vector).

p

The transition probability matrix.

n_cycles

The number of model cycles. Default is 85 as in the example from the tutorials.

Examples

x0 <- c(1, 0, 0, 0) p <- matrix( c(0.848, 0.15, 0, 0.002, 0.5, 0.395, 0.105, 0.006, 0, 0, 0.98, 0.02, 0, 0, 0, 1), byrow = TRUE, nrow = 4, ncol = 4 ) sim_markov_chain(x0 = x0, p = p, n_cycles = 2)
#> [,1] [,2] [,3] [,4] #> 0 1.000000 0.00000 0.00000 0.000000 #> 1 0.848000 0.15000 0.00000 0.002000 #> 2 0.794104 0.18645 0.01575 0.004596