Inner Markov Loop in base R

markov_loop(sim = NULL, cohort, transition = NULL, duration = NULL)

Arguments

sim

Matrix with the same number of rows as the duration of the model and the same number of columns as the number of states in the model.

cohort

A vector containing the initial state.

transition

A transition matrix, see example_two_state_markov for an example of setting this up.

duration

Numeric, how many long to run the model for.

Value

A matrix of the same size as the inputted sim matrix.

Examples

transition <- matrix(rnorm(4), 2, 2) sim <- matrix(NA, 10, 2) cohort <- c(1, 0) duration <- 10 markov_loop(sim, cohort, transition, duration)
#> [,1] [,2] #> [1,] 1.000000 0.0000000 #> [2,] -2.261042 -0.7913672 #> [3,] 6.135821 1.2623625 #> [4,] -15.506020 -4.0151122 #> [5,] 40.252689 9.5973929 #> [6,] -103.425763 -25.4639943 #> [7,] 266.783733 64.8919204 #> [8,] -687.136885 -167.9139901 #> [9,] 1770.816127 431.9678696 #> [10,] -4562.573253 -1113.7292084