# How to compare the distributions of two variables

The attached figure plots the distributions of two variables.

I want to demonstrate statistically how closely the the two distributions match each other. What is the best way of doing this?

• How many points do you have ? Commented May 23, 2015 at 9:05
• "best" in what sense? What are you trying to be best at? (what makes one thing better than another for your purposes?) Do you have the individual data points in both samples? Commented May 23, 2015 at 9:16

## 3 Answers

There might not be a best solution as such. But if you are trying to visualize the distribution similarity, you can use violin plots instead of box-plots.

However, if statistical measures of similarity is what you are trying to calculate, then I think you should try fitting the distributions against several standard distributions and see how well they compare. If you are familiar with GLDs (Generalized Lambda Distributions), you can obtain GLD fits for each of the distributions and compare their resulting parameters.

• Not familiar with GLDs I'm afraid. I'm wondering...might comparing their distributions with chi-squared be an option? Commented May 23, 2015 at 7:28
• It might not be the best option. But yes, it is an option. It all depends on how good a measure you require. Commented May 23, 2015 at 7:41

To compare two distributions you have several options.

First of all you can visualize the two distributions:

• plot the probability density functions
• plot the cumulative distribution functions
• a quantile-quantile plot

Then, you can statistically characterize the differences between the two distributions:

• run statistical hypothesis tests to check whether there is a significant difference between the two samples; in your case (distributions seem to be a bit skewed) you should rely on non-parametric Mann-Whitney or Kolmogorov-Smirnov test (if you don't know how such tests work, you can find nice explanations on CrossValidated)
• compute Kullback–Leibler divergence (and similar measures)

In particular, Kullback-Leibler divergence is a non-symmetric measure of the difference between two probability distributions, say $P$ and $Q$. More precisely, the KS divergence of $Q$ to $P$, $D_{KL}(P||Q)$, is a measure of the information lost when $Q$ is used to approximate $P$.

For discrete probability distributions $P$ and $Q$, the KS divergence is defined as: $$D_{KL}(P||Q) = \sum_{i}P(i) \ln \frac{P(i)}{Q(i)},$$ whereas in the continuous case: $$D_{KL}(P||Q) = \int_{-\infty}^{\infty}p(x) \ln \frac{p(x)}{q(x)}dx,$$

where $p$ and $q$ represent the densities of $P$ and $Q$.

Note that the KS divergence is always non-negative: $D_{KL}(P||Q) \geq 0$, and the equality holds if and only if $P = Q$ almost everywhere.

• I'm afraid the estimate of Kullback-Leibler based on two samples is not an easy thing to deal with. Commented May 23, 2015 at 9:04
• I guess it depends on the size of the two samples... Commented May 23, 2015 at 9:19

Check out the Kullback-Leibler divergence (http://en.wikipedia.org/wiki/Kullback_Leibler_divergence). This describes the loss of information when one distribution is used to approximate the other

• I think @luciano has one sample of each distribution, he does not have the distributions themsleves. And I'm afraid the estimate of Kullback-Leibler based on two samples is not an easy thing to deal with. Commented May 23, 2015 at 9:05