brm_data {brms.mmrm} | R Documentation |
Create and preprocess an MMRM dataset.
Description
Create a dataset to analyze with an MMRM.
Usage
brm_data(
data,
outcome,
baseline = NULL,
group,
subgroup = NULL,
time,
patient,
covariates = character(0L),
missing = NULL,
reference_group,
reference_subgroup = NULL,
reference_time = NULL,
role = NULL,
level_baseline = NULL,
level_control = NULL
)
Arguments
data |
Data frame or tibble with longitudinal data. |
outcome |
Character of length 1, name of the continuous
outcome variable.
Example possibilities from clinical trial datasets include
|
baseline |
Character of length 1,
name of the baseline response variable (for example, |
group |
Character of length 1, name of the treatment group variable.
Example possibilities from clinical trial datasets include
|
subgroup |
Character of length 1, optional name of the a
discrete subgroup variable. Set to |
time |
Character of length 1, name of the discrete time variable.
Example possibilities from clinical trial datasets include
Ordinarily, ordered factors automatically use polynomial contrasts from
|
patient |
Character of length 1, name of the patient ID variable.
Example possibilities from clinical trial datasets include
|
covariates |
Character vector of names of other covariates.
All these covariates are assumed to be non-time-varying. For time-varying
covariates, please manually expand the data to the full grid of patients
and time points before you call |
missing |
Character of length 1, name of an optional variable
in a simulated dataset to indicate which outcome values should be missing.
Set to |
reference_group |
Atomic value of length 1, Level of the |
reference_subgroup |
Atomic value of length 1,
level of the |
reference_time |
Atomic value of length 1 or If Note: |
role |
Deprecated as unnecessary on 2024-07-11 (version 1.0.1.9007).
Use |
level_baseline |
Deprecated on 2024-01-11 (version 0.2.0.9002).
Use |
level_control |
Deprecated on 2024-01-11 (version 0.2.0.9002).
Use |
Value
A classed tibble with attributes which denote features of the data such as the treatment group and discrete time variables.
Preprocessing
The preprocessing steps in brm_data()
are as follows:
Perform basic assertions to make sure the data and other arguments are properly formatted.
Convert the group and time columns to character vectors.
Sanitize the levels of the group and time columns using
make.names(unique = FALSE, allow_ = TRUE)
to ensure agreement between the data and the output ofbrms
.For each implicitly missing outcome observation, add explicit row with the outcome variable equal to
NA_real_
. Missing values in the predictors are implicitly filled usingzoo::na.locf()
on within each patient, which is not valid for time-varying covariates. If any covariates are time-varying, please manually perform this step before callingbrm_data()
.Arrange the rows of the data by group, then patient, then discrete time.
Select only the columns of the data relevant to an MMRM analysis.
Separation string
Post-processing in brm_marginal_draws()
names each of the
group-by-time marginal means with the delimiting character string
from Sys.getenv("BRM_SEP", unset = "|")
. Neither the column names
nor element names of the group and time variables can contain
this string. To set a custom string yourself, use
Sys.setenv(BRM_SEP = "YOUR_CUSTOM_STRING")
.
See Also
Other data:
brm_data_change()
,
brm_data_chronologize()
Examples
set.seed(0)
data <- brm_simulate_simple()$data
colnames(data) <- paste0("col_", colnames(data))
data
brm_data(
data = data,
outcome = "col_response",
group = "col_group",
time = "col_time",
patient = "col_patient",
reference_group = "group_1",
reference_time = "time_1"
)