brms (version 2.9.0)

pp_average.brmsfit: Posterior predictive samples averaged across models

Description

Compute posterior predictive samples averaged across models. Weighting can be done in various ways, for instance using Akaike weights based on information criteria or marginal likelihoods.

Usage

# S3 method for brmsfit
pp_average(x, ..., weights = "loo2",
  method = c("predict", "fitted", "residuals"), nsamples = NULL,
  summary = TRUE, probs = c(0.025, 0.975), robust = FALSE,
  model_names = NULL, control = list(), seed = NULL)

pp_average(x, ...)

Arguments

x

A brmsfit object.

...

More brmsfit objects or further arguments passed to the underlying post-processing functions.

weights

Name of the criterion to compute weights from. Should be one of "loo", "waic", "kfold", "loo2" (current default), or "marglik". For the former three options, Akaike weights will be computed based on the information criterion values returned by the respective methods. For "loo2", method loo_model_weights will be used to obtain weights. For "marglik", method post_prob will be used to compute weights based on log marginal likelihood values (make sure to specify reasonable priors in this case). Alternatively, weights can be a numeric vector of pre-specified weights.

method

Type of predictions to average. Should be one of "predict" (default), "fitted", or "residuals".

nsamples

Total number of posterior samples to use.

summary

Should summary statistics (i.e. means, sds, and 95% intervals) be returned instead of the raw values? Default is TRUE.

probs

The percentiles to be computed by the quantile function. Only used if summary is TRUE.

robust

If FALSE (the default) the mean is used as the measure of central tendency and the standard deviation as the measure of variability. If TRUE, the median and the median absolute deviation (MAD) are applied instead. Only used if summary is TRUE.

model_names

If NULL (the default) will use model names derived from deparsing the call. Otherwise will use the passed values as model names.

control

Optional list of further arguments passed to the function specified in weights.

seed

A single numeric value passed to set.seed to make results reproducible.

Value

Same as the output of the method specified in argument method.

Details

Weights are computed with the model_weights method.

See Also

model_weights, posterior_average

Examples

Run this code
# NOT RUN {
# model with 'treat' as predictor
fit1 <- brm(rating ~ treat + period + carry, data = inhaler)
summary(fit1)

# model without 'treat' as predictor
fit2 <- brm(rating ~ period + carry, data = inhaler)
summary(fit2)

# compute model-averaged predicted values
(df <- unique(inhaler[, c("treat", "period", "carry")]))
pp_average(fit1, fit2, newdata = df)

# compute model-averaged fitted values
pp_average(fit1, fit2, method = "fitted", newdata = df)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab