loo_validation.bgmfit {bsitar} | R Documentation |
Perform leave-one-out (LOO) cross-validation
Description
The loo_validation() function is a wrapper around the
brms::loo()
function to perform approximate leave-one-out cross-validation
based on the posterior likelihood. See brms::loo()
for more details.
Usage
## S3 method for class 'bgmfit'
loo_validation(
model,
compare = TRUE,
resp = NULL,
dpar = NULL,
pointwise = FALSE,
moment_match = FALSE,
reloo = FALSE,
k_threshold = 0.7,
save_psis = FALSE,
moment_match_args = list(),
reloo_args = list(),
model_names = NULL,
ndraws = NULL,
draw_ids = NULL,
cores = 1,
deriv_model = NULL,
verbose = FALSE,
dummy_to_factor = NULL,
expose_function = FALSE,
usesavedfuns = NULL,
clearenvfuns = NULL,
envir = NULL,
...
)
loo_validation(model, ...)
Arguments
model |
An object of class |
compare |
A logical flag indicating if the information criteria of the
models should be compared using |
resp |
Optional names of response variables. If specified, predictions are performed only for the specified response variables. |
dpar |
Optional name of a predicted distributional parameter. If specified, expected predictions of this parameters are returned. |
pointwise |
A flag indicating whether to compute the full
log-likelihood matrix at once or separately for each observation.
The latter approach is usually considerably slower but
requires much less working memory. Accordingly, if one runs
into memory issues, |
moment_match |
A logical flag to indicate whether
|
reloo |
A logical flag indicating whether |
k_threshold |
The Pareto |
save_psis |
Should the |
moment_match_args |
An optional |
reloo_args |
An optional |
model_names |
If |
ndraws |
A positive integer indicating the number of posterior draws to
use in estimation. If |
draw_ids |
An integer specifying the specific posterior draw(s) to use
in estimation (default |
cores |
The number of cores to be used for parallel computations if
|
deriv_model |
A logical value specifying whether to estimate the
velocity curve from the derivative function or by differentiating the
distance curve. Set |
verbose |
A logical argument (default |
dummy_to_factor |
A named list (default
|
expose_function |
A logical argument (default |
usesavedfuns |
A logical value (default |
clearenvfuns |
A logical value indicating whether to clear the exposed
Stan functions from the environment ( |
envir |
The environment used for function evaluation. The default is
|
... |
Additional arguments passed to the |
Details
The function supports model comparisons using loo::loo_compare()
for comparing information criteria across models. For bgmfit
objects, LOO
is simply an alias for loo
. Additionally, you
can use brms::add_criterion()
to store information criteria in the fitted
model object for later use.
Value
If only one model object is provided, an object of class loo
is returned. If multiple objects are provided, an object of class
loolist
is returned.
Author(s)
Satpal Sandhu satpal.sandhu@bristol.ac.uk
See Also
Examples
# Fit Bayesian SITAR model
# To avoid mode estimation which takes time, the Bayesian SITAR model fit to
# the 'berkeley_exdata' has been saved as an example fit ('berkeley_exfit').
# See 'bsitar' function for details on 'berkeley_exdata' and 'berkeley_exfit'.
# Check and confirm whether model fit object 'berkeley_exfit' exists
berkeley_exfit <- getNsObject(berkeley_exfit)
model <- berkeley_exfit
# Perform leave-one-out cross-validation
loo_validation(model, cores = 1)