Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

loocv

Leave one group out cross-validation for baggr models


Description

Performs exact leave-one-group-out cross-validation on a baggr model.

Usage

loocv(data, return_models = FALSE, ...)

Arguments

data

Input data frame - same as for baggr function.

return_models

logical; if FALSE, summary statistics will be returned and the models discarded; if TRUE, a list of models will be returned alongside summaries

...

Additional arguments passed to baggr.

Details

The values returned by loocv() can be used to understand how any one group affects the overall result, as well as how well the model predicts the omitted group.

This function automatically runs K baggr models, leaving out one group at a time, and then calculates expected log predictive density (ELPD) for that group (see Gelman et al 2013). The main output is the cross-validation information criterion, or -2 times the ELPD averaged over 'K' models. This is related to, and often approximated by, the Watanabe-Akaike Information Criterion. A value closer to zero (i.e. a smaller number in magnitude) means a better fit. For more information on cross-validation see this overview article

For running more computation-intensive models, consider setting the mc.cores option before running loocv, e.g. options(mc.cores = 4) (by default baggr runs 4 MCMC chains in parallel). As a default, rstan runs "silently" (refresh=0). To see sampling progress, please set e.g. loocv(data, refresh = 500).

Value

log predictive density value, an object of class baggr_cv; full model, prior values and lpd of each model are also returned. These can be examined by using attributes() function.

Author(s)

Witold Wiecek

References

Gelman, Andrew, Jessica Hwang, and Aki Vehtari. “Understanding Predictive Information Criteria for Bayesian Models.” Statistics and Computing 24, no. 6 (November 2014): 997–1016. https://doi.org/10.1007/s11222-013-9416-2.

Examples

# even simple examples may take a while
cv <- loocv(schools, pooling = "partial")
print(cv)      # returns the lpd value
attributes(cv) # more information is included in the object

baggr

Bayesian Aggregate Treatment Effects

v0.4.0
GPL (>= 3)
Authors
Witold Wiecek [cre, aut], Rachael Meager [aut], Brice Green [ctb] (predict(), loo_compare, many visuals), Trustees of Columbia University [cph] (tools/make_cc.R)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.