View source: R/data_preparation.R
data_preparation | R Documentation |
This function expands observational data in the person-time format (i.e., the ‘long’ format) to emulate a sequence of target trials and also estimates the inverse probability of treatment and censoring weights as required.
data_preparation(
data,
id = "id",
period = "period",
treatment = "treatment",
outcome = "outcome",
eligible = "eligible",
model_var = NULL,
outcome_cov = ~1,
estimand_type = c("ITT", "PP", "As-Treated"),
switch_n_cov = ~1,
switch_d_cov = ~1,
first_period = NA,
last_period = NA,
use_censor_weights = FALSE,
cense = NA,
pool_cense = c("none", "both", "numerator"),
cense_d_cov = ~1,
cense_n_cov = ~1,
eligible_wts_0 = NA,
eligible_wts_1 = NA,
where_var = NULL,
data_dir,
save_weight_models = FALSE,
glm_function = "glm",
chunk_size = 500,
separate_files = FALSE,
quiet = FALSE,
...
)
data |
A |
id |
Name of the variable for identifiers of the individuals. Default is ‘id’. |
period |
Name of the variable for the visit/period. Default is ‘period’. |
treatment |
Name of the variable for the treatment indicator at that visit/period. Default is ‘treatment’. |
outcome |
Name of the variable for the indicator of the outcome event at that visit/period. Default is ‘outcome’. |
eligible |
Name of the variable for the indicator of eligibility for the target trial at that visit/period. Default is ‘eligible’. |
model_var |
Treatment variables to be included in the marginal structural model for the emulated trials.
|
outcome_cov |
A RHS formula with baseline covariates to be adjusted for in the marginal structural model for the
emulated trials. Note that if a time-varying covariate is specified in |
estimand_type |
Specify the estimand for the causal analyses in the sequence of emulated trials. |
switch_n_cov |
A RHS formula to specify the logistic models for estimating the numerator terms of the inverse
probability of treatment weights. A derived variable named |
switch_d_cov |
A RHS formula to specify the logistic models for estimating the denominator terms of the inverse probability of treatment weights. |
first_period |
First time period to be set as trial baseline to start expanding the data. |
last_period |
Last time period to be set as trial baseline to start expanding the data. |
use_censor_weights |
Require the inverse probability of censoring weights. If |
cense |
Variable name for the censoring indicator. Required if |
pool_cense |
Fit pooled or separate censoring models for those treated and those untreated at the immediately
previous visit. Pooling can be specified for the models for the numerator and denominator terms of the inverse
probability of censoring weights. One of |
cense_d_cov |
A RHS formula to specify the logistic models for estimating the denominator terms of the inverse probability of censoring weights. |
cense_n_cov |
A RHS formula to specify the logistic models for estimating the numerator terms of the inverse probability of censoring weights. |
eligible_wts_0 |
See definition for |
eligible_wts_1 |
Exclude some observations when fitting the models for the inverse probability of treatment
weights. For example, if it is assumed that an individual will stay on treatment for at least 2 visits, the first 2
visits after treatment initiation by definition have a probability of staying on the treatment of 1.0 and should
thus be excluded from the weight models for those who are on treatment at the immediately previous visit. Users can
define a variable that indicates that these 2 observations are ineligible for the weight model for those who are on
treatment at the immediately previous visit and add the variable name in the argument |
where_var |
Specify the variable names that will be used to define subgroup conditions when fitting the marginal
structural model for a subgroup of individuals. Need to specify jointly with the argument |
data_dir |
Directory to save model objects when |
save_weight_models |
Save model objects for estimating the weights in |
glm_function |
Specify which glm function to use for the marginal structural model from the |
chunk_size |
Number of individuals whose data to be processed in one chunk when |
separate_files |
Save expanded data in separate CSV files for each trial. |
quiet |
Suppress the printing of progress messages and summaries of the fitted models. |
... |
Additional arguments passed to |
The arguments chunk_size
and separate_files
allow for processing of large datasets that would not fit in
memory once expanded. When separate_files = TRUE
, the input data are processed in chunks of individuals and saved
into separate files for each emulated trial. These separate files can be sampled by case-control sampling to create
a reduced dataset for the modelling.
An object of class TE_data_prep
, which can either be sampled from (case_control_sampling_trials) or
directly used in a model (trial_msm). It contains the elements
the expanded dataset for all emulated trials. If separate_files = FALSE
, it is a data.table
; if
separate_files = TRUE
, it is a character vector with the file path of the expanded data as CSV files.
index for the first trial in the expanded data
index for the last trial in the expanded data
the total number of observations in the expanded data
a zero-row data.frame
with the columns and attributes of the expanded data
a list of summaries of the models fitted for inverse probability of treatment weights,
if estimand_type
is "PP"
or "As-Treated"
a list of summaries of the models fitted for inverse probability of censoring weights,
if use_censor_weights=TRUE
a list contain the parameters used to prepare the data and fit the weight models
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.