ArmaMarkovLoop: An inner Markov loop implemented using RcppArmadillo

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

An inner Markov loop implemented using RcppArmadillo

Usage

1
ArmaMarkovLoop(sim, cohort, transition, duration)

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

 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)

seabbs/SpeedyMarkov documentation built on Dec. 26, 2019, 4:38 a.m.