Learn R Programming

smoothedIPW (version 0.1.0)

prep_data: Prepare data set for inverse probability weighting

Description

This function adds columns to the input data set to assist with inverse probability weighting. See details.

Usage

prep_data(
  data,
  grace_period_length = 0,
  baseline_vars = NULL,
  lag_vars = NULL,
  n_lags = 1
)

Value

A data table containing the observed data with the additional columns.

Arguments

data

Data frame containing the observed data

grace_period_length

Numeric scalar indicating the length of the grace period, if applicable. The default is 0, indicating no grace period.

baseline_vars

Vector of character strings specifying the names of the baseline covariates that should be added to the observed data.

lag_vars

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.

n_lags

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.

Details

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.

Examples

Run this code
data_null_processed <- prep_data(data = data_null, grace_period_length = 2,
                                 baseline_vars = 'L')


Run the code above in your browser using DataLab