trim.mcmc {BayesPIM}R Documentation

Subset MCMC draws (burn-in and thinning)

Description

Takes an mcmc.list object (or a list of MCMC chains) and returns a new mcmc.list containing only the specified subset of iterations (from burnin to end) with the specified thinning interval.

Usage

trim.mcmc(obj, burnin = 1, end = nrow(as.matrix(obj[[1]])), thining = 1)

Arguments

obj

An object of class mcmc.list (or a list of matrices) containing MCMC draws.

burnin

A numeric scalar giving the starting iteration of the MCMC sample to keep. Defaults to 1.

end

A numeric scalar giving the last iteration of the MCMC sample to keep. Defaults to the number of rows in the first chain of obj.

thining

A numeric scalar for the thinning interval. Defaults to 1.

Details

This function subsets each chain of the input obj to the specified iteration indices and creates a new mcmc.list. If you have multiple MCMC chains, each chain is trimmed in the same way.

Value

An object of class mcmc.list, representing the trimmed subset of the original MCMC draws.

Examples

# Example with a toy mcmc.list
set.seed(123)
x1 <- matrix(rnorm(2000), ncol = 2)
x2 <- matrix(rnorm(2000), ncol = 2)
mcmc_list <- mcmc.list(mcmc(x1), mcmc(x2))

# Trim and thin the chains
trimmed_mcmc <- trim.mcmc(mcmc_list, burnin = 100, end = 800, thining = 5)
summary(trimmed_mcmc)


[Package BayesPIM version 1.0.0 Index]