Learn R Programming

CLRtools (version 0.1.0)

compare_models_loo: Compare Bayesian Models Using PSIS-LOO

Description

This function compares multiple Bayesian models using PSIS-LOO (Pareto-smoothed importance sampling leave-one-out cross-validation) from the loo package. It returns a comparison table and a plot of the estimated ELPD (expected log predictive density) with standard errors.

Usage

compare_models_loo(..., k = 0.7, name_log = "log_lik")

Value

A list with the following elements:

p_loo

A ggplot object showing elpd_loo values and standard errors for each model.

comparison

A loo_compare table comparing the relative fit of the models.

models_loo

A named list of individual loo objects for each model.

Arguments

...

Two or more stanfit model objects to compare. Each model must include pointwise log-likelihood values (usually named log_lik) stored in the generated quantities or transformed parameters block.

k

A numeric value specifying the Pareto-k diagnostic threshold. Default is 0.7.

name_log

A character string specifying the name of the log-likelihood parameter in the model. Default is "log_lik".

Details

This function performs PSIS-LOO diagnostics on each model, creates a visual summary, and ranks them using loo_compare. Ensure that each model includes pointwise log-likelihood values named consistently (e.g., "log_lik").