This is a two state Markov model - modelling smoking cessation - it was adapted from reference_two_state_markov to use the SpeedyMarkov framework. It essentially contains a list of functions that are then used to sample a markov model that can then be simulated and analysed. Unlike reference_two_state_markov this is not a standalone analysis pipeline but instead represents a model definition.

example_two_state_markov()

Value

A named list of functions that all require a samples argument and pass additional arguments (using ...). The list contains:

  • transitions_list: a list of transition functions, with the first taking the number of samples as an argument and the following being dependent on the a previous transition.

  • qalys: a function that samples the qaly cost for each intervention.

  • intervention_costs: a function that returns the costs for each intervention.

  • state_costs: a function that returns the state costs for each intervention.

  • cohorts: a function that returns the initial state for each intervention.

Please see the code for more details on each required list item.

Examples

## Example model run example_two_state_markov()
#> $transitions_list #> $transitions_list$SoC #> function (samples = NULL, ...) #> { #> tmp <- list(VGAM::rdiric(samples, c(88, 12)), VGAM::rdiric(samples, #> c(8, 92))) #> tmp <- SpeedyMarkov::matrix_arrange(tmp, ...) #> return(tmp) #> } #> <bytecode: 0x9019610> #> <environment: 0xab4d948> #> #> $transitions_list$`Soc with Website` #> function (baseline = NULL, ...) #> { #> samples <- length(baseline) #> new_row_sample <- VGAM::rdiric(samples, c(85, 15)) #> updated <- purrr::map2(baseline, 1:samples, function(transition, #> sample) { #> transition[1, ] <- new_row_sample[sample, ] #> return(transition) #> }) #> return(updated) #> } #> <bytecode: 0x901e7c8> #> <environment: 0xab4d948> #> #> #> $qalys #> function (samples = NULL, ...) #> { #> qaly <- function(samples = 1, ...) { #> tmp <- list(stats::rnorm(samples, mean = 0.95, sd = 0.01)/2, #> rep(1/2, samples)) #> out <- SpeedyMarkov::vector_arrange(tmp) #> return(out) #> } #> soc <- qaly(samples = samples) #> soc_with_website <- soc #> out <- list(soc, soc_with_website) #> names(out) <- list("SoC", "Soc with Website") #> out <- purrr::transpose(out) #> return(out) #> } #> <bytecode: 0x901cff0> #> <environment: 0xab4d948> #> #> $intervention_costs #> function (samples = NULL, ...) #> { #> tmp <- list(rep(0, samples), rep(50, samples)) #> out <- SpeedyMarkov::vector_arrange(tmp) #> return(out) #> } #> <bytecode: 0x9020df8> #> <environment: 0xab4d948> #> #> $state_costs #> function (samples = NULL, ...) #> { #> state_cost <- function(samples = 1) { #> tmp <- list(rep(0, samples), rep(0, samples)) #> out <- SpeedyMarkov::vector_arrange(tmp) #> return(out) #> } #> soc <- state_cost(samples = samples) #> soc_with_website <- soc #> out <- list(soc, soc_with_website) #> names(out) <- list("SoC", "Soc with Website") #> out <- purrr::transpose(out) #> return(out) #> } #> <bytecode: 0x9024528> #> <environment: 0xab4d948> #> #> $cohorts #> function (samples = NULL, ...) #> { #> cohort <- function(samples = 1) { #> tmp <- list(rep(1, samples), rep(0, samples)) #> out <- SpeedyMarkov::vector_arrange(tmp) #> return(out) #> } #> soc <- cohort(samples = samples) #> soc_with_website <- soc #> out <- list(soc, soc_with_website) #> names(out) <- list("SoC", "Soc with Website") #> out <- purrr::transpose(out) #> return(out) #> } #> <bytecode: 0x902a790> #> <environment: 0xab4d948> #> #> attr(,"class") #> [1] "SpeedyMarkov" "list"