Passes the pointwise log likelihood of log_lik.mvgam() to
loo::waic(). loo.mvgam() estimates the same ELPD by PSIS and
reports Pareto k diagnostics that say when to distrust it. Vehtari
et al. (2017) recommend it over WAIC.
Usage
# S3 method for class 'mvgam'
waic(
x,
...,
compare = TRUE,
resp = NULL,
pointwise = FALSE,
model_names = NULL,
incl_autocor = TRUE,
incl_dynamics = NULL,
by_series = FALSE
)Arguments
- x
A fitted
mvgamorjsdgamobject.- ...
Further arguments to
log_lik.mvgam(), such asndraws.- compare, resp, pointwise, model_names
The arguments of brms::waic.brmsfit.
respscopes a multivariate fit to one response. Supplying one of the others raises an error.loo_compare()ranks severalwaic()results.- incl_autocor
Logical, default
TRUE. Passed tolog_lik.mvgam().TRUEscores each observation under the latent trend state the model inferred at that time. The ELPD then describes the series that was observed.FALSEscores the covariate part of the model alone.- incl_dynamics
Deprecated alias for
incl_autocor.- by_series
Logical, default
FALSE.TRUEreturns a data frame with one row per series and columnsseries,elpd,se_elpd,pandn_obs, asspOccupancy::waicOcc(by.sp = TRUE)ranks species. An occupancy or N-mixture fit is scored per site, each site counted in its species.
Value
A waic object (see loo::waic()), or with
by_series = TRUE a data frame of per-series estimates.
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:1413-1432. doi:10.1007/s11222-016-9696-4
See also
loo.mvgam() estimates the same ELPD by PSIS.
lfo_cv.mvgam() scores forecasts from rolling origins. The
forecast evaluation article
compares models by approximate and exact cross-validation.
Other model comparison:
bridge_sampler.mvgam(),
compare_elpds(),
kfold.mvgam(),
lfo_cv.mvgam(),
log_lik.mvgam(),
loo.mvgam(),
loo_compare.mvgam_lfo(),
mvgam_loo_extras,
posterior_average.mvgam()
Examples
# \dontrun{
# A Poisson GAM without a latent trend. PSIS approximates each
# held-out count of such a model well (see Details of ?loo.mvgam)
set.seed(13)
simdat <- sim_mvgam(family = poisson(), n_series = 1L,
n_timepoints = 120L, trend_model = "None")
mod <- mvgam(y ~ s(x), data = simdat$data_train,
family = poisson(), chains = 2, silent = 2)
#> Warning: 11 of 2000 (1.0%) transitions ended with a divergence.
#> See https://mc-stan.org/misc/warnings for details.
# }
# \dontrun{
# The WAIC estimate of the ELPD, with its effective number of
# parameters p_waic. A p_waic above 0.4 for any observation raises
# a warning that recommends loo()
waic(mod)
#> Warning:
#> 3 (3.3%) p_waic estimates greater than 0.4. We recommend trying loo instead.
#>
#> Computed from 2000 posterior draws and 90 log-likelihood terms.
#>
#> Estimate SE
#> elpd_waic -208.8 8.4
#> p_waic 8.0 1.5
#> waic 417.5 16.8
#>
#> 3 (3.3%) p_waic estimates greater than 0.4. We recommend trying loo instead.
# The PSIS estimate of the same ELPD. Its Pareto k diagnostics mark
# the observations it estimates poorly
loo(mod)
#>
#> Computed from 2000 posterior draws and 90 log-likelihood terms.
#>
#> Estimate SE
#> elpd_loo -208.9 8.4
#> p_loo 8.1 1.5
#> looic 417.7 16.8
#> ------
#> MCSE of elpd_loo is 0.1.
#> MCSE and ESS estimates assume MCMC draws (r_eff in [0.5, 1.2]).
#>
#> All Pareto k estimates are good (k < 0.7).
#> See help('pareto-k-diagnostic') for details.
# Next, loo_compare() ranks several models by either estimate
# }
