fit-method-loo: Leave-one-out cross-validation (LOO-CV)

fit-method-looR Documentation

Leave-one-out cross-validation (LOO-CV)

Description

The ⁠$loo()⁠ method computes approximate LOO-CV using the loo package. In order to use this method you must compute and save the pointwise log-likelihood in your Stan program. See loo::loo.array() and the loo package vignettes for details.

Usage

loo(variables = "log_lik", r_eff = TRUE, moment_match = FALSE, ...)

Arguments

variables

(character vector) The name(s) of the variable(s) in the Stan program containing the pointwise log-likelihood. The default is to look for "log_lik". This argument is passed to the $draws() method.

r_eff

(multiple options) How to handle the r_eff argument for loo():

  • TRUE (the default) will automatically call loo::relative_eff.array() to compute the r_eff argument to pass to loo::loo.array().

  • FALSE or NULL will avoid computing r_eff (which can sometimes be slow), but the reported ESS and MCSE estimates can be over-optimistic if the posterior draws are not (near) independent.

  • If r_eff is anything else, that object will be passed as the r_eff argument to loo::loo.array().

moment_match

(logical) Whether to use a moment-matching correction for problematic observations. The default is FALSE. Using moment_match=TRUE will result in compiling the additional methods described in fit-method-init_model_methods. This allows CmdStanR to automatically supply the functions for the log_lik_i, unconstrain_pars, log_prob_upars, and log_lik_i_upars arguments to loo::loo_moment_match().

...

Other arguments (e.g., cores, save_psis, etc.) passed to loo::loo.array() or loo::loo_moment_match.default() (if moment_match = TRUE is set).

Value

The object returned by loo::loo.array() or loo::loo_moment_match.default().

See Also

The loo package website with documentation and vignettes.

Examples


## Not run: 
# the "logistic" example model has "log_lik" in generated quantities
fit <- cmdstanr_example("logistic")
loo_result <- fit$loo(cores = 2)
print(loo_result)

## End(Not run)


stan-dev/cmdstanr documentation built on April 21, 2024, 5:38 a.m.