multichainACF: ACF plots for multiple Markov chains

Medha Agarwal, Dootika Vats

2020-09-04

The R package multichainACF produces autocorrelation and autocovariance plots suitable for multiple Markov chains (with the same transition). Parallel implementations of Markov chains may concentrate in different parts of the state space particularly when the Markov chains are slow mixing. In such a situation running acf on each individual Markov chain can yield underestimates for the autocorrelation.

Following Agarwal and Vats (2020), we plot globally-centered ACF plots where the Markov chains are centered around the global mean from all chains.

Demonstrative example

We demonstrate the striking difference in estimation in ACF plots. Consider a random-walk Metropolis-Hastings sampler for a univariate mixture of Gaussians target density. Let the target density be \[ f(x) = 0.7\,f(x; -5, 1) + 0.3\,f(x; 5, 0.5)\,, \] where \(f(x; a,b)\) is the density of a normal distribution with mean \(a\) and variance \(b\). We run two Markov chains with starting values distributed to the two modes. The trace plots below indicates that in the first \(10^4\) steps, the chains do not jump modes so that both Markov chains yield significantly different estimates of the population mean, \(\mu\). At \(n = 10^5\), both Markov chains have traversed the state space reasonably and yield similar estimates of \(\mu\).



Simply, an ACF plot on any of the two chains for the shorter run of \(10^4\) should indicate high correlation and what is popularly termed as “bad mixing”. However, the old ACF plots using acf give a false indication of the level of autocorrelation induced by the Markov chain kernel.

par(mfrow = c(1,2))
acf(short_run[[1]], main = "Chain 1 for short run") # ACF of chain 1
acf(short_run[[2]], main = "Chain 2 for short run") # ACF of chain 2

Of course, once the Markov chains have jumped modes, the old acf function is finally able to assess the slow convergence.

par(mfrow = c(1,2))
acf(long_run[[1]], main = "Chain 1 for long run") # ACF of chain 1
acf(long_run[[2]], main = "Chain 2 for long run") # ACF of chain 2


Globally centered ACF plots

The globally-centered ACF estimator accounts for the discrepancy in sample means between two chains leading to a far improved quality of estimation of autocorrelations even for shorter runs of the Markov chains. The ACF plots can be constructed using globalACF in the package. In addition to global centering, the package also provides a visual for assessing ACF plots for all Markov chains (for a specific component), with averaged ACF curves given in a solid line.


Plots in the style of the traditional ACF plots are also possible by setting avg = FALSE and picking a particular chain.


References

Agarwal, Medha, and Dootika Vats. 2020. “Globally-Centered Autocovariances in MCMC.” Arxiv. https://arxiv.org/abs/2009.01799.