run_twig {twig}R Documentation

Run a twig model

Description

This function runs a twig model, which currently can be either a decision tree or a Markov model.

Usage

run_twig(
  twig_obj,
  params,
  n_cycles = NULL,
  verbose = FALSE,
  parallel = FALSE,
  offset_trace_cycle = 1,
  ncore = NULL,
  progress_bar = TRUE
)

Arguments

twig_obj

A twig object created by the twig function.

params

A data frame or list of parameters to be used in the model.

n_cycles

An integer specifying the number of cycles for a Markov model. Default is NULL.

verbose

A logical value indicating whether to print detailed output. Default is FALSE.

parallel

A logical value indicating whether to run the model in parallel. Default is FALSE.

offset_trace_cycle

An integer specifying the offset trace cycle. Default is 1. This is used to adjust the cycle number in the trace output. If set to 0, the initial state distribution will be used as the first cycle. If set to 1, the initial state distribution will be ignored in the Markov trace. In both situations, the total number of cycles will be the same as the input n_cycles.

ncore

An integer specifying the number of cores to use for parallel processing. Default is total number of cores - 1.

progress_bar

A logical value indicating whether to display a progress bar. Default is TRUE.

Value

A list containing the results of the model run. The list includes the following elements:

The following will also be returned if verbose is TRUE for Markov models:

The following will also be returned if verbose is TRUE for decision trees:

See Also

Getting started guide and vignettes

Examples

library(twig)

# define a Markov model twig
mytwig <- twig() +
  decisions(names = c(A,B)) +
  states(names = c(H,D),
         init_probs = c(1,0)) +
  event(name = death_event,
        options = c(yes, none),
        probs = c(pDie, leftover),
        transitions = c(D, stay)) +
  payoffs(names = c(utility))

# define the parameters
params <- list(prob_die = 0.1, rrA = 0.9)

# define vectorized functions
pDie <- function(decision, state, prob_die, rrA){
  # prob death is 0.1 if healthy and 0 otherwise
  prob_die * (state=="H") *
    # multiplied by a relative risk of 0.9 if the decision is A, and 1 otherwise
    rrA ^ (decision=="A")
}

utility <- function(state){
  1 * (state=="H") # utility is 1 if healthy and 0 otherwise
}

# run the model for 10 cycles
run_twig(mytwig, params = params, n_cycles = 10)

# see the vignettes for more examples

[Package twig version 1.0.0.0 Index]