Learn R Programming

JointAI (version 1.1.0)

auto_corr: 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)

Value

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

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.

Examples

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

Run the code above in your browser using DataLab