Skip to contents

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_fit object.

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.draws stored 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() and cpo() hand the map to tulpa::tulpa_criteria() as group; 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 for cover() (the areal field node, when sites are grouped via group_var) and occu_cover() (the site_cell map); a non-spatial fit has no cells, so "cell" errors there. Equivalent to passing group = the cell map directly, without hand-building it. dic() has no cross-validation unit – it is a plug-in deviance over all observations – and rejects loo.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's n.threads.outer. NULL (default) uses all but four logical cores, at most two under R CMD check; other families ignore it.

...

For dic() and cpo(), forwarded to tulpa::tulpa_criteria() (e.g. chunk_size, or an explicit group = for a custom leave-one-group-out unit). waic() and loo() accept only group =, 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, as n.draws above. 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.