Learn R Programming

hesim (version 0.2.0)

create_input_mats: Create input matrices

Description

create_input_mats is a generic function for creating an object of class input_mats. Model matrices are typically constructed based on the variables specified in the model object and the data specified in data, although there are some cases in which input_mats can be created from object alone.

Usage

create_input_mats(object, ...)

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

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

# S3 method for lm_list 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, ...)

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 the function expand.hesim_data. Used to look for the input 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

input_mats.

Examples

Run this code
# NOT RUN {
library("flexsurv")

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

# Class "lm"
expanded_dat <- expand(hesim_dat, by = c("strategies", "patients", "states"))
fit_lm <- stats::lm(costs ~ female + state_name, psm4_exdata$costs$medical)
input_mats <- create_input_mats(fit_lm, expanded_dat)
class(input_mats)

# Class "flexsurvreg"
expanded_dat <- expand(hesim_dat, by = c("strategies", "patients"))
fit_wei <- flexsurv::flexsurvreg(formula = Surv(futime, fustat) ~ 1, 
                                 data = ovarian, dist = "weibull")
input_mats <- create_input_mats(fit_wei, expanded_dat)
class(input_mats)
# }

Run the code above in your browser using DataLab