Diagnostics for Laplace and ADVI approximations and Laplace-loo and ADVI-loo
Source:R/psis_approximate_posterior.R
psis_approximate_posterior.RdDiagnostics for Laplace and ADVI approximations and Laplace-loo and ADVI-loo
Usage
psis_approximate_posterior(
log_p = NULL,
log_g = NULL,
log_liks = NULL,
cores,
save_psis,
...,
log_q = NULL
)Arguments
- log_p
The log-posterior (target) evaluated at S samples from the proposal distribution (g). A vector of length S.
- log_g
The log-density (proposal) evaluated at S samples from the proposal distribution (g). A vector of length S.
- log_liks
A log-likelihood matrix of size S * N, where N is the number of observations and S is the number of samples from q. See
loo.matrix()for details. Default isNULL. Then only the posterior is evaluated using the k_hat diagnostic.- cores
The number of cores to use for parallelization. This defaults to the option
mc.coreswhich can be set for an entire R session byoptions(mc.cores = NUMBER). The old optionloo.coresis now deprecated but will be given precedence overmc.coresuntilloo.coresis removed in a future release. As of version 2.0.0 the default is now 1 core ifmc.coresis not set, but we recommend using as many (or close to as many) cores as possible.Note for Windows 10 users: it is strongly recommended to avoid using the
.Rprofilefile to setmc.cores(using thecoresargument or settingmc.coresinteractively or in a script is fine).
- save_psis
Should the
psisobject created internally byloo()be saved in the returned object? Theloo()function callspsis()internally but by default discards the (potentially large)psisobject after using it to compute the LOO-CV summaries. Settingsave_psis=TRUEwill add apsis_objectcomponent to the list returned byloo. This is useful if you plan to use theE_loo()function to compute weighted expectations after runningloo. Several functions in the bayesplot package also acceptpsisobjects.- log_q
Deprecated argument name (the same as log_g).
Value
If log likelihoods are supplied, the function returns a "loo" object,
otherwise the function returns a "psis" object.
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 (journal version, preprint arXiv:1507.04544).
Vehtari, A., Simpson, D., Gelman, A., Yao, Y., and Gabry, J. (2024). Pareto smoothed importance sampling. Journal of Machine Learning Research, 25(72):1-58. PDF