Skip to contents

Checks MCMC convergence diagnostics — R-hat and effective sample size — against user-specified thresholds, and reports any parameters that fail either check.

Usage

diagnose_model(fitted_model, rhat_threshold = 1.1, eff_sample_threshold = 100)

Arguments

fitted_model

A fitted model object of class EpiStrainDynamics.fit, as returned by fit_model().

rhat_threshold

R-hat threshold for convergence (default 1.1). Values above this threshold indicate chains have not mixed well.

eff_sample_threshold

Effective sample size threshold (default 100). Values below this threshold indicate the posterior samples for a parameter are too autocorrelated to reliably estimate its distribution.

Value

An object of class list, returned invisibly, containing:

convergence

Logical; TRUE if no parameter fails either threshold

rhat_issues

Character vector of parameter names with R-hat above rhat_threshold

eff_sample_issues

Character vector of parameter names with effective sample size below eff_sample_threshold

max_rhat

The largest R-hat value across all parameters

min_neff

The smallest effective sample size across all parameters

summary

The full rstan::summary() table the above are derived from

Examples

if (FALSE) { # interactive()
mod <- construct_model(
  pathogen_structure = single(
    case_timeseries = sarscov2$cases,
    time = sarscov2$date
  ),
  method = random_walk()
)
fit <- fit_model(mod)
diagnose_model(fit)
}