Skip to contents

elpd_loo() estimates leave-one-out cross-validation from one Bayesian fit by Pareto-smoothed importance sampling (PSIS-LOO); elpd_waic() computes WAIC. Both take the pointwise log-likelihood log p(y_i | theta_s) of each posterior draw (rows) and observation (columns), and match the loo package.

Usage

elpd_loo(log_lik, r_eff = NULL)

elpd_waic(log_lik)

Arguments

log_lik

A matrix, one row per posterior draw and one column per observation.

r_eff

Optional relative efficiency of the draws per observation (1 for independent draws).

Value

A list: estimates (named elpd, se, p and ic, the information criterion -2 elpd) and pointwise; for elpd_loo() also pareto_k per observation and k_threshold, above which an observation's estimate is unreliable.

Examples

set.seed(1)
y <- rnorm(20)
mu <- rnorm(400, mean(y), 1 / sqrt(20))
ll <- sapply(y, function(yi) dnorm(yi, mu, 1, log = TRUE))
elpd_loo(ll)$estimates
#>        elpd          se           p          ic 
#> -27.1824277   3.0778492   0.7764155  54.3648554 
elpd_waic(ll)$estimates
#>        elpd          se           p          ic 
#> -27.1740218   3.0765552   0.7680096  54.3480437