auto_corr: Autocorrelation of MCMC samples

View source: R/crosscorr.R

auto_corrR Documentation

Autocorrelation of MCMC samples

Description

This function obtains the autocorrelation of the MCMC samples in an JointAI object via coda::autocorr.diag(). autocorr_plot() visualizes the results using ggplot2.

Usage

auto_corr(object, lags = 0:30, by_chain = TRUE, outcome = 1L,
  start = NULL, end = NULL, thin = NULL)

auto_corr_plot(object, lags = 0:30, by_chain = TRUE, outcome = 1L,
  start = NULL, end = NULL, thin = NULL)

Arguments

object

an object of class JointAI

lags

a numeric vector indicating the lags to consider

by_chain

logical; should the autocorrelation be computed for each chain separately?

outcome

integer; index of the outcome model for which the autocorrelation should be plotted

start

the first iteration of interest (see window.mcmc)

end

the last iteration of interest (see window.mcmc)

thin

thinning interval (integer; see window.mcmc). For example, thin = 1 (default) will keep the MCMC samples from all iterations; thin = 5 would only keep every 5th iteration.

Value

a matrix or a list of matrix objects if by_chain = TRUE, or a ggplot() object for autocorr_plot().

Examples

fit <- lm_imp(y ~ C1 + C2 + B2, data = wideDF, n.iter = 200)
auto_corr(fit)
auto_corr_plot(fit)


JointAI documentation built on Jan. 30, 2026, 5:07 p.m.