# Does it make sense to perform a one-tailed Kolmogorov-Smirnov test?

Is it meaningful and possible to perform a one-tailed KS test? What would the null hypothesis of such a test be? Or is the KS test inherently a two-tailed test?

I would benefit from an answer that helped me understand the distribution of $$DD$$ (I am working through Massey’s 1951 paper, and find the description challenging, for example are $$D+D^{+}$$ and $$D−D^{-}$$ the supremum and infimum of the differences of the non-absolute value of differences in empirical CDFs?).

Followup question: how are $$pp$$-values for $$D+D^{+}$$ and $$D−D^{-}$$ obtained? So many of the publications I am encountering are presenting tabled values, rather than CDF of $$DnD_{n}$$, $$D+D^{+}$$ and $$D−D^{-}$$.

Update: I just discovered the related question What’s the null hypothesis in a one-sided Kolmogorov-Smirnov test?, which I missed on my initial scan before writing this one.

Is it meaningful and possible to perform a one-tailed KS test?

Definitely, in the sense that one-tailed is generally used with the Kolmogorov-Smirnov. Because we’re talking about many differences at once (the cdf is a function, not a value), the direction of a difference is not a single fixed thing – the cdf might be greater at one place and less at another (so both directional tests might be significant at the same time).

is the KS test inherently a two-tailed test?

Not at all.

What would the null hypothesis of such a test be?

You don’t make it clear whether you’re talking about the one-sample or the two sample test. My answer here covers both – if you regard $$FXF_X$$ as representing the cdf of the population from which an $$XX$$ sample was drawn, it’s two-sample, while you get the one sample case by regarding $$FXF_X$$ as some hypothesized distribution ($$F0F_0$$, if you prefer).

You could in some cases write the null as an equality (e.g.if it wasn’t seen as possible for it to go the other way), but if you want to write a directional nulls for a one tailed alternative, you could write something like this:

$$H0:FY(t)≥FX(t)H_0: F_Y(t)\geq F_X(t)$$

$$H1:FY(t), for at least one $$tt$$

(or its converse for the other tail, naturally)

If we add an assumption when we use the test that they're either equal or that $$FYF_Y$$ will be smaller, then rejection of the null implies (first order) stochastic ordering / first order stochastic dominance. In large enough samples, it's possible for the F's to cross - even several times, and still reject the one-sided test, so the assumption is strictly needed for stochastic dominance to hold.

Loosely if $$FY(t)≤FX(t)F_Y(t)\leq F_X(t)$$ with strict inequality for at least some $$tt$$ then $$YY$$ 'tends to be bigger' than $$XX$$.

Adding assumptions like this is not weird; it's standard. It's not particularly different from assuming (say in an ANOVA) that a difference in means is because of a shift of the whole distribution (rather than a change in skewness, where some of the distribution shifts down and some shifts up, but in such a way that the mean has changed).

So let's consider, for example, a shift in mean for a normal:

The fact that the distribution for $$YY$$ is shifted right by some amount from that for $$XX$$ implies that $$FYF_Y$$ is lower than $$FXF_X$$. The one-sided Kolmogorov-Smirnov test will tend to reject in this situation.

Similarly, consider a scale shift in a gamma:

Again, the shift to a larger scale produces a lower F. Again, the one-sided Kolmogorov-Smirnov test will tend to reject in this situation.

There are numerous situations where such a test may be useful.

So what are $$D+D^+$$ and $$D−D^-$$?

In the one-sample test, $$D+D^+$$ is the maximum positive deviation of the sample cdf from the hypothesized curve (that is the biggest distance the ECDF is above $$F0F_0$$, while $$D−D^-$$ is the maximum negative deviation - the biggest distance the ECDF is below $$F0F_0$$). Both $$D+D^+$$ and $$D−D^-$$ are positive quantities:

A one tailed Kolmogorov-Smirnov test would look at either $$D+D^+$$ or $$D−D^-$$ depending on the direction of the alternative. Consider the one tailed one sample test:

$$H0:FY(t)≥F0(t)H_0: F_Y(t)\geq F_0(t)$$

$$H1:FY(t), for at least one $$tt$$

To test this one - we want sensitivity to $$YY$$ being stochastically larger than hypothesized (its true $$FF$$ is lower than $$F0F_0$$). So unusually large values of $$D−D^-$$ will tend to occur when the alternative is true. As a result, to test against the alternative $$FY(t), we use $$D−D^-$$ in our one-tailed test.

Follow-up question: how are p-values for $$D+D^+$$ and $$D−D^−$$ obtained?

It's not a simple thing. There are a variety of approaches that have been used.

If I recall correctly one of the ways the distribution was obtained via the use of Brownian bridge processes (this document seems to support that recollection).

I believe this paper, and the paper by Marsaglia et al here both cover some of the background and give computational algorithms with lots of references.

Between those, you'll get a lot of the history and various approaches that have been used. If they don't cover what you need, you'll probably need to ask this as a new question.

So many of the publications I am encountering are presenting tabled values, rather than CDF of $$DnD_n$$, $$D+D^+$$ and $$D−D^−$$

That's not particularly a surprise. If I remember right, even the asymptotic distribution is obtained as a series, and in finite samples it's discrete and not in any simple form. In either case and there's no convenient way to present the information except as either a graph or a table.