# How to tell if a set of MCMC chains mixed?

Let's say I have a Bayesian network with both numeric and categorical variables. I run several MCMC chains to collect samples from the distribution. Now, if the chains are "similar enough" after some number of samples, it is reasonable to assume that they mixed.

The problem is this "similar enough" thingy. In literature I always get blocked by notions like "autocovariance" and "variance", which apply to numerical variables only. What to do when the network contains also categorical variables?

One idea would be to use some statistical distance applied to empirical distributions produced by the chains. If the mutual distances are small enough, then declare victory. The problem with this approach is that again the distance 'measures' are tailored either to categorical probability distributions (Kullback–Leibler divergence) or to numerical distributions (Kolmogorov–Smirnov statistic).

Is there some other approach?

• I don't know what you mean about KL divergences being tailored to categorical distributions - KL divergence is easily defined using integrals for absolutely continuous densities relative to some reference measure. But you might want to look into mixing times for Markov chains. – Don Walpola Aug 19 '19 at 19:06
• @DonWalpola I mean that if you have a distribution that puts P(0) = 1 then the KL divergence from a distribution where P(0.001) = 1 is the same as from a distribution where P(1000) = 1. That is, the divergence is oblivious to the numeric values of the probability distribution. – Martin Drozdik Aug 20 '19 at 11:44
• Well, in a trivial sense, you’re right - the value of the KL divergence would be undefined in both those cases as your distributions (which are also degenerate in your example) do not even have the same support. I suggest you check your definitions again. – Don Walpola Aug 20 '19 at 12:22
• @DonWalpola you're right. My mistake. Just replace the KL divergence with the total variation distance and the argument holds. That is, some statistical distances take the actual values of the random variable into account, while others do not. – Martin Drozdik Aug 20 '19 at 12:36
• Well, without going off the rails into technical details, any true metric (which KL divergence is not, but TV is) will be agnostic to the particular values you input: |3 - 2| = |103 - 102|. No metric would fit the definition of a metric if it privileges points with certain magnitudes. You may be thinking of something like a norm, but I don’t think that has much to do with your goal. If what you really want is to know how well mixed your chains are, you definitely want their mixing times which are a measure of convergence to their stationary distribution (assuming you chains have one). – Don Walpola Aug 20 '19 at 12:58