derive_chain: Helper Function for 'loo' calculation

View source: R/rstan_generics.R

derive_chainR Documentation

Helper Function for loo calculation

Description

This function accepts a log-likelihood matrix produced by id_post_pred and extracts the IDs of the MCMC chains. It is necessary to use this function as the second argument to the loo function along with an exponentiated log-likelihood matrix. See the package vignette How to Evaluate Models for more details.

Usage

derive_chain(ll_matrix = NULL)

Arguments

ll_matrix

A log-likelihood matrix as produced by the id_post_pred() function

Value

An integer vector of MCMC chain IDs extracted from the log-likelihood matrix, for use as the chain_id argument to relative_eff.

Examples


sim <- id_sim_gen()
est <- id_estimate(sim, model_type=1, fixtype='vb_full',
                   use_method="pathfinder", nchains=2, ncores=2)
ll <- id_post_pred(est, type='log_lik')
chain_ids <- derive_chain(ll)
# use with loo
loo::loo(exp(ll), r_eff=loo::relative_eff(exp(ll), chain_id=chain_ids))


idealstan documentation built on May 13, 2026, 1:08 a.m.