These functions are wrappers around the E_loo function (loo package) that provide compatibility for rstanarm models.

# S3 method for stanreg
loo_predict(
  object,
  type = c("mean", "var", "quantile"),
  probs = 0.5,
  ...,
  psis_object = NULL
)

# S3 method for stanreg
loo_linpred(
  object,
  type = c("mean", "var", "quantile"),
  probs = 0.5,
  transform = FALSE,
  ...,
  psis_object = NULL
)

# S3 method for stanreg
loo_predictive_interval(object, prob = 0.9, ..., psis_object = NULL)

Arguments

object

A fitted model object returned by one of the rstanarm modeling functions. See stanreg-objects.

type

The type of expectation to compute. The options are "mean", "variance", and "quantile".

probs

For computing quantiles, a vector of probabilities.

...

Currently unused.

psis_object

An object returned by psis. If missing then psis will be run internally, which may be time consuming for models fit to very large datasets.

transform

Passed to posterior_linpred.

prob

For loo_predictive_interval, a scalar in \((0,1)\) indicating the desired probability mass to include in the intervals. The default is prob=0.9 (\(90\)% intervals).

Value

A list with elements value and pareto_k.

For loo_predict and loo_linpred the value component is a vector with one element per observation.

For loo_predictive_interval the value component is a matrix with one row per observation and two columns (like predictive_interval). loo_predictive_interval(..., prob = p) is equivalent to loo_predict(..., type = "quantile", probs = c(a, 1-a)) with a = (1 - p)/2, except it transposes the result and adds informative column names.

See E_loo and pareto-k-diagnostic for details on the pareto_k diagnostic.

References

Vehtari, A., Gelman, A., and Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing. 27(5), 1413--1432. doi:10.1007/s11222-016-9696-4. arXiv preprint: http://arxiv.org/abs/1507.04544/

Yao, Y., Vehtari, A., Simpson, D., and Gelman, A. (2018) Using stacking to average Bayesian predictive distributions. Bayesian Analysis, advance publication, doi:10.1214/17-BA1091. (online).

Gabry, J. , Simpson, D. , Vehtari, A. , Betancourt, M. and Gelman, A. (2019), Visualization in Bayesian workflow. J. R. Stat. Soc. A, 182: 389-402. doi:10.1111/rssa.12378, (journal version, arXiv preprint, code on GitHub)

Examples

# \dontrun{ if (!exists("example_model")) example(example_model) # optionally, log-weights can be pre-computed and reused psis_result <- loo::psis(log_ratios = -log_lik(example_model))
#> Warning: Relative effective sample sizes ('r_eff' argument) not specified. PSIS n_eff will not be adjusted based on MCMC n_eff.
#> Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
loo_probs <- loo_linpred(example_model, type = "mean", transform = TRUE, psis_object = psis_result)
#> Instead of posterior_linpred(..., transform=TRUE) please call posterior_epred(), which provides equivalent functionality.
str(loo_probs)
#> List of 2 #> $ value : num [1:56] 0.4209 0.1157 0.0703 0.1037 0.1688 ... #> $ pareto_k: num [1:56] 0.6827 0.2988 0.5858 0.0642 0.4565 ...
loo_pred_var <- loo_predict(example_model, type = "var", psis_object = psis_result) str(loo_pred_var)
#> List of 2 #> $ value : num [1:56] 0.064117 0.002284 0.004407 0.000646 0.007451 ... #> $ pareto_k: num [1:56] 0.62 0.235 0.664 0.278 0.373 ...
loo_pred_ints <- loo_predictive_interval(example_model, prob = 0.8, psis_object = psis_result) str(loo_pred_ints)
#> List of 2 #> $ value : num [1:56, 1:2] 3 0 0 0 1 0 0 2 0 0 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : chr [1:2] "10%" "90%" #> $ pareto_k: num [1:56] 0.594 0.372 0.683 0.223 0.493 ...
# }