# Similarity between 2 statistical distributions

Is there any index that measures similarity between 2 gaussian distributions of 1-D data (may have slightly different number of points) considering their mean shift, variance shift, difference in shapes(like one is symmetric and the other is skewed) etc. and gives similarity between [0,1]?

I am using Hedges' index for the same but it does not give a similarity index between 0 and 1. It can be greater than 1 as well, so it is difficult to interpret it.

Also, no pattern of the data is known beforehand, if it helps in any way for the answer.

• No pattern of data contradics your first statement where you ask for difference between 2 gaussians. Do you know something about the distribution of your samples? Apr 5 at 16:04
• @rapaio I meant by no pattern that there is no knowledge of any trend that the data might follow, example - periodicity or something similar. I am sorry if it confused you. The distribution can be skewed or normal and the sample sizes can be different for the distributions which is accounted by Hedges' index. Also, can you let me know what more information will you require, if any? Apr 5 at 16:08
• Additional question since you are talking about periodicity or trends, your two samples are time dependent samples (time series)? If that is the case I do not think you can use Hedge's g. I do not know something better than what you use. If you want to normalize you can transform that into something like 1/(1+Hg) which is 1 for identical samples and decreases towards 0 when they are not similar Apr 5 at 16:45
• PS: I do not understand the minus for the question. I can admit that the language is not precise, but it is a legit question and we should help each other. That should be the purpose, I think. Apr 5 at 16:48

One method is Kolmogorov-Smirnov test. Kolmogorov-Smirnov test checks whether two samples are drawn from the same continuous distribution where sample sizes can be different. It's p-value is close to 0 when two samples follow the same distribution and close to 1 when they do not follow the same distribution. So you can use 1 - (p-value) as a similarity metric.

import numpy as np
from scipy.stats import ks_2samp

np.random.seed(52)

n1 = 200
n2 = 300

mu_1 = 5
mu_2 = 5.1

sigma_1 = 0.3
sigma_2 = 0.2

sample_1 = np.random.normal(mu_1, sigma_1, n1)
sample_2 = np.random.normal(mu_2, sigma_2, n2)

result = ks_2samp(sample_1, sample_2)

print(result.pvalue)


1.4998994601889137e-08

Note that there are also other methods such as Bhattacharyya distance, Kullback–Leibler divergence. Some implementations for Kullback-Leibner can be found also here.

• OP asks for a method to measure similarity. While hypothesis tests can signal if two samples are different those tells you nothing about effect size, no matter which p values they produce. HT can,t be used for that purpose Apr 6 at 5:12
• @Orkun does the Kolmogorov-Smirnov test depend a lot on the difference in the 2 sample sizes. Because I am getting very different p-values if mean and variance of 2 samples are same, just their sizes are different. Apr 6 at 5:38