Computes the expected log pointwise predictive density (ELPD) as the sum of
pointwise log predictive density contributions (\(\mathrm{lppd}_i\)), using
ptw_log_pred_density(). ELPD is returned on the utility scale (higher is
better), consistent with the sign convention used throughout this package.
Arguments
- ylp
A numeric matrix or three-dimensional array of log predictive densities or probabilities:
Matrix (\(S \times n\)): \(S\) posterior draws (chains merged) by \(n\) observations.
Array (\(I \times C \times n\)): \(I\) MCMC iterations per chain, \(C\) chains, and \(n\) observations. Converted to an \(S \times n\) matrix internally.
- log_weights
Optional numeric matrix of unnormalized log-importance weights with dimensions \(S \times n\). Weights are column-normalized before computing each per-observation contribution.
- pointwise
Optional numeric vector of precomputed \(\mathrm{lppd}_i\) values. When supplied,
ylpandlog_weightsare ignored.
Value
An object of class "measure": a list with:
estimatesA 1 \(\times\) 2 matrix. The row is named after the measure, the columns are
EstimateandSE(standard error).pointwiseAn \(n \times 1\) matrix of per-observation values. The column is named after the measure.
extraOptional. Auxiliary data for the standard error of a difference. Most measures do not set it.
Attributes measure (i.e., measure name) and dims (draws \(\times\)
observations) are also set. Use print() for a readable summary.
Details
$$\mathrm{elpd} = \sum_{i=1}^{n} \mathrm{lppd}_i,$$
where each \(\mathrm{lppd}_i\) is computed by ptw_log_pred_density().
The standard error is \(\sqrt{n}\,\mathrm{sd}(\mathrm{lppd}_i)\).
Examples
ylp <- matrix(log(c(0.2, 0.4, 0.3, 0.8)), nrow = 2)
measure_elpd(ylp)
#>
#> Computed from 2 draws by 2 observations.
#>
#> Estimate SE
#> elpd -1.8 0.6
# With unnormalized importance weights (e.g., PSIS-LOO)
lw <- matrix(log(c(0.7, 0.3, 0.6, 0.4)), nrow = 2)
measure_elpd(ylp, log_weights = lw)
#>
#> Computed from 2 draws by 2 observations.
#>
#> Estimate SE
#> elpd -2.0 0.7
# From a draws x chains x observations array
LLarr <- example_loglik_array()
measure_elpd(LLarr)
#>
#> Computed from 1000 draws by 32 observations.
#>
#> Estimate SE
#> elpd -80.3 3.2