An Introduction to heemod

2016-09-16

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:
## 
##     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
## 
## Counting method: 'life-table'.
## 
##       cost  utility
## I 19796856 7654.552

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

Analyse results

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"
  )

The state membership counts can be accessed with get_counts().

get_counts(res_mod_1)
##           A        B
## 1  950.0000  50.0000
## 2  865.0000 135.0000
## 3  805.5000 194.5000
## 4  763.8500 236.1500
## 5  734.6950 265.3050
## 6  714.2865 285.7135
## 7  700.0005 299.9995
## 8  690.0004 309.9996
## 9  683.0003 316.9997
## 10 678.1002 321.8998

Convenience functions

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)
## [1] 0.5551419

Type ?probability to see a list of the convenience functions available.

External data

Age and sex-specific mortality rates can be downloaded from the WHO online database with the function get_who_mr().

External data contained in user-defined data frames can be referenced in a model with the function look_up().

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").

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

See vignette vignette("reproduction", package = "heemod") for an exact reproduction of the analyses from Decision Modelling for Health Economic Evaluation.

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.