Decision tree models are widely used in health economic evaluation to compare healthcare interventions under uncertainty. These models estimate expected costs and health outcomes by combining clinical probabilities, costs, and utility values assigned to possible health states.

In cost-utility analysis, health outcomes are typically expressed as quality-adjusted life years (QALYs), which combine both the quality and duration of life into a single metric used in health technology assessment.

This tutorial demonstrates how to construct a reproducible decision tree model in R using the rdecision. The example compares low molecular weight heparin (LMWH) with conventional treatment for patients undergoing hip replacement surgery and calculates expected costs, QALYs, and the incremental cost-effectiveness ratio (ICER).

The workflow illustrates how decision analytic models can be implemented programmatically in R for pharmacoeconomic analysis, health technology assessment (HTA), and health economic modelling.

Learning objectives

Building a decision tree with utility (QALY) outcomes (cost utility analysis)

Define decision nodes, chance nodes, and terminal nodes using the rdecision package

Attach probabilities, treatment costs, and utility weights to the model branches.

Visualize the decision tree structure

 Use the `draw()` function to generate a graphical representation of the decision tree.

Evaluate the decision tree to obtain expected outcomes

 Compute the expected cost and QALY for each intervention strategy.

Calculate incremental cost-effectiveness results

 Estimate incremental costs, incremental QALYs, and the ICER.

Show reproducibility with rdecision package

#==========================
# Hip Replacement Decision Tree Model
#==========================

#--------------------------
# 1. Load package
#--------------------------

library(rdecision)
library(dplyr) # For pipe operator
library(flextable)

Decision Tree Model Structure

  1. Nodes vertices (V)

Nodes represent critical points within the decision process.

Three principal types of nodes are used in decision tree models:

(1) Decision nodes represent alternative interventions or strategies under evaluation. These nodes define the competing options available to the decision maker.

(2) Chance nodes represent uncertain events that may occur following a decision. Each branch emerging from a chance node is associated with a probability that reflects the likelihood of that outcome.

(3) Terminal nodes (or leaf nodes) represent the final outcomes of the decision process, where costs and health outcomes such as utilities or quality-adjusted life years are assigned.

  1. Branches edges (E)

Branches represent the pathways that connect nodes and represent the sequence of events occurring within the model. In this framework, branches are represented by two types of objects: actions and reactions.

Actions represent the primary pathways that originate from a decision node and correspond to the alternative interventions being compared, while reactions represent the possible consequences that occur following an action. These typically correspond to transitions from chance nodes to subsequent chance nodes or terminal nodes and are associated with probabilities and, where relevant, costs or health outcomes.

Together, nodes and branches constitute the fundamental building blocks required for constructing a decision tree model.

Scenario

The objective of this example is to reproduce a published decision tree model using the rdecision package.

In this cost-utility framework, health preferences are quantified through utility weights assigned to each terminal node.

To transform these cross-sectional utility values into Quality-Adjusted Life Years (QALYs), a temporal horizon of one year was defined using the as.difftime function horizon <- as.difftime(365.25, units = “days”). This ensures that the terminal nodes (LeafNode$new) correctly integrate the duration of the health state, following the standard formula: QALY = Utility * Time.

Create Nodes (Vertices V)

# Time interval creation    (utility * time Interval =  QALY)
horizon_years <- 1
horizon <- as.difftime(horizon_years*365.25, units="days")

# 2. NODES (V)
#---------------------
# (1) Decision Node
#---------------------

decision <- DecisionNode$new("Hip replacement patients")

#---------------------
# (2) Chance Nodes
#---------------------
c_lmwh <- ChanceNode$new("LMW heparin")
c_dvt_h <- ChanceNode$new("DVT")
c_no_dvt_h <- ChanceNode$new("No DVT")

c_conv_trt <- ChanceNode$new("Conventional treatment")
c_dvt_conv <- ChanceNode$new("DVT")
c_no_dvt_conv<- ChanceNode$new("No DVT")

#---------------------
# (3) Terminal or leaf nodes
#---------------------
t1     <- LeafNode$new(label = "Bleed", utility = 0.65, interval = horizon) #Bleed_LMWH_DVT
t2     <- LeafNode$new("No Bleed", utility = 0.7, interval = horizon)       #No Bleed_LMWH_DVT
t3     <- LeafNode$new("Bleed",utility =0.95, interval = horizon)
t4     <- LeafNode$new("No Bleed",utility =1, interval = horizon)

t5     <- LeafNode$new("Bleed", utility = 0.65, interval = horizon)
t6     <- LeafNode$new("No Bleed", utility = 0.7, interval = horizon)
t7     <- LeafNode$new("Bleed", utility = 0.95, interval = horizon)
t8     <- LeafNode$new("No Bleed", utility = 1, interval = horizon)

V = list(decision, c_lmwh,c_dvt_h, c_no_dvt_h,c_conv_trt,c_dvt_conv, c_no_dvt_conv, t1,t2,t3,t4,t5,t6,t7,t8)

Create branches (Edges E)

Edges include actions and reactions, the alternative treatment options are defined in actions and the consequent pathways in reactions

Create “Actions” and “Reactions” Alternative treatments and associated pathways

# LMWH or Conventional treatment

a1<-Action$new(decision, c_lmwh, "LMWH")
a2<-Action$new(decision, c_conv_trt, "Conv.Trt")

# LMWH pathway
r1<-Reaction$new(c_lmwh, c_dvt_h, p = 0.14)
r2<-Reaction$new(c_lmwh, c_no_dvt_h, p = 0.86)          

r3<-Reaction$new(c_dvt_h, t1, p = 0.1, cost =2800) 
r4<-Reaction$new(c_dvt_h, t2, p = 0.9,cost =2300) 

r5<-Reaction$new(c_no_dvt_h, t3, p = 0.1, cost= 800)           
r6<-Reaction$new(c_no_dvt_h, t4, p = 0.9, cost = 300)

# Conventional Treatment pathway
r7<-Reaction$new(c_conv_trt, c_dvt_conv, p = 0.25)          
r8<-Reaction$new(c_conv_trt, c_no_dvt_conv, p = 0.75)       

r9<-Reaction$new( c_dvt_conv, t5, p = 0.01,cost =2450)
r10<-Reaction$new( c_dvt_conv,t6, p = 0.99,cost =2050)

r11<-Reaction$new(c_no_dvt_conv, t7, p = 0.01,cost = 550)
r12<-Reaction$new(c_no_dvt_conv, t8, p = 0.99, cost=50)

E= list(a1,a2,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12)

After defining nodes and branches, the decision tree can be constructed.

Assemble Nodes (vertices) with branches (edges)

tree <- DecisionTree$new(V = V,E = E)

Visualize decision tree draw()

tree$draw()

Model evaluation evaluate()

tree$evaluate()
##   Run Hip.replacement.patients Probability   Cost Benefit Utility   QALY
## 1   1                 Conv.Trt           1 554.75       0  0.9245 0.9245
## 2   1                     LMWH           1 630.00       0  0.9530 0.9530

Output in a table Format

results<-tree$evaluate()

results %>% select(Hip.replacement.patients, Cost, QALY) %>% flextable()

Hip.replacement.patients

Cost

QALY

Conv.Trt

554.75

0.9245

LMWH

630.00

0.9530

Incremental Cost Effectiveness analysis: ICER calculation

IC <- diff(results$Cost)
IE <- diff(results$QALY)

IC<- round(IC)        # Rounded to the nearest digits
IE<- round(IE,2)      # Rounded 

IC ; IE
## [1] 75
## [1] 0.03
ICER<- IC/IE
ICER
## [1] 2500
plot(IE, IC,
     xlab="Incremental QALY",
     ylab="Incremental Cost",
     pch=19)
abline(h=0,v=0)

cat("Incremental cost:", IC,"£","\n")
## Incremental cost: 75 £
cat("Incremental QALY:",IE,"\n")
## Incremental QALY: 0.03
cat("ICER:", ICER, "£","Per QALY gained")
## ICER: 2500 £ Per QALY gained

Conclusion

From the analysis, LMWH is more expensive but more effective compared to conventional treatment. The incremental cost is 75 £ with an incremental gain of 0.03 QALY. The resulting ICER is 2500 £ per QALY gained.This falls in the Northeast quadrant of the cost-effectiveness plane.

The ICER (£2500/QALY) is substantially below the commonly used willingness-to-pay threshold used by the National Institute for Health and Care Excellence (£20,000–£30,000/QALY), indicating that LMWH would be considered highly cost-effective.

Reference: https://share.google/Wm8CAzdna6QzBcoqx