rstanarm (version 2.15.3)

loo_predict.stanreg: Compute weighted expectations using LOO

Description

These functions are wrappers around the E_loo function (loo package).

Usage

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

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

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

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", "var" (variance), and "quantile".

probs

A vector of probabilities. Ignored unless type is "quantile".

...

Optional arguments passed to psislw. If lw is specified these arguments are ignored.

lw

An optional matrix of (smoothed) log-weights. If lw is missing then psislw is executed internally, which may be time consuming for models fit to very large datasets.

transform
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

loo_predict and loo_linpred return a vector with one element per observation. The only exception is if type="quantile" and length(probs) >= 2, in which case a separate vector for each element of probs is computed and they are returned in a matrix with length(probs) rows and one column per observation.

loo_predictive_interval returns 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.

Examples

Run this code
# NOT RUN {
if (!exists("example_model")) example(example_model)
head(loo_predictive_interval(example_model, prob = 0.8, cores = 2))

# optionally, log-weights can be pre-computed and reused
psis <- loo::psislw(-log_lik(example_model), cores = 2)
loo_predictive_interval(example_model, prob = 0.8, lw = psis$lw_smooth)
loo_predict(example_model, type = "var", lw = psis$lw_smooth)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab