This vignette is an example of an elementary semi-Markov model using
rdecision package. It is based on the example given by
Briggs et al1
(Exercise 2.5) which itself is based on a model described by Chancellor
et al2. The model
compares a combination therapy of Lamivudine/Zidovudine versus
Zidovudine monotherapy in people with HIV infection.
The variables used in the model are all numerical constants, and are defined as follows.
# transition counts <- 1251L nAA <- 350L nAB <- 116L nAC <- 17L nAD <- 731L nBB <- 512L nBC <- 15L nBD <- 1312L nCC <- 437L nCD # Healthcare system costs <- 1701.0 # direct medical costs associated with state A dmca <- 1774.0 # direct medical costs associated with state B dmcb <- 6948.0 # direct medical costs associated with state C dmcc <- 1055.0 # Community care costs associated with state A ccca <- 1278.0 # Community care costs associated with state B cccb <- 2059.0 # Community care costs associated with state C cccc # Drug costs <- 2278.0 # zidovudine drug cost cAZT <- 2087.0 # lamivudine drug cost cLam # Treatment effect <- 0.509 RR # Discount rates <- 6.0 # annual discount rate, costs (%) cDR <- 0.0 # annual discount rate, benefits (%)oDR
The model is constructed by forming a graph, with each state as a
node and each transition as an edge. Nodes (of class
MarkovState) and edges (class
have various properties whose values reflect the variables of the model
(costs, rates etc.). Because the model is intended to evaluate survival,
the utility of states A, B and C are set to 1 (by default) and state D
to zero. Thus the incremental quality adjusted life years gained per
cycle is equivalent to the survival function.
# create Markov states for monotherapy (zidovudine only) <- MarkovState$new("A", cost = dmca + ccca + cAZT) sAm <- MarkovState$new("B", cost = dmcb + cccb + cAZT) sBm <- MarkovState$new("C", cost = dmcc + cccc + cAZT) sCm <- MarkovState$new("D", cost = 0.0, utility = 0.0) sDm # create transitions <- Transition$new(sAm, sAm) tAAm <- Transition$new(sAm, sBm) tABm <- Transition$new(sAm, sCm) tACm <- Transition$new(sAm, sDm) tADm <- Transition$new(sBm, sBm) tBBm <- Transition$new(sBm, sCm) tBCm <- Transition$new(sBm, sDm) tBDm <- Transition$new(sCm, sCm) tCCm <- Transition$new(sCm, sDm) tCDm <- Transition$new(sDm, sDm) tDDm # construct the model <- SemiMarkovModel$new( m.mono V = list(sAm, sBm, sCm, sDm), E = list(tAAm, tABm, tACm, tADm, tBBm, tBCm, tBDm, tCCm, tCDm, tDDm), discount.cost = cDR / 100.0, discount.utility = oDR / 100.0 )
Briggs et al1
interpreted the observed transition counts in 1 year as transition
probabilities by dividing counts by the total transitions observed from
each state. With this assumption, the annual (per-cycle) transition
probabilities are calculated as follows and applied to the model via the
<- nAA + nAB + nAC + nAD nA <- nBB + nBC + nBD nB <- nCC + nCD nC <- matrix( Pt c(nAA / nA, nAB / nA, nAC / nA, nAD / nA, 0.0, nBB / nB, nBC / nB, nBD / nB, 0.0, 0.0, nCC / nC, nCD / nC, 0.0, 0.0, 0.0, 1.0), nrow = 4L, byrow = TRUE, dimnames = list( source = c("A", "B", "C", "D"), target = c("A", "B", "C", "D") ) )$set_probabilities(Pt)m.mono
More usually, fully observed transition counts are converted into
transition rates (rather than probabilities), as described by Welton and
Ades3. This is because counting
events and measuring total time at risk includes individuals who make
more than one transition during the observation time, and can lead to
rates with values which exceed 1. In contrast, the difference between a
census of the number of individuals in each state at the start of the
interval and another at the end is directly related to the per-cycle
probability. As Miller and Homan4, Welton and Ades3, Jones et al5 and others note, conversion between
rates and probabilities for multi-state Markov models is
non-trivial5 and care is needed
when modellers calculate probabilities from published rates for use in
A representation of the model in DOT format (Graphviz) can be created using the
as_DOT function of
function returns a character vector which can be saved in a file
.gv extension) for visualization with the
tool of Graphviz, or plotted directly in R via the
DiagrammeR package. The Markov model for monotherapy is
shown in Figure 1.
The states in the model can be tabulated with the function
tabulate_states. For the monotherapy model, the states are
tabulated below. The cost of each state includes the annual cost of AZT
The per-cycle transition probabilities, which are the cells of the
Markov transition matrix, can be extracted from the model via the
transition_probabilities. For the monotherapy
model, the transition matrix is shown below. This is consistent with the
Table 1 of Chancellor et al2.
cycle applies one cycle of a Markov model
to a defined starting population in each state. It returns a table with
one row per state, and each row containing several columns, including
the population at the end of the state and the cost of occupancy of
states, normalized by the number of patients in the cohort, with
Multiple cycles are run by feeding the state populations at the end
of one cycle into the next. Function
cycles does this and
returns a data frame with one row per cycle, and each row containing the
state populations and the aggregated cost of occupancy for all states,
with discounting applied. This is done below for the first 20 cycles of
the model for monotherapy, without half cycle correction, with discount.
In addition, the proportion of patients alive at each cycle (the Markov
trace) is added to the table. The populations and discounted costs are
consistent with Briggs et al, Table 2.31, and the QALY column is consistent
with Table 2.4 (without half cycle correction). No discount was applied
to the utilities.
# create starting populations <- 1000L N <- c(A = N, B = 0L, C = 0L, D = 0L) populations $reset(populations) m.mono# run 20 cycles <- m.mono$cycles(ncycles = 20L, hcc.pop = FALSE, hcc.cost = FALSE)MT.mono
The estimated life years is approximated by summing the proportions of patients left alive at each cycle (Briggs et al1, Exercise 2.5). This is an approximation because it ignores the population who remain alive after 21 years, and assumes all deaths occurred at the start of each cycle. For monotherapy the expected life gained is 7.991 years at a cost of 44663 GBP.
For combination therapy, a similar model was created, with adjusted costs and transition rates. Following Briggs et al1 the treatment effect was applied to the probabilities, and these were used as inputs to the model. More usually, treatment effects are applied to rates, rather than probabilities.
# annual probabilities modified by treatment effect <- RR*nAB/nA pAB <- RR*nAC/nC pAC <- RR*nAD/nA pAD <- RR*nBC/nB pBC <- RR*nBD/nB pBD <- RR*nCD/nC pCD # annual transition probability matrix <- matrix( Ptc c(1.0 - pAB - pAC - pAD, pAB, pAC, pAD, 0.0, (1.0 - pBC - pBD), pBC, pBD, 0.0, 0.0, (1.0 - pCD), pCD, 0.0, 0.0, 0.0, 1.0), nrow = 4L, byrow = TRUE, dimnames=list( source = c("A", "B", "C", "D"), target = c("A", "B", "C", "D") ) )# create Markov states for combination therapy <- MarkovState$new("A", cost = dmca + ccca + cAZT + cLam) sAc <- MarkovState$new("B", cost = dmcb + cccb + cAZT + cLam) sBc <- MarkovState$new("C", cost = dmcc + cccc + cAZT + cLam) sCc <- MarkovState$new("D", cost = 0.0, utility = 0.0) sDc # create transitions <- Transition$new(sAc, sAc) tAAc <- Transition$new(sAc, sBc) tABc <- Transition$new(sAc, sCc) tACc <- Transition$new(sAc, sDc) tADc <- Transition$new(sBc, sBc) tBBc <- Transition$new(sBc, sCc) tBCc <- Transition$new(sBc, sDc) tBDc <- Transition$new(sCc, sCc) tCCc <- Transition$new(sCc, sDc) tCDc <- Transition$new(sDc, sDc) tDDc # construct the model <- SemiMarkovModel$new( m.comb V = list(sAc, sBc, sCc, sDc), E = list(tAAc, tABc, tACc, tADc, tBBc, tBCc, tBDc, tCCc, tCDc, tDDc), discount.cost = cDR / 100.0, discount.utility = oDR / 100.0 )# set the probabilities $set_probabilities(Ptc)m.comb
The per-cycle transition matrix for the combination therapy is as follows:
In this model, lamivudine is given for the first 2 years, with the
treatment effect assumed to persist for the same period. The state
populations and cycle numbers are retained by the model between calls to
cycles and can be retrieved by
get_populations. In this example, the combination
therapy model is run for 2 cycles, then the population is used to
continue with the monotherapy model for the remaining 8 years. The
reset function is used to set the cycle number and elapsed
time of the new run of the mono model.
# run combination therapy model for 2 years <- c("A" = N, "B" = 0L, "C" = 0L, "D" = 0L) populations $reset(populations) m.comb# run 2 cycles <- m.comb$cycles(2L, hcc.pop = FALSE, hcc.cost = FALSE) MT.comb # feed populations into mono model & reset cycle counter and time <- m.comb$get_populations() populations $reset( m.mono populations, icycle = 2L, elapsed = as.difftime(365.25*2.0, units = "days") )# and run model for next 18 years <- rbind( MT.comb $cycles(ncycles = 18L, hcc.pop = FALSE, hcc.cost = FALSE) MT.comb, m.mono)
The Markov trace for combination therapy is as follows:
The ICER is calculated by running both models and calculating the incremental cost per life year gained. Over the 20 year time horizon, the expected life years gained for monotherapy was 7.991 years at a total cost per patient of 44,663 GBP. The expected life years gained with combination therapy for two years was 8.94 at a total cost per patient of 50,607 GBP. The incremental change in life years was 0.949 years at an incremental cost of 5,944 GBP, giving an ICER of 6264 GBP/QALY. This is consistent with the result obtained by Briggs et al1 (6276 GBP/QALY), within rounding error.