Description Usage Arguments Value Examples
An inner Markov loop implemented using RcppArmadillo
1 | ArmaMarkovLoop(sim, cohort, transition, duration)
|
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 |
duration |
Numeric, how many long to run the model for. |
A matrix of the same size as the inputted sim matrix.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | transition <- matrix(rnorm(4), 2, 2)
sim <- matrix(NA, 100, 2)
cohort <- c(1, 0)
duration <- 100
# Reference R implementation
sim_r <- markov_loop(sim, cohort, transition, duration)
# RcppArmadillo implementation
sim_rcppArma <- ArmaMarkovLoop(sim, cohort, transition, duration)
# Check results are within tolerances
all.equal(sim_r, sim_rcppArma)
# Benchmark
library(microbenchmark)
microbenchmark(markov_loop(sim, cohort, transition, duration),
ArmaMarkovLoop(sim, cohort, transition, duration),
times = 1000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.