This document is a presentation of the basic steps to define and run a model in
heemod. Note that decision trees are actually a subset even of Markov model, and thus can be specified easily with this package.
When building a Markov model the following steps must be performed:
The probability to transition from one state to another during a time period is called a transition probability. Said time period is called a cycle.
Transition probabilities between states can be described through a 2-way table where the lines correspond to the states at the beginning of a cycle and the columns to the states at the end of a cycle. Consider a model with 2 states
When starting a cycle in state A (row A), the probability to still be in state A at the end of the cycle is found in colunm A (cell 1) and the probability to change to state B is found in column B (cell 2).
Similarly, when starting a cycle from state B (row B), the probability to be in state A or B at the end of the cycle are found in cells 3 or 4 respectively.
In the context of Markov models, this 2-way table is called a transition matrix. A transition matrix can be defined easily in
heemod with the
define_transition() function. If we consider the previous example, where cell values have been replaced by actual probabilities:
That transition matrix can be defined with the following command:
<- define_transition( mat_trans 9, .1, .2, .8 . )mat_trans
Values are attached to states. Cost and utility are classical examples of such values. To continue with the previous example, the following values can be attachd to state A and B:
A state and its values can be defined with
<- define_state( state_A cost = 1234, utility = 0.85 ) state_A <- define_state( state_B cost = 4321, utility = 0.50 )state_B
Now that the transition matrix and the state values are defined for a given strategy, we can combine them with
<- define_strategy( strat transition = mat_trans, state_A, state_B )strat
A model is a made of one or more strategy, run with
run_model() for a given number of cycles. Here we run only one strategy, so no comparison of the cost-effectiveness of the different strategies will be made. The variables corresponding to valuation of cost and effect must be given at that point.
<- run_model( res_mod strat,cycles = 10, cost = cost, effect = utility )res_mod
By default the model is run for 1000 persons starting in the first state (here state A).
We can plot the state membership counts over time. Other plot types are available.
Plots can be modified using
library(ggplot2) plot(res_mod) + xlab("Time") + ylab("N") + theme_minimal() + scale_color_brewer( name = "State", palette = "Set1" )
And black & white plots for publication are available with the
bw plot option
library(ggplot2) plot(res_mod, bw = TRUE)
The state membership counts and the values can be accessed with
Convenience functions are available to easily compute transition probabilities from indidence rates, OR, RR, or probabilities estimated on a different timeframe.
Example : convert an incidence rate of 162 cases per 1,000 person-years to a 5-year probability.
rate_to_prob(r = 162, per = 1000, to = 5)
?probability to see a list of the convenience functions available.
Mortality rates by age and sex (often used as transition probabilities) can be downloaded from the WHO online database with the function
External data contained in user-defined data frames can be referenced in a model with the function
In order to compare different strategies it is possible to run a model with multiple strategies in parallel, examples are provided in
vignette("c-homogeneous", "heemod") or
Time varying transition probabilities and state values are available through the
state_cycle variables. Time-varying probabilities and values are explained in
Transition costs between states can be defined by adding an additional state called a transition state. This is a special case of a tunnel state. A situation where the transtion from
A->B) costs $100 and reduces utility by 0.1 points compared to the usual values of
B can be modelled by adding a state
The cost and utility of
B_trans are the same as those of
B +$100 and -0.1 QALY respectively.
A->B_trans is equal to the former value of
A->B is set to 0 (all transitions from
B must pass through
B_trans from now on). The probability to stay in
B_trans is 0,
B_trans->B is equal to
B->B and similarly all
B_trans->* are equal to
Some operation such as PSA can be significantly sped up using parallel computing. This can be done in the following way:
use_cluster(4)to use 4 cores).
Results may vary depending on the machine, but we found speed gains to be quite limited beyond 4 cores.
Probabilistic uncertainty analysis
vignette("e-probabilistic", "heemod") and deterministic sensitivity analysis
vignette("f-sensitivity", "heemod") can be performed. Population-level estimates and heterogeneity can be computed :