I'm trying to build a 3-state Markov model using the heemod package in R to evaluate cost and effectiveness over time. I defined:
- 3 health states:
Healthy,State2, andDeath - A 3x3 transition probability matrix (row/column names match state names)
- Per-cycle costs and utilities (QALYs) for each state
- A single treatment strategy
However, when I try to use define_strategy() with the matrix-based transition and define_state() for each health state, I keep getting an error like: Number of state in model input (3) differ from number of state in transition object (0)
I've confirmed the matrix has 3 rows and 3 columns, and the class is "matrix". All state names are consistent. Here's a simplified version of my code:
library(heemod) params <- define_parameters( cost_healthy = 80000, cost_state2 = 300000, cost_death = 0, util_healthy = 0.95, util_state2 = 0.70, util_death = 0.00 ) transition_matrix <- matrix(c( 0.90, 0.08, 0.02, 0.00, 0.93, 0.07, 0.00, 0.00, 1.00 ), nrow = 3, byrow = TRUE, dimnames = list( from = c("Healthy", "State2", "Death"), to = c("Healthy", "State2", "Death") )) state_healthy <- define_state(cost = cost_healthy, qaly = util_healthy) state_state2 <- define_state(cost = cost_state2, qaly = util_state2) state_death <- define_state(cost = cost_death, qaly = util_death) strategy <- define_strategy( transition = transition_matrix, Healthy = state_healthy, State2 = state_state2, Death = state_death ) The error occurs at the define_strategy() step. Any idea why this happens, and how to fix it? I'm using R version 4.3.1 and heemod version 1.1.0. Thanks in advance!