| elpd.sdmTMB_cv | R Documentation |
Converts the pointwise out-of-sample log predictive densities
(cv_loglik) from sdmTMB_cv() into a loo elpd_generic object.
This lets loo::loo_compare() compare models, including a standard error
of the difference in expected log predictive density.
## S3 method for class 'sdmTMB_cv'
elpd(x, ...)
x |
Output from |
... |
Not used. |
Models compared with loo::loo_compare() must be fit to the same data
with the same folds (e.g., via fold_ids) and should use the same
predictive argument. loo only checks that the number of
observations matches. The standard errors reflect variation across
observations, not the Monte Carlo error from nsim.
The printed object refers to a "1 by N log-likelihood matrix" because the
pointwise values are already integrated over draws within
sdmTMB_cv().
An object of class elpd_generic and loo. See loo::elpd().
sdmTMB_cv(), compare_deviance() for in-sample deviance
explained.
if (requireNamespace("loo", quietly = TRUE)) {
mesh <- make_mesh(pcod_2011, c("X", "Y"), cutoff = 20)
folds <- rep(1:4, length.out = nrow(pcod_2011))
m1 <- sdmTMB_cv(density ~ 1, data = pcod_2011, mesh = mesh,
family = tweedie(), fold_ids = folds)
m2 <- sdmTMB_cv(density ~ depth_scaled + depth_scaled2,
data = pcod_2011, mesh = mesh, family = tweedie(), fold_ids = folds)
loo::loo_compare(list(null = loo::elpd(m1), depth = loo::elpd(m2)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.