# Scipy ttest_ind versus ks_2samp. When to use which test

From the docs

scipy.stats.ks_2samp
This is a two-sided test for the null hypothesis that 2 independent samples are drawn from the same continuous distribution

scipy.stats.ttest_ind
This is a two-sided test for the null hypothesis that 2 independent samples have identical average (expected) values. This test assumes that the populations have identical variances by default.


Assuming that one uses the default assumption of identical variances, the second test seems to be testing for identical distribution as well. The only difference then appears to be that the first test assumes continuous distributions.

If that is the case, what are the differences between the two tests? What is the right interpretation if they have very different results? For example I have two data sets for which the p values are 0.95 and 0.04 for the ttest(tt_equal_var=True) and the ks test, respectively.

• Your question is really about when to use the independent samples t-test and when to use the Kolmogorov-Smirnov two sample test; the fact of their implementation in scipy is entirely beside the point in relation to that issue (I'd remove that bit). I am curious that you don't seem to have considered the (Wilcoxon-)Mann-Whitney test in your comparison (scipy.stats.mannwhitneyu), which many people would tend to regard as the natural "competitor" to the t-test for suitability to similar kinds of problems. Is there a reason for that? Can you show the data sets for which you got dissimilar results? Jul 16 '18 at 7:33
• I was not aware of the W-M-W test. Had a read over it and it seems indeed a better fit. The data is truncated at 0 and has a shape a bit like a chi-square dist. Jul 16 '18 at 8:36
• When you say it's truncated at 0, ... can you elaborate? Are <0 recorded as 0 (censored/Winsorized) or are there simply no values that would have been <0 at all -- they're not observed/not in the sample (distribution is actually truncated)? Jul 17 '18 at 3:48
• The distribution naturally only has values >= 0 Jul 17 '18 at 6:24
• Ah. I wouldn't call that truncated at all. Jul 17 '18 at 6:31