This document is an introduction to heemod’s basic steps to define and run a model.

When building a Markov model for health economic evaluation, the following steps must be performed:

Other vignettes provide more details and examples on specific topics:

Transition probabilities

The probability to change from one state to another during a time period is called a transition probability. The time period is called a cycle.

Transition probabilities between states can be specified 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. For example consider a model with 2 states A and B:

A B
A 1 2
B 3 4

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_matrix function. If we consider the previous example, where cell values have been replaced by actual probabilities:

A B
A 0.9 0.1
B 0.2 0.8

That transition matrix can be defined with the following command:

mat_trans <- define_matrix(
  .9, .1,
  .2, .8
)
## No named state -> generating names.
mat_trans
## An unevaluated matrix, 2 states.
## 
##   A   B  
## A 0.9 0.1
## B 0.2 0.8

Attach values to states

In health economic evaluation, 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 <- define_state(
  cost = 1234,
  utility = 0.85
)
state_A
## An unevaluated state with 2 values.
## 
## cost = 1234
## utility = 0.85
state_B <- define_state(
  cost = 4321,
  utility = 0.50
)
state_B
## An unevaluated state with 2 values.
## 
## cost = 4321
## utility = 0.5

Combine information in a model

Now that the transition matrix and the state values are defined, we can combine them to create a Markov model with define_model:

mod_1 <- define_model(
  transition_matrix = mat_trans,
  state_A,
  state_B
)
## No named state -> generating names.
mod_1
## An unevaluated Markov model:
## 
##     0 parameter,
##     2 states,
##     2 state values

Run a model

The model can then be run with run_model for a given number of cycles. The variables corresponding to valuation of cost and effect must be given at that point.

res_mod_1 <- run_models(
  mod_1,
  cycles = 10,
  cost = cost,
  effect = utility
)
## No named model -> generating names.
res_mod_1
## 1 Markov model run for 10 cycles.
## 
## Initial states:
## 
##      N
## A 1000
## B    0
##       cost  utility
## I 20296822 7597.866

By default the model is run for one person starting in the first state (here state A).

Analyse results

The result can be explored with summary:

summary(res_mod_1)
## 1 Markov model run for 10 cycles.
## 
## Initial states:
## 
##      N
## A 1000
## B    0
##       cost  utility
## I 20296822 7597.866

We can plot the state membership counts over time. Other plot types are available.

plot(res_mod_1)

Plots can be modified using ggplot2 syntax.

library(ggplot2)

plot(res_mod_1) +
  xlab("Time") +
  ylab("N") +
  theme_minimal() +
  scale_color_brewer(
    name = "State",
    palette = "Set1"
  )

Going futher

In order to compare different strategies it is possible to run several models in parallel, examples are provided in vignette("homogeneous", package = "heemod") or vignette("non-homogeneous", package = "heemod").

Incertitude analysis vignette("probabilistic", package = "heemod") and sensitivity analysis vignette("sensitivity", package = "heemod") can be performed.

Population-level country-specific mortality rates by age and sex (often used as transition probabilities in Markov models) can be downloaded from WHO databases with the get_who_mr() function.