| name | health-economics |
| description | Health economic analysis in R, including cost-effectiveness, QALYs, decision models, and budget impact. |
Health Economics Evaluation in R
Overview
Health economic evaluation methods covering cost-effectiveness analysis (CEA), quality-adjusted life years (QALYs), incremental cost-effectiveness ratios (ICERs), budget impact analysis, Markov cohort models, partitioned survival analysis, probabilistic sensitivity analysis, and value of information analysis.
Cost-Effectiveness Fundamentals
Basic Calculations
costs_int <- 15000
costs_comp <- 8000
effects_int <- 5.2
effects_comp <- 4.5
delta_cost <- costs_int - costs_comp
delta_effect <- effects_int - effects_comp
icer <- delta_cost / delta_effect
cat("ICER:", round(icer, 0), "per QALY gained\n")
wtp <- 50000
nmb <- delta_effect * wtp - delta_cost
cat("NMB at WTP $", wtp, ":", round(nmb, 0), "\n")
nhb <- delta_effect - delta_cost / wtp
cat("NHB:", round(nhb, 3), "QALYs\n")
Cost-Effectiveness Plane
library(ggplot2)
set.seed(123)
n_sim <- 1000
delta_c <- rnorm(n_sim, delta_cost, 2000)
delta_e <- rnorm(n_sim, delta_effect, 0.3)
ce_data <- data.frame(
delta_cost = delta_c,
delta_effect = delta_e
)
ggplot(ce_data, aes(x = delta_effect, y = delta_cost)) +
geom_point(alpha = 0.3, color = "blue") +
geom_hline(yintercept = 0, linetype = "dashed") +
geom_vline(xintercept = 0, linetype = "dashed") +
geom_abline(slope = wtp, intercept = 0, color = "red", linetype = "dashed") +
annotate("text", x = 1.5, y = 15000, label = paste0("WTP = $", wtp),
color = "red") +
labs(x = "Incremental Effect (QALYs)",
y = "Incremental Cost ($)",
title = "Cost-Effectiveness Plane") +
theme_bw()
Cost-Effectiveness Analysis with BCEA
Using BCEA Package
library(BCEA)
n_sim <- 1000
n_int <- 2
effects <- matrix(
c(rnorm(n_sim, 4.5, 0.5),
rnorm(n_sim, 5.2, 0.6)),
nrow = n_sim, ncol = n_int
)
costs <- matrix(
c(rnorm(n_sim, 8000, 1500),
rnorm(n_sim, 15000, 3000)),
nrow = n_sim, ncol = n_int
)
colnames(effects) <- colnames(costs) <- c("Comparator", "Intervention")
bcea_result <- bcea(
e = effects,
c = costs,
ref = 1,
interventions = c("Comparator", "Intervention"),
Kmax = 100000
)
summary(bcea_result, wtp = 50000)
bcea_result$ICER
bcea_result$ceac
CE Plane and CEAC Plots
library(BCEA)
ceplane.plot(bcea_result,
wtp = 50000,
graph = "ggplot2",
title = "Cost-Effectiveness Plane")
ceac.plot(bcea_result,
graph = "ggplot2",
title = "Cost-Effectiveness Acceptability Curve")
ceaf.plot(bcea_result, graph = "ggplot2")
eib.plot(bcea_result, graph = "ggplot2")
Multiple Interventions
library(BCEA)
effects_3 <- matrix(
c(rnorm(n_sim, 4.0, 0.4),
rnorm(n_sim, 4.8, 0.5),
rnorm(n_sim, 5.5, 0.6)),
nrow = n_sim
)
costs_3 <- matrix(
c(rnorm(n_sim, 5000, 1000),
rnorm(n_sim, 12000, 2500),
rnorm(n_sim, 20000, 4000)),
nrow = n_sim
)
colnames(effects_3) <- colnames(costs_3) <- c("Standard", "Treatment_A", "Treatment_B")
bcea_multi <- bcea(
e = effects_3,
c = costs_3,
ref = 1,
interventions = colnames(effects_3)
)
mce <- multi.ce(bcea_multi)
ceac.plot(mce, graph = "ggplot2")
contour2(bcea_multi, wtp = 50000)
Markov Cohort Models
Using heemod Package
library(heemod)
mat_trans <- define_transition(
state_names = c("Healthy", "Sick", "Dead"),
C, 0.15, 0.01,
0.10, C, 0.05,
0, 0, 1
)
state_healthy <- define_state(
cost = 0,
utility = 1
)
state_sick <- define_state(
cost = 5000,
utility = 0.7
)
state_dead <- define_state(
cost = 0,
utility = 0
)
strat_base <- define_strategy(
transition = mat_trans,
Healthy = state_healthy,
Sick = state_sick,
Dead = state_dead
)
result_base <- run_model(
strat_base,
cycles = 50,
cost = cost,
effect = utility,
init = c(1000, 0, 0),
method = "beginning"
)
summary(result_base)
plot(result_base)
Comparing Strategies
library(heemod)
mat_trans_trt <- define_transition(
state_names = c("Healthy", "Sick", "Dead"),
C, 0.10, 0.01,
0.15, C, 0.04,
0, 0, 1
)
state_healthy_trt <- define_state(
cost = 500,
utility = 1
)
strat_trt <- define_strategy(
transition = mat_trans_trt,
Healthy = state_healthy_trt,
Sick = state_sick,
Dead = state_dead
)
result_comp <- run_model(
base = strat_base,
treatment = strat_trt,
cycles = 50,
cost = cost,
effect = utility,
init = c(1000, 0, 0)
)
summary(result_comp)
icer_result <- summary(result_comp)$res_comp
print(icer_result)
Time-Dependent Parameters
library(heemod)
param <- define_parameters(
age_init = 50,
age = age_init + model_time,
mortality = 1 - exp(-0.0001 * age^2),
p_sick = 0.1 + 0.005 * model_time
)
mat_time <- define_transition(
state_names = c("Healthy", "Sick", "Dead"),
C, p_sick, mortality,
0.05, C, mortality * 1.5,
0, 0, 1
)
result_time <- run_model(
define_strategy(
transition = mat_time,
Healthy = state_healthy,
Sick = state_sick,
Dead = state_dead
),
cycles = 30,
cost = cost,
effect = utility,
init = c(1000, 0, 0),
parameters = param
)
Partitioned Survival Analysis
Using hesim Package
library(hesim)
library(flexsurv)
fit_os <- flexsurvreg(
Surv(time, status) ~ treatment,
data = surv_data,
dist = "weibull"
)
fit_pfs <- flexsurvreg(
Surv(time_pfs, status_pfs) ~ treatment,
data = surv_data,
dist = "weibull"
)
Building PSM with hesim
library(hesim)
strategies <- data.table(
strategy_id = 1:2,
strategy_name = c("Standard", "New Treatment")
)
patients <- data.table(
patient_id = 1:100,
age = rnorm(100, 60, 10)
)
states <- data.table(
state_id = 1:3,
state_name = c("Stable", "Progressed", "Dead")
)
hesim_data <- hesim_data(
strategies = strategies,
patients = patients,
states = states
)
input_data <- expand(hesim_data, by = c("strategies", "patients"))
survmods <- create_PsmCurves(
input_data = input_data,
params = params_surv_list
)
stprobs <- survmods$sim_stateprobs(t = seq(0, 10, 0.1))
Costs and QALYs from PSM
library(hesim)
utility_tbl <- stateval_tbl(
data.table(
state_id = 1:3,
est = c(0.8, 0.6, 0)
),
dist = "fixed"
)
cost_tbl <- stateval_tbl(
data.table(
state_id = 1:3,
est = c(1000, 5000, 0)
),
dist = "fixed"
)
psm <- Psm$new(
survival_models = survmods,
utility_model = utility_tbl,
cost_models = list(drug = cost_tbl)
)
psm$sim_stateprobs(t = seq(0, 10, by = 0.1))
psm$sim_qalys(dr = 0.03)
psm$sim_costs(dr = 0.03)
ce_results <- psm$summarize()
Probabilistic Sensitivity Analysis
Parameter Distributions
library(heemod)
param_psa <- define_parameters(
p_sick = rbeta(1, shape1 = 20, shape2 = 80),
p_death_healthy = rbeta(1, shape1 = 2, shape2 = 198),
p_death_sick = rbeta(1, shape1 = 10, shape2 = 90),
cost_sick = rgamma(1, shape = 100, rate = 0.02),
cost_treatment = rgamma(1, shape = 50, rate = 0.1),
utility_sick = rbeta(1, shape1 = 70, shape2 = 30)
)
psa_result <- run_psa(
model = result_comp,
psa = param_psa,
N = 1000
)
summary(psa_result)
plot(psa_result, type = "ce")
plot(psa_result, type = "ac")
Custom PSA Implementation
n_sim <- 1000
psa_results <- data.frame(
sim = 1:n_sim,
cost_base = NA,
cost_trt = NA,
qaly_base = NA,
qaly_trt = NA
)
for (i in 1:n_sim) {
p_sick <- rbeta(1, 20, 80)
cost_sick <- rgamma(1, 100, 0.02)
utility_sick <- rbeta(1, 70, 30)
psa_results$cost_base[i] <- sum_cost_base