brm_formula | R Documentation |
Build a model formula for an MMRM, either for a generic
brm_data()
dataset or an informative prior archetype.
brm_formula(
data,
model_missing_outcomes = FALSE,
check_rank = TRUE,
sigma = brms.mmrm::brm_formula_sigma(data = data, check_rank = check_rank),
correlation = "unstructured",
autoregressive_order = 1L,
moving_average_order = 1L,
residual_covariance_arma_estimation = FALSE,
...
)
## Default S3 method:
brm_formula(
data,
model_missing_outcomes = FALSE,
check_rank = TRUE,
sigma = brms.mmrm::brm_formula_sigma(data = data, check_rank = check_rank),
correlation = "unstructured",
autoregressive_order = 1L,
moving_average_order = 1L,
residual_covariance_arma_estimation = FALSE,
intercept = TRUE,
baseline = !is.null(attr(data, "brm_baseline")),
baseline_subgroup = !is.null(attr(data, "brm_baseline")) && !is.null(attr(data,
"brm_subgroup")),
baseline_subgroup_time = !is.null(attr(data, "brm_baseline")) && !is.null(attr(data,
"brm_subgroup")),
baseline_time = !is.null(attr(data, "brm_baseline")),
covariates = TRUE,
group = TRUE,
group_subgroup = !is.null(attr(data, "brm_subgroup")),
group_subgroup_time = !is.null(attr(data, "brm_subgroup")),
group_time = TRUE,
subgroup = !is.null(attr(data, "brm_subgroup")),
subgroup_time = !is.null(attr(data, "brm_subgroup")),
time = TRUE,
center = TRUE,
...,
effect_baseline = NULL,
effect_group = NULL,
effect_time = NULL,
interaction_baseline = NULL,
interaction_group = NULL
)
## S3 method for class 'brms_mmrm_archetype'
brm_formula(
data,
model_missing_outcomes = FALSE,
check_rank = TRUE,
sigma = brms.mmrm::brm_formula_sigma(data = data, check_rank = check_rank),
correlation = "unstructured",
autoregressive_order = 1L,
moving_average_order = 1L,
residual_covariance_arma_estimation = FALSE,
...,
warn_ignored = TRUE
)
data |
A classed data frame from |
model_missing_outcomes |
Logical of length 1, |
check_rank |
|
sigma |
A formula produced by |
correlation |
Character of length 1, name of the correlation
structure. The correlation matrix is a square
|
autoregressive_order |
Nonnegative integer,
autoregressive order for the |
moving_average_order |
Nonnegative integer,
moving average order for the |
residual_covariance_arma_estimation |
|
... |
Named arguments to specific |
intercept |
Logical of length 1.
|
baseline |
Logical of length 1.
|
baseline_subgroup |
Logical of length 1. |
baseline_subgroup_time |
Logical of length 1.
|
baseline_time |
Logical of length 1.
|
covariates |
Logical of length 1.
|
group |
Logical of length 1.
|
group_subgroup |
Logical of length 1.
|
group_subgroup_time |
Logical of length 1.
|
group_time |
Logical of length 1.
|
subgroup |
Logical of length 1.
|
subgroup_time |
Logical of length 1.
|
time |
Logical of length 1.
|
center |
|
effect_baseline |
Deprecated on 2024-01-16 (version 0.0.2.9002).
Use |
effect_group |
Deprecated on 2024-01-16 (version 0.0.2.9002).
Use |
effect_time |
Deprecated on 2024-01-16 (version 0.0.2.9002).
Use |
interaction_baseline |
Deprecated on 2024-01-16 (version 0.0.2.9002).
Use |
interaction_group |
Deprecated on 2024-01-16 (version 0.0.2.9002).
Use |
warn_ignored |
Set to |
An object of class "brmsformula"
returned from
brms::brmsformula()
. It contains the fixed effect mapping,
correlation structure, and residual variance structure.
brm_data()
formulasFor a brm_data()
dataset,
brm_formula()
builds an R formula for an MMRM based on
the details in the data and your choice of mapping.
Customize your mapping by toggling on or off
the various TRUE
/FALSE
arguments of brm_formula()
,
such as intercept
, baseline
, and group_time
.
All plausible additive effects, two-way interactions, and
three-way interactions can be specified. The following interactions
are not supported:
Any interactions with the concomitant covariates you specified in the
covariates
argument of brm_data()
.
Any interactions which include baseline response and treatment group together. Rationale: in a randomized controlled experiment, baseline and treatment group assignment should be uncorrelated.
Functions like brm_archetype_successive_cells()
tailor datasets to informative prior archetypes. For these specialized
tailored datasets, brm_formula()
works differently. It still applies
the variance and correlation structure of your choosing, and it still
lets you choose whether to adjust for nuisance covariates,
but it no longer lets you toggle on/off individual terms in the model,
such as intercept
, baseline
, or group
. Instead, to ensure the
correct interpretation of the parameters, brm_formula()
uses
the x_*
and nuisance_*
columns generated by
brm_archetype_successive_cells( prefix_interest = "x_", prefix_nuisance = "nuisance_")
.
For a formula on a brm_data()
dataset,
the formula is not the only factor
that determines the fixed effect mapping.
The ordering of the categorical variables in the data,
as well as the contrast
option in R, affect the
construction of the model matrix. To see the model
matrix that will ultimately be used in brm_model()
,
run brms::make_standata()
and examine the X
element
of the returned list. See the examples below for a
demonstration.
Other models:
brm_formula_sigma()
,
brm_model()
set.seed(0)
data <- brm_data(
data = brm_simulate_simple()$data,
outcome = "response",
group = "group",
time = "time",
patient = "patient",
reference_group = "group_1",
reference_time = "time_1"
)
brm_formula(data)
brm_formula(data = data, intercept = FALSE, baseline = FALSE)
formula <- brm_formula(
data = data,
intercept = FALSE,
baseline = FALSE,
group = FALSE
)
formula
# Standard deviations of residuals are distributional parameters that can
# regress on variables in the data.
homogeneous <- brm_formula_sigma(data, time = FALSE)
by_group <- brm_formula_sigma(data, group = TRUE, intercept = TRUE)
homogeneous
by_group
brm_formula(data, sigma = homogeneous)
brm_formula(data, sigma = by_group)
# Optional: set the contrast option, which determines the model matrix.
options(contrasts = c(unordered = "contr.SAS", ordered = "contr.poly"))
# See the fixed effect mapping you get from the data:
head(brms::make_standata(formula = formula, data = data)$X)
# Specify a different contrast method to use an alternative
# mapping when fitting the model with brm_model():
options(
contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")
)
# different model matrix than before:
head(brms::make_standata(formula = formula, data = data)$X)
# Formula on an informative prior archetype:
data <- brm_simulate_outline(
n_group = 2,
n_patient = 100,
n_time = 4,
rate_dropout = 0,
rate_lapse = 0
) |>
dplyr::mutate(response = rnorm(n = dplyr::n())) |>
brm_data_change() |>
brm_simulate_continuous(names = c("biomarker1", "biomarker2")) |>
brm_simulate_categorical(
names = "biomarker3",
levels = c("present", "absent")
)
archetype <- brm_archetype_successive_cells(data)
formula <- brm_formula(data = archetype)
formula
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.