create_StateVals() is a generic function for creating an object of class StateVals from a fitted statistical model or a stateval_tbl object.

create_StateVals(object, ...)

# S3 method for class 'lm'
create_StateVals(
  object,
  input_data = NULL,
  n = 1000,
  uncertainty = c("normal", "none"),
  ...
)

# S3 method for class 'stateval_tbl'
create_StateVals(object, hesim_data = NULL, n = 1000, ...)

Arguments

object

A model object of the appropriate class.

...

Further arguments (time_reset and method) passed to StateVals$new().

input_data

An object of class expanded_hesim_data. Must be expanded by treatment strategies, patients, and health states.

n

Number of random observations of the parameters to draw when parameters are fit using a statistical model.

uncertainty

Method determining how parameter uncertainty should be handled. See documentation in create_params().

hesim_data

A hesim_data object. Only required when object is of class stateval_tbl. See "details".

Value

A StateVals object.

Details

If object is a stateval_tbl, then a hesim_data object is used to specify treatment strategies, patients, and/or health states not included as columns in the table, or, to match patients in the table to groups. Not required if the table includes one row for each treatment strategy, patient, and health state combination. Patients are matched to groups by specifying both a patient_id and a grp_var column in the patients table.

See also

See StateVals for documentation of the class and additional examples. An example use case for create_StateVals.stateval_tbl() is provided in the stateval_tbl() documentation.

Examples

set.seed(10)

# EXAMPLE FOR `create_statevals.lm()`
## Simple example comparing two treatment strategies where
## medical costs vary by sex and health state

## Setup model
hesim_dat <- hesim_data(
  strategies = data.frame(strategy_id = c(1, 2)),
  patients = data.frame(
    patient_id = c(1, 2),
    female = c(1, 0)
  ),
  states = data.frame(
    state_id = c(1, 2, 3),
    state_name = c("state1", "state2", "state3")
  )
)

## Fit model
medcost_estimation_data <- psm4_exdata$costs$medical
medcost_estimation_data$time5 <- rbinom(nrow(medcost_estimation_data), 
                                        1, .5) # Illustrative time dummy
medcost_fit <- lm(costs ~ female + state_name + time5, 
                  data = medcost_estimation_data)

## Create medical cost model
### Allow medical costs to vary across time in addition to by patient and 
### health state
medcost_times <- time_intervals(
  data.frame(time_start = c(0, 3, 5),
            time5 = c(0, 0, 1)) # Time dummy corresponds to time > 5
)
medcost_input_data <- expand(hesim_dat, 
                             by = c("strategies", "patients", "states"),
                             times = medcost_times)
medcost_model <- create_StateVals(medcost_fit, medcost_input_data,
                                  n = 1)

## Explore predictions from medical cost model
### We can assess predictions at multiple time points
medcost_model$sim(t = c(1, 6), type = "predict")
#>     sample strategy_id patient_id state_id  time    value
#>      <num>       <int>      <int>    <int> <num>    <num>
#>  1:      1           1          1        1     1 35879.44
#>  2:      1           1          1        1     6 35328.58
#>  3:      1           1          1        2     1 31270.98
#>  4:      1           1          1        2     6 30720.12
#>  5:      1           1          1        3     1 36850.71
#>  6:      1           1          1        3     6 36299.86
#>  7:      1           1          2        1     1 32840.08
#>  8:      1           1          2        1     6 32289.23
#>  9:      1           1          2        2     1 28231.62
#> 10:      1           1          2        2     6 27680.77
#> 11:      1           1          2        3     1 33811.36
#> 12:      1           1          2        3     6 33260.50
#> 13:      1           2          1        1     1 35879.44
#> 14:      1           2          1        1     6 35328.58
#> 15:      1           2          1        2     1 31270.98
#> 16:      1           2          1        2     6 30720.12
#> 17:      1           2          1        3     1 36850.71
#> 18:      1           2          1        3     6 36299.86
#> 19:      1           2          2        1     1 32840.08
#> 20:      1           2          2        1     6 32289.23
#> 21:      1           2          2        2     1 28231.62
#> 22:      1           2          2        2     6 27680.77
#> 23:      1           2          2        3     1 33811.36
#> 24:      1           2          2        3     6 33260.50
#>     sample strategy_id patient_id state_id  time    value