Learn R Programming

brms (version 2.7.0)

waic.brmsfit: Compute the WAIC

Description

Compute the widely applicable information criterion (WAIC) based on the posterior likelihood using the loo package. For more details see waic

Usage

# S3 method for brmsfit
waic(x, ..., compare = TRUE, resp = NULL,
  pointwise = FALSE, model_names = NULL)

Arguments

x

A fitted model object.

...

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

compare

A flag indicating if the information criteria of the models should be compared to each other via compare_ic.

resp

Optional names of response variables. If specified, predictions are performed only for the specified response variables.

pointwise

A flag indicating whether to compute the full log-likelihood matrix at once or separately for each observation. The latter approach is usually considerably slower but requires much less working memory. Accordingly, if one runs into memory issues, pointwise = TRUE is the way to go.

model_names

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

Value

If just one object is provided, an object of class ic. If multiple objects are provided, an object of class iclist.

Details

When comparing models fitted to the same data, the smaller the WAIC, the better the fit. For brmsfit objects, WAIC is an alias of waic. Use method add_ic to store information criteria in the fitted model object for later usage.

References

Vehtari, A., Gelman, A., & Gabry J. (2016). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. In Statistics and Computing, doi:10.1007/s11222-016-9696-4. arXiv preprint arXiv:1507.04544.

Gelman, A., Hwang, J., & Vehtari, A. (2014). Understanding predictive information criteria for Bayesian models. Statistics and Computing, 24, 997-1016.

Watanabe, S. (2010). Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory. The Journal of Machine Learning Research, 11, 3571-3594.

Examples

Run this code
# NOT RUN {
# model with population-level effects only
fit1 <- brm(rating ~ treat + period + carry,
            data = inhaler, family = "gaussian")
waic(fit1)

# model with an additional varying intercept for subjects
fit2 <- brm(rating ~ treat + period + carry + (1|subject),
            data = inhaler, family = "gaussian")
# compare both models
waic(fit1, fit2)                          
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab