I'm new to R and have a project assigned, whereby I have to build a cost-effectiveness model in R. It's based on a Markov Model, I'm currently just trying to get used to the interface and have installed the heemod package to assist in producing markov models.
I've got simple models to run based on the vignettes from Cran, but thought I'll try to expand upon that which would relate to something similar to the project.
Instead of an intervention and one comparator, I have 2 comparators, but seems to be getting the error as follows. (note the values/numbers are just for testing purposes so far, to try to get the model to work).
library(heemod)
param <- define_parameters(
nin_state_110 = .721,
nin_state_100 = .202,
nin_state_90 = .067,
nin_state_80 = .014,
nin_state_70 = .85,
nin_state_60 = .234,
nin_state_50 = .67,
nin_state_40 = .56,
nin_state_30 = 0,
pfn_state_110 = .96,
pfn_state_100 = .85,
pfn_state_90 = .56,
pfn_state_80 = .53,
pfn_state_70 = .44,
pfn_state_60 = .76,
pfn_state_50 = .22,
pfn_state_40 = .35,
pfn_state_30 = 0,
bsc_state_110 = .8,
bsc_state_100 = .77,
bsc_state_90 = .66,
bsc_state_80 = .77,
bsc_state_70 = .43,
bsc_state_60 = .97,
bsc_state_50 = .66,
bsc_state_40 = .37,
bsc_state_30 = 0,
cost_nin = 2278,
cost_pfn = 2086,
cost_bsc = 0,
cost_110 = 199,
cost_100 = 200,
cost_90 = 250,
cost_80 = 300,
cost_70 = 225,
cost_60 = 150,
cost_50 = 250,
cost_40 = 200,
cost_30 = 0
)
mat_nin <- define_transition(
nin_state_110, C, 0, 0, 0, 0, 0, 0, 0,
0, nin_state_100, C, 0, 0, 0, 0, 0, 0,
0, 0, nin_state_90, C, 0, 0, 0, 0, 0,
0, 0, 0, nin_state_80, C, 0, 0, 0, 0,
0, 0, 0, 0, nin_state_70, C, 0, 0, 0,
0, 0, 0, 0, 0, nin_state_60, C, 0, 0,
0, 0, 0, 0, 0, 0, nin_state_50, C, 0,
0, 0, 0, 0, 0, 0, 0, nin_state_40, C,
0, 0, 0, 0, 0, 0, 0, 0, nin_state_30
)
mat_pfn <- define_transition(
pfn_state_110, C, 0, 0, 0, 0, 0, 0, 0,
0, pfn_state_100, C, 0, 0, 0, 0, 0, 0,
0, 0, pfn_state_90, C, 0, 0, 0, 0, 0,
0, 0, 0, pfn_state_80, C, 0, 0, 0, 0,
0, 0, 0, 0, pfn_state_70, C, 0, 0, 0,
0, 0, 0, 0, 0, pfn_state_60, C, 0, 0,
0, 0, 0, 0, 0, 0, pfn_state_50, C, 0,
0, 0, 0, 0, 0, 0, 0, pfn_state_40, C,
0, 0, 0, 0, 0, 0, 0, 0, pfn_state_30
)
mat_bsc <- define_transition(
bsc_state_110, C, 0, 0, 0, 0, 0, 0, 0,
0, bsc_state_100, C, 0, 0, 0, 0, 0, 0,
0, 0, bsc_state_90, C, 0, 0, 0, 0, 0,
0, 0, 0, bsc_state_80, C, 0, 0, 0, 0,
0, 0, 0, 0, bsc_state_70, C, 0, 0, 0,
0, 0, 0, 0, 0, bsc_state_60, C, 0, 0,
0, 0, 0, 0, 0, 0, bsc_state_50, C, 0,
0, 0, 0, 0, 0, 0, 0, bsc_state_40, C,
0, 0, 0, 0, 0, 0, 0, 0, bsc_state_30
)
state_110 <- define_state(
cost_110 = 199,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_110 + cost_drugs, .035),
utility = 0.8380
)
state_100 <- define_state(
cost_100 = 200,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_100 + cost_drugs, .035),
utility = 0.8380
)
state_90 <- define_state(
cost_90 = 250,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_90 + cost_drugs, .035),
utility = 0.8380
)
state_80 <- define_state(
cost_80 = 300,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_80 + cost_drugs, .035),
utility = 0.8380
)
state_70 <- define_state(
cost_70 = 225,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_70 + cost_drugs, .035),
utility = 0.8380
)
state_60 <- define_state(
cost_60 = 150,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_60 + cost_drugs, .035),
utility = 0.8380
)
state_50 <- define_state(
cost_50 = 250,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_50 + cost_drugs, .035),
utility = 0.8380
)
state_40 <- define_state(
cost_40 = 200,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_40 + cost_drugs, .035),
utility = 0.8380
)
state_30 <- define_state(
cost_30 = 0,
cost_drugs = discount(dispatch_strategy(
nin = cost_nin,
pfn = cost_pfn,
bsc = cost_bsc
)),
cost_total = discount(cost_30 + cost_drugs, .035),
utility = 0
)
strat_nin <- define_strategy(
transition = mat_nin,
state_110,
state_100,
state_90,
state_80,
state_70,
state_60,
state_50,
state_40,
state_30
)
strat_pfn <- define_strategy(
transition = mat_pfn,
state_110,
state_100,
state_90,
state_80,
state_70,
state_60,
state_50,
state_40,
state_30
)
strat_bsc <- define_strategy(
transition = mat_bsc,
state_110,
state_100,
state_90,
state_80,
state_70,
state_60,
state_50,
state_40,
state_30
)
res_mod <- run_model(
nin = strat_nin,
pfn = strat_pfn,
parameters = param,
cycles = 50,
cost = cost_total,
effect = utility
)
res_mod2 <- run_model(
nin = strat_nin,
bsc = strat_bsc,
parameters = param,
cycles = 50,
cost = cost_total,
effect = utility
)
rsp <- define_psa(
cost_110 ~ gamma(mean = 180, sd = sqrt(199)),
cost_100 ~ gamma(mean = 170, sd = sqrt(200)),
cost_90 ~ gamma(mean = 240, sd = sqrt(250)),
cost_80 ~ gamma(mean = 290, sd = sqrt(300)),
cost_70 ~ gamma(mean = 230, sd = sqrt(225)),
cost_60 ~ gamma(mean = 150, sd = sqrt(125)),
cost_50 ~ gamma(mean = 240, sd = sqrt(250)),
cost_40 ~ gamma(mean = 210, sd = sqrt(200)),
cost_30 ~ gamma(mean = 1, sd = sqrt(1)),
)
pm <- run_psa(
model = res_mod,
psa = rsp,
N = 100
)
This is the error that outputs:
No named state -> generating names. Error in check_states(states) : State value names differ between states.