# How can the F-test reject the null hypothesis while the KS test does not?

Suppose I have two datasets, $$\mathbf{a}$$ and $$\mathbf{b}$$. I want to test whether the two datasets are different in a statistically significant way.

To compute the F-test, I take the ratio of the variances of each dataset and compare this to F values based on some significance level (e.g. $$\alpha = 0.05$$) and the number of degrees of freedom. If the F value I computed lies outside the bounds of $$1\pm\alpha$$, then the null hypothesis is rejected (i.e. the two datasets are different in a statistically significant way).

To compute the KS test, I find the ECDF of each dataset and the find the maximum vertical distance between the ECDFs to compute the D-statistic. Similar, to the F-test, if the D-statistic is greater than some critical value, the null hypothesis is rejected (i.e. the two datasets are different in a statistically significant way).

My intuition is that the tests should generally give similar results. If something is statistically significant, it should be statistically significant for both tests, no? Perhaps this intuition is wrong. But, at the very least, I thought that the KS test was more sensitive than the F-test. As such, if the F-test rejects the null hypothesis, then I thought for sure, the KS test would also reject the null.

But I have found many cases where this is not true. I have some examples where the F-test results in rejection of the null hypothesis while the KS test does not!

Any explanation of why this could be is appreciated.

• Because they have two different null hypotheses and are therefore testing different things? – Alexis Dec 31 '19 at 20:24
• Even if they were to have had the same null (imagine the question was asking about two tests of goodness of fit of normality, say), they have non-equivalent test statistics (there's a different partial order imposed on the sample space) -- they would measure sample deviation from the null differently. As a result you should typically see differences in p-values. – Glen_b Jan 1 '20 at 1:53
• While it has been hinted at in the above comments, note that the $F$-test requires normality, while the KS test does not. (From another point of view, the $F$-test’s null hypothesis includes that your samples are from normally distributed populations.) The question is still valid if there were no such assumption in the $F$-test, but beware that your examples may simply arise from the $F$-test “detecting” non-normality. – Wrzlprmft Jan 1 '20 at 13:47
• I ran a quick simulation, comparing random samples, normal distribution, n of 25, mean of 0, sd of either 1 or 2. In this case, R's var.test reported p <= 0.05, 92% of the time. And R's ks.test reported p <= 0.05, 15% of the time. So at least under the conditions of this simulation, the KS test is severely underpowered relative to the F test to detect a difference in variance (unless I did something wrong). – Sal Mangiafico Jan 1 '20 at 13:48

Significance testing consists of defining a rejection region, and rejecting if the data is in that region. The size of the region is its $$\alpha$$ value. If two different regions are different shapes, then even if one is smaller than the other, there can be places that are inside the smaller one but not in the larger one.

Dave’s answer explains that KS tests many different attributes, such as mean, variance, and multimodality. Suppose we restrict our attention to just mean and variance. We can then represent the sample on a two-dimensional plot, with one, say, differences in mean being the horizontal dimension and difference in variance being vertical:

The $$F$$-test’s rejection region (blue) are two horizontal strips in this space: if difference in variance is too positive, or too negative, it rejects the null. The KS test’s rejection region (green) is (with some simplification) a ring: anything too far from the origin in any direction will be rejected. We can (again, with some simplification), consider each to have a “radius”, and anything outside that radius results in the null being rejected. But for the $$F$$-test, only the vertical distance from the $$x$$-axis is considered, while the distance from the origin is considered for the KS test.

If both have the same $$\alpha$$, then since the KS looks at both dimensions, its radius has to be larger. So if your sample has a small difference in mean, and a difference in variance that is slightly more than the $$F$$-test’s “radius”, then it will be within the KS radius.

• Indeed, you can draw such a plot, simply by assuming a specific distribution and simulating a bunch (an obvious candidate for the distribution to begin with would be the normal, since that lets the F have the right type I error rate). You can start with say a standard normal for one group and see how varying the mean and variance of the other affects the rejection rate at some given pair of sample sizes (the specific location and scale you start at doesn't matter, you can generalize to other choices). – Glen_b Jan 1 '20 at 22:59
• It would be somewhat akin to the work required to generate this plot, in that case comparing non-rejection regions for a three group two-way ANOVA and the corresponding Kruskal-Wallis test (two parameters of interest). This is discussed here – Glen_b Jan 2 '20 at 0:43
• Nice. I have not seen this kind of graphical explanation before. – Alexis Jan 4 '20 at 18:56
• Wow that is a great figure to explain the problem. Where did you get it from so I can cite it properly if I use it? – Darcy Apr 29 '20 at 19:27

The F-test specifically examines for differences in variance and does not need to be sensitive to other differences such as mean. KS has to be sensitive to every kind of distributional difference, whether that difference is mean, variance, or multimodality.

Think of the F-test as a specialist that will be great at finding differences in variance at the expense of perhaps missing other differences. If all you want is to check for variance differences, use the test that specializes in variance differences. If your question is more broad, if there is any difference between the populations, then KS would be the more appropriate test. A drawback to KS is that it won’t tell you what that difference is, while an F test would signal a difference in variances (as a t-test would signal a difference in means).

You are correct that if your populations have different variances and F finds that while KS misses it, that is a type II error by KS.

• Specifically the F test's differences in within group and between group variances. – Alexis Dec 31 '19 at 20:25
• @Alexis ANOVA is one use of the F-test, but nothing prevents us from using F to examine for variance differences between a control and treatment group. – Dave Dec 31 '19 at 20:30
• The gentle reminder is appreciated, thank you. – Alexis Jan 1 '20 at 0:25