This function adds columns to the input data set to assist with inverse probability weighting. See details.
prep_data(
data,
grace_period_length = 0,
baseline_vars = NULL,
lag_vars = NULL,
n_lags = 1
)A data table containing the observed data with the additional columns.
Data frame containing the observed data
Numeric scalar indicating the length of the grace period, if applicable. The default is 0, indicating no grace period.
Vector of character strings specifying the names of the baseline covariates that should be added to the observed data.
Vector of character strings specifying the names of the covariates whose lags should be added as columns to the observed data. The number of lags is controlled by the n_lags argument.
Numeric scalar specifying the number of lags to use when computing the lagged values of lag_vars. Additional columns will be created for 1, ..., n_lags lags of the variables specified in lag_vars.
This function performs the following tasks:
Adds a column C_artificial which indicates when an individual should be artificially censored from the data when applying inverse probability weighting.
Adds a column A_model_eligible which indicates what records should be used for fitting the treatment adherence model.
If baseline_vars is supplied, it adds columns corresponding to the baseline value of these variables. These columns have the name _baseline appended to them.
If lag_vars is supplied, it adds columns corresponding to the lagged value of these variables. For each of these variables, additional columns will be created for 1, ..., n_lags lags of the variable.
data_null_processed <- prep_data(data = data_null, grace_period_length = 2,
baseline_vars = 'L')
Run the code above in your browser using DataLab