How to correct high autocorrelation?

In @_eigenfoo’s excellent cookbook, he advises checking “if your chains are impaired by high autocorrelation”. I have a trace that seems to be impaired by high autocorrelation. For example, here is an autocorrelation plot for one variable, that has a mean of 2.0 effective samples in a trace of 1200 samples (NUTS):

Now what? I know I need to reparameterize the model, but I am not sure how to start. Certainly this RV is super-simple:

potential_sale_mu = pm.Normal('potential_sale_mu', mu=0, sigma=2)

So the problem must be downstream, among variables that use potential_sale_mu.

How can I figure out what change to make?

Hi David,
This looks quite correlated indeed! I would check which variables are highly correlated with each other: an az.plot_pair is usually useful here. This should give you hints about which variables are problematic for the sampler, and at which range.
Hope this helps :vulcan_salute:

1 Like

Update: I refactored the model (for other reasons), and the autocorrelation largely disappeared. Here is the plot for the same RV now:


Well done @bridgeland! I’m curious: what and how did you refactor?

There were several variables that model situations that are conceptually binomials. But hierarchical models of binomials do not simulate well, so the binomials were approximated as truncated normals. I refactored; each conceptual binomial is now a product of n and a beta. Problem solved.


Nice! Let us know if you publish that model somewhere :wink: