The Kolmogorov-Smirnov (KS) statistic is a measure of the distance between the empirical distribution functions of two samples. In the context of the KS test, the empirical distribution function (EDF) for a sample is a step function that increases by 1/n at each sample point, where n is the number of observations in the sample.
The KS statistic itself is the maximum difference between the two EDFs over the range of all possible values. More formally, the KS statistic D is defined as:
D = max|x| (|F1(x) - F2(x)|)
where F1(x) and F2(x) are the EDFs of the first and second sample, respectively, and the maximum is calculated over all points x in the combined dataset. The KS statistic ranges from 0 to 1, where 0 indicates that the samples are identical, and 1 indicates that the samples are completely different.
The p-value obtained from a KS test indicates the probability of observing a test statistic as extreme as, or more extreme than, the one observed, if the null hypothesis is true. A small p-value (typically less than 0.05) leads to the rejection of the null hypothesis, suggesting that the two samples have significantly different distributions.
The KS test is non-parametric and distribution-free, which means it makes no assumption about the distribution of data. Here are some suitable scenarios for using the KS test:
-
Comparing a sample with a reference probability distribution: To test if the sample comes from the specified probability distribution. This is a one-sample KS test.
-
Comparing two samples: To test whether two independent samples have been drawn from the same distribution or from different distributions. This is a two-sample KS test, which you are applying in your analysis.
-
Non-parametric hypothesis testing: When you do not want to make assumptions about the normality of the data or when the sample size is too small to rely on parametric tests.
-
Goodness-of-fit tests: To test if the observed frequencies of events or values differ significantly from the expected frequencies, which would imply a distribution hypothesis.
Keep in mind that the KS test is sensitive to both location and shape of the empirical cumulative distribution functions of the two samples. It is not recommended to use the KS test for small sample sizes or when your data has many ties due to the discrete or rounded values. Also, while KS test gives you whether two distributions differ, it doesn't specify how they differ or where the difference occurs.