使用heemod构建三状态马尔可夫模型时define_strategy报错求助
问题原因与解决方案
报错原因
define_strategy()要求transition参数必须是heemod专属的转移对象,而非普通R矩阵。直接传入原生matrix时,函数无法解析其中的状态元数据,因此判定转移对象的状态数为0,与你定义的3个状态产生数量不匹配的错误。
解决方法
使用heemod的define_transition()函数将你的转移矩阵包装为符合要求的转移对象,再传入define_strategy()即可。
修改后的完整代码
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") )) # 用define_transition包装转移矩阵 trans_mat <- define_transition(transition_matrix) 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 = trans_mat, # 使用包装后的转移对象 Healthy = state_healthy, State2 = state_state2, Death = state_death )
内容的提问来源于stack exchange,提问作者福井里佳
相关产品推荐
相关产品推荐

