create_data_matrix {psborrow2} | R Documentation |
Create Data Matrix
Description
Creates a matrix suitable for create_analysis_obj()
. Creates dummy variables for factors and
allows transformations of covariates specified with a formula.
Usage
create_data_matrix(
data,
outcome,
trt_flag_col,
ext_flag_col,
covariates = NULL,
weight_var = NULL
)
Arguments
data |
data.frame. Data containing all variables |
outcome |
character. The outcome variable for binary outcomes or the time and censoring variables. |
trt_flag_col |
character. The treatment indicator variable. |
ext_flag_col |
character. The external cohort indicator. |
covariates |
character or formula. The covariates for model adjustment. |
weight_var |
character. An optional weight variable. |
Value
Invisibly returns a matrix
containing all variables to pass to create_analysis_obj()
.
Prints names of covariates columns to use with add_covariates()
.
Examples
dat <- survival::diabetic
dat$ext <- dat$trt == 0 & dat$id > 1000
data_mat <- create_data_matrix(
dat,
outcome = c("time", "status"),
trt_flag_col = "trt",
ext_flag_col = "ext",
covariates = ~ age + laser + log(risk)
)
data_mat
[Package psborrow2 version 0.0.3.4 Index]