
WAIC from paired coefficient and covariance draws
Source:R/mniw_model_comparison.R
compute_sample_waic.RdEvaluates row-wise multivariate normal log likelihoods for paired posterior draws, using log-sum-exp aggregation for the predictive density and sample variances for the WAIC penalty.
Arguments
- Y
Finite numeric response matrix with dimensions n by q.
- X
Finite numeric design matrix with dimensions n by p. Include an intercept column explicitly when required.
- B_samples
Finite numeric array with dimensions p by q by S, containing posterior coefficient draws. At least two draws are required.
- Sigma_samples
Finite numeric array with dimensions q by q by S, containing symmetric positive-definite posterior response covariance draws. Slice s must be paired with slice s of
B_samples.- return_log_lik
Logical scalar. If
TRUE, also return the S by nlog_likmatrix, suitable forloo::waic()orloo::loo(). The loo package is optional and is not called by this function.
Value
The same summaries and pointwise matrix as
compute_analytical_waic(), with an additional log_lik matrix when
return_log_lik = TRUE.
Details
Each response row is one observation, with likelihood
\(Y_i\mid B,\Sigma\sim N_q(x_i B,\Sigma)\) independently across rows.
The draws can come from any posterior with this likelihood; they need not
follow an MNIW law. The analytical comparison requires an MNIW posterior.
Arrays retain three dimensions even when p, q, or n equals one.
The penalty uses sample variance with denominator S - 1, matching
loo::waic() for a matrix of log likelihoods. Correlated draws can
increase Monte Carlo error; this function does not diagnose convergence.