create_input_mats() is a generic function for creating an object of class input_mats. Model matrices are constructed based on the variables specified in the model object and the data specified in input_data. create_input_mats() is not typically called by users directly, but is instead used by functions that create model objects (e.g., create_IndivCtstmTrans(), create_CohortDtstmTrans(), create_PsmCurves()).

create_input_mats(object, ...)

# S3 method for lm
create_input_mats(object, input_data, ...)

# S3 method for flexsurvreg
create_input_mats(object, input_data, ...)

# S3 method for flexsurvreg_list
create_input_mats(object, input_data, ...)

# S3 method for partsurvfit
create_input_mats(object, input_data, ...)

# S3 method for params_lm
create_input_mats(object, input_data, ...)

# S3 method for params_surv
create_input_mats(object, input_data, ...)

# S3 method for params_surv_list
create_input_mats(object, input_data, ...)

# S3 method for multinom
create_input_mats(object, input_data, ...)

# S3 method for multinom_list
create_input_mats(object, input_data, ...)

# S3 method for params_mlogit_list
create_input_mats(object, input_data, ...)

Arguments

object

An object of the appropriate class.

...

Further arguments passed to model.matrix().

input_data

An object of class expanded_hesim_data returned by expand.hesim_data(). It is used to look for the variables needed to create an input matrix for use in a statistical models and the ID variables for indexing rows in the input matrix.

Value

An object of class input_mats.

See also

Examples

library("flexsurv")

strategies <- data.frame(strategy_id = c(1, 2))
patients <- data.frame(patient_id = seq(1, 3),
                       age = c(45, 47, 60),
                       female = c(1, 0, 0),
                       group = factor(c("Good", "Medium", "Poor")))
states <- data.frame(state_id =  seq(1, 3),
                     state_name = factor(paste0("state", seq(1, 3))))
hesim_dat <- hesim_data(strategies = strategies,
                        patients = patients,
                        states = states)

# Class "lm"
input_data <- expand(hesim_dat, by = c("strategies", "patients", "states"))
medcost_fit <- lm(costs ~ female + state_name, psm4_exdata$costs$medical)
input_mats <- create_input_mats(medcost_fit, input_data)
input_mats
#> An "input_mats" object 
#> 
#> Column binding the ID variables with all variables contained in the X matrices:
#>     strategy_id patient_id state_id (Intercept) female state_namestate2
#>  1:           1          1        1           1      1                0
#>  2:           1          1        2           1      1                1
#>  3:           1          1        3           1      1                0
#>  4:           1          2        1           1      0                0
#>  5:           1          2        2           1      0                1
#>  6:           1          2        3           1      0                0
#>  7:           1          3        1           1      0                0
#>  8:           1          3        2           1      0                1
#>  9:           1          3        3           1      0                0
#> 10:           2          1        1           1      1                0
#> 11:           2          1        2           1      1                1
#> 12:           2          1        3           1      1                0
#> 13:           2          2        1           1      0                0
#> 14:           2          2        2           1      0                1
#> 15:           2          2        3           1      0                0
#> 16:           2          3        1           1      0                0
#> 17:           2          3        2           1      0                1
#> 18:           2          3        3           1      0                0
#>     state_namestate3
#>  1:                0
#>  2:                0
#>  3:                1
#>  4:                0
#>  5:                0
#>  6:                1
#>  7:                0
#>  8:                0
#>  9:                1
#> 10:                0
#> 11:                0
#> 12:                1
#> 13:                0
#> 14:                0
#> 15:                1
#> 16:                0
#> 17:                0
#> 18:                1
#> 
#> Number of unique values of ID variables:
#> n_strategies   n_patients     n_states 
#>            2            3            3 
#> 

# Class "flexsurvreg"
input_data <- expand(hesim_dat, by = c("strategies", "patients"))
fit_wei <- flexsurvreg(formula = Surv(futime, fustat) ~ 1,
                       data = ovarian, dist = "weibull")
input_mats <- create_input_mats(fit_wei, input_data)
input_mats
#> An "input_mats" object 
#> 
#> Column binding the ID variables with all variables contained in the X matrices:
#>    strategy_id patient_id (Intercept)
#> 1:           1          1           1
#> 2:           1          2           1
#> 3:           1          3           1
#> 4:           2          1           1
#> 5:           2          2           1
#> 6:           2          3           1
#> 
#> Number of unique values of ID variables:
#> n_strategies   n_patients 
#>            2            3 
#>