Average marginal MCMC draws across time points.
Source:R/brm_marginal_draws_average.R
brm_marginal_draws_average.Rd
Simple un-weighted arithmetic mean of marginal MCMC draws across time points.
Arguments
- data
A classed data frame from
brm_data()
, or an informative prior archetype from a function likebrm_archetype_successive_cells()
.- draws
List of posterior draws from
brm_marginal_draws()
.- times
Character vector of discrete time point levels over which to average the MCMC samples within treatment group levels. Set to
NULL
to average across all time points. Levels are automatically sanitized withmake.names(unique = FALSE, allow_ = TRUE)
to ensure agreement withbrms
variable names in downstream computations.- label
Character of length 1, time point label for the averages. Automatically sanitized with
make.names(unique = FALSE, allow_ = TRUE)
. Must not conflict with any existing time point labels in the data after the label and time points are sanitized.
Value
A named list of tibbles of MCMC draws of the marginal posterior
distribution of each treatment group and time point
(or group-by-subgroup-by-time, if applicable).
In each tibble, there is 1 row per posterior sample sand one column for
each type of marginal distribution (i.e. each combination of treatment
group and discrete time point. The specific tibble
s in the returned
list are described below:
response
: on the scale of the response variable.difference_time
: change from baseline: theresponse
at a particular time minus theresponse
at baseline (reference_time
). Only returned if therole
argument ofbrm_data()
was"response"
. (Ifrole
is"change"
, thenresponse
already represents change from baseline.)difference_group
: treatment effect: the thedifference_time
at each active group minus thedifference_time
at the control group (reference_group
). Ifrole
is"change"
, then treatment group is instead the difference betweenresponse
at each active group minus theresponse
at the control group.difference_subgroup
: subgroup differences: thedifference_group
at each subgroup level minus thedifference_group
at the subgroup reference level (reference_subgroup
).
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 marginals:
brm_marginal_data()
,
brm_marginal_draws()
,
brm_marginal_grid()
,
brm_marginal_probabilities()
,
brm_marginal_summaries()
Examples
if (identical(Sys.getenv("BRM_EXAMPLES", unset = ""), "true")) {
set.seed(0L)
data <- brm_data(
data = brm_simulate_simple()$data,
outcome = "response",
role = "response",
group = "group",
time = "time",
patient = "patient",
reference_group = "group_1",
reference_time = "time_1"
)
formula <- brm_formula(
data = data,
baseline = FALSE,
baseline_time = FALSE
)
tmp <- utils::capture.output(
suppressMessages(
suppressWarnings(
model <- brm_model(
data = data,
formula = formula,
chains = 1,
iter = 100,
refresh = 0
)
)
)
)
draws <- brm_marginal_draws(data = data, formula = formula, model = model)
brm_marginal_draws_average(draws = draws, data = data)
brm_marginal_draws_average(
draws = draws,
data = data,
times = c("time_1", "time_2"),
label = "mean"
)
}