hesim-dev / hesim

Health economic simulation modeling and decision analysis
https://hesim-dev.github.io/hesim/
62 stars 17 forks source link

Costs by disease state in Markov cohort model #7

Closed aheff closed 4 years ago

aheff commented 4 years ago

Hi hesim-dev - I've been playing around with bits of code in the repository for a couple of days now and really like the package - thanks for developing it.

While trying to adapt the code in the "getting-started.Rmd" file (see here) I found I couldn't work out how to assign costs to specific states of the model - e.g. if you wanted the costs of being in the AIDS state to be greater than CD4 >200 state.

This is something that can be achieved in the more complex individual CTSTMs vignette - see here - specifically lines 129-134.

I've tried adapting the latter code by creating a stateval_tbl object in the cohort model approach and putting it into the tparams_def object - for instance I used such an object to try and specify community medical expenses by state of the model - but to no effect.

I must admit my grasp of what's going on behind the code is limited here but would appreciate any help solving this issue.

dincerti commented 4 years ago

Nicely done delving into the "development" version of the package. I might suggest you take a look at the development documentation here as well as an HTML version of the vignette here. You can also read through some of the model definition function documentation here.

To answer your question, the easiest way to do this is to enter costs as a vector as in the vignette (e.g., c_dmed_mean = c(A = 1701, B = 1774, C = 6948) on line 82), meaning that direct medical costs are $1701 in state A, $1774 in State B, and $6948 in State C). In the vignette we then use a gamma distribution (gamma_rng() on line 106) for the PSA which returns a data table where each column is costs in a distinct (non-death) state (i.e., column 1 = costs in State A, column 2 = costs in State B, column 3 = costs in State C). .

Hope this is helpful. Please note though that these features are only available in the development version of hesim via devtools::install_github(). I'm planning to have v0.3.0 released sometime close to the New Year, although you're free to use them now and the API is not expected to change.

aheff commented 4 years ago

Hi - thanks for the quick reply. Yes this solves that issue - should've worked that out myself to be honest!

aheff commented 4 years ago

Just to make sure I've not gone about this the wrong way - would the following be an appropriate way to specify a set of recurring costs for categories A, B and C - I've attempted to make it quite general so I can specify different distributions for each cost:

`c_dmed = custom(matrix(c(runif(n, min = c_annual_dial[1], max = c_annual_dial[2]),

                        runif(n, min = c_annual_ntx[1], max = c_annual_ntx[2]), 

                        runif(n, min = c_annual_ntx[1], max = c_annual_ntx[2])), 

                      nrow=n, ncol=3, byrow = F), 

                  names = c("A","B","C"))`

where n is the number of samples drawn, as defined in rng_def and c_annual_dial and c_annual_ntx are two component vectors that specify the minima and maxima of distributions defining the annual costs of the states in the model (costs of dialysis and liver transplant).

dincerti commented 4 years ago

That is exactly right. You could have equivalently set up c_dmed as:

c_dmed = custom(matrix(c(runif(n, 
                               min = c(c_annual_dial[1], rep(c_annual_ntx[1], 2)),
                               max = c(c_annual_dial[2], rep(c_annual_ntx[2], 2)))),
                       nrow = n, ncol = 3, byrow = T),
                names = c("A",  "B", "C"))

c_dmed can also be a data.frame or data.table in which case you can refer to columns in define_tparams() with c_dmed$A, c_dmed$B, c_dmed$C. In the matrix case, you would need to use c_dmed[, "A"], c_dmed[, "B"], c_dmed[, "C"]

aheff commented 4 years ago

Thanks for clarifying and the alternative idea suggestion.