Skip to contents

Usage

extract_HPD_mcmc(object, prob = 0.99)

Arguments

object

An `rstan` model fit object (of class `stanfit`) containing posterior samples.

prob

Numeric. The probability mass to include within the HPD interval. Default is `0.99`, corresponding to the 99

A list of MCMC chains (as `mcmc` objects) filtered to retain only the samples lying within the HPD intervals for all parameters. Chains are truncated to have equal length, corresponding to the smallest number of retained samples among all chains. Extracts and filters posterior samples from an `rstan` MCMC object to retain only those within the specified Highest Posterior Density (HPD) interval. This function computes HPD intervals for each parameter and removes draws falling outside these intervals across all chains. The function first converts the Stan model output into a list of MCMC chains using `rstan::As.mcmc.list()`. For each chain, it computes the HPD intervals for every parameter via `coda::HPDinterval()`. Only iterations where all parameters fall within their respective HPD bounds are kept. To ensure consistency across chains, the function trims all filtered chains to the same number of rows (equal to the smallest retained sample size).