Learn R Programming

psborrow2 (version 0.0.4.0)

create_data_matrix: 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
)

Value

Invisibly returns a matrix containing all variables to pass to create_analysis_obj(). Prints names of covariates columns to use with add_covariates().

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.

Examples

Run this code
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

Run the code above in your browser using DataLab