Learn R Programming

brms (version 0.6.0)

LOO.brmsfit: Compute LOO

Description

Compute Leave-one-out cross-validation based on the posterior likelihood by using the loo package

Usage

## S3 method for class 'brmsfit':
LOO(x, ..., compare = TRUE, cores = getOption("loo.cores",
  parallel::detectCores()), wcp = 0.2, wtrunc = 3/4)

LOO(x, ..., compare = TRUE)

Arguments

x
A fitted model object typically of class brmsfit.
...
Optionally more fitted model objects.
compare
A flag indicating if the WAICs of the models should be compared to each other.
cores
The number of cores to use for parallelization. This can be set for an entire R session by options(loo.cores = NUMBER). The default is detectCores().
wcp, wtrunc
Parameters used for the Pareto smoothed importance sampling. See loo for details.

Value

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

Methods (by class)

  • brmsfit: method for classbrmsfit

Details

When comparing models fitted to the same data, the smaller the LOO, the better the fit.

References

Vehtari, A., Gelman, A., and Gabry, J. (2015). Efficient implementation of leave-one-out cross-validation and WAIC for evaluating fitted Bayesian models. 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
#model with fixed effects only
fit_i1 <- brm(rating ~ treat + period + carry,
              data = inhaler, family = "gaussian")
LOO(fit_i1)

#model with an additional random intercept for subjects
fit_i2 <- brm(rating ~ treat + period + carry + (1|subject),
             data = inhaler, family = "gaussian")
#compare both models
LOO(fit_i1, fit_i2)

Run the code above in your browser using DataLab