waic(), loo(), dic(), and cpo() on a tobs_fit build the family
pointwise log-likelihood matrix once and hand it to the engine's single
criteria layer tulpa::tulpa_criteria(), which derives WAIC / DIC / CPO /
LPML / PSIS-LOO. DIC additionally evaluates the deviance at the posterior
mean of the parameters, supplied by the family-specific
.tobs_loglik_at_mean().
Usage
# S3 method for class 'tobs_fit'
waic(x, n.draws = 1000L, loo.unit = c("obs", "cell"), n.threads = NULL, ...)
# S3 method for class 'tobs_fit'
loo(x, n.draws = 1000L, loo.unit = c("obs", "cell"), n.threads = NULL, ...)
# S3 method for class 'tobs_fit'
dic(object, n.draws = 1000L, n.threads = NULL, ...)
# S3 method for class 'tobs_fit'
cpo(
object,
n.draws = 1000L,
loo.unit = c("obs", "cell"),
n.threads = NULL,
...
)
# S3 method for class 'tobs_fit'
pointwise_loglik(object, ndraws = NULL, ...)Arguments
- x, object
A
tobs_fitobject.- n.draws
Posterior draws used to build the pointwise log-likelihood (the cover / occu_cover paths sample this many; the draw-matrix families use the first
n.drawsstored draws). Default 1000.- loo.unit
The cross-validation unit for
waic()/loo()/cpo()."obs"(default) is the family's pointwise unit – one column of the log-likelihood per plot (cover) or site (occu_cover) – and is byte-identical to the call without the argument."cell"switches to leave-one-group-out cross-validation (LOGO-CV): the fit's own per-observation cell map folds the log-likelihood columns of a spatial cell into one, so each cell is a fold instead of each plot / site.waic()andcpo()hand the map totulpa::tulpa_criteria()asgroup;loo()applies the same fold itself and runs PSIS on the resulting[n_draws x n_cells]matrix, whose column is the cell's joint conditional log-likelihood per draw, so the importance ratio inverts the whole cell's likelihood. A whole cell is a larger perturbation of the posterior than a single row, so the Pareto k values are correspondingly higher and are the diagnostic to read before trusting the cell-level number. Implemented forcover()(the areal field node, when sites are grouped viagroup_var) andoccu_cover()(thesite_cellmap); a non-spatial fit has no cells, so"cell"errors there. Equivalent to passinggroup =the cell map directly, without hand-building it.dic()has no cross-validation unit – it is a plug-in deviance over all observations – and rejectsloo.unit.- n.threads
Threads for the parallel
occu_cover()pointwise log-likelihood (the compact / ragged path). The draw loop is embarrassingly parallel, so this is the WAIC / LOO analogue of the fit'sn.threads.outer.NULL(default) uses all but four logical cores, at most two underR CMD check; other families ignore it.- ...
For
dic()andcpo(), forwarded totulpa::tulpa_criteria()(e.g.chunk_size, or an explicitgroup =for a custom leave-one-group-out unit).waic()andloo()accept onlygroup =, which folds the pointwise matrix before the loo call, and reject any other argument.- ndraws
For
pointwise_loglik(), the posterior draws used to build the matrix, asn.drawsabove.NULL(default) uses 1000.
Value
dic() and cpo() return a tulpa_criteria object. waic()
returns a waic object and loo() a psis_loo object from the loo
package; read the estimates from $estimates (e.g.
waic(fit)$estimates["waic", "Estimate"]). Both carry the
cross-validation unit they scored in their "loo_unit" attribute.
Details
waic() and loo() are the loo package's generics and build their
objects through loo::waic() and loo::loo() on the same pointwise matrix
(loo() via PSIS with relative effective sample sizes), so
loo::loo_compare() and the rest of that ecosystem read them directly.
dic() and cpo() are tulpa's, and return a tulpa_criteria object.