So far, we've only looked at tests for parameters of a distribution. Non-parametric tests refer to tests about the distribution as a whole; the three examples of such tests we'll discuss in this lecture are:
Kolmogorov-Smirnov. Given X1,…,Xn sampled (i.i.d.) from a distribution with CDF F, we have:
H0:=“The CDF F matches another CDF F0.”∥H1:=“The CDF F does not match another CDF F0.”
Kolmogorov-Lilliefors. Given X1,…,Xn sampled (i.i.d.) from a distribution X∼P, we have:
H0:=“The random variable X is Gaussian.”∥H1:=“The random variable X is not Gaussian.”
Two-Sample Test. Given X1,…,Xn∼FX and Y1,…,Ym∼FY (i.i.d.), where FX and FY are CDFs, we have:
H0:=“The CDF FX matches the CDF FY.”∥H1:=“The CDF FX does not match the CDF FY.”
All three of these tests share the same idea behind their test statistic.
Definition. Given X1,…,Xn sampled (i.i.d.) from a distribution, their empirical CDF is F^n(t):=n1∑i=1n1(Xi≤t).
Then the test statistic for all three tests will look something like Tn:=suptF^n(t)−F0(t), which represents the greatest absolute difference between the empirical CDF F^n(t) and the expected CDF F0(t).
§ The Kolmogorov-Smirnov Test
Here's the main idea behind the test.
Theorem. (Kolmogorov-Smirnov Distribution) Assuming the null hypothesis, suppose X1,…,Xn are sampled (i.i.d.) from the distribution with continuous CDF F0. Then the distribution of the test statistic Tn does not depend on F0.
Remark. This should not be particularly surprising. For example, it should be clear why F0(t) and F0(2t) would yield the same test statistic: scaling the x-axis of a CDF shouldn't affect the maximum-detected difference in y-values.
Proof: The point is that the CDF F0 has no relevance at all, and the lemma below explains why.
Lemma. If a random variable X has continuous CDF F0, then F0(X)∼Unif(0,1).
Proof: Ignoring the real-analysis technicalities, here's the gist of why this should feel true.
When we say X has continuous CDF F0, that just means X can be generated by picking a random number λ∼Unif(0,1), then setting X=F0−1(λ). The conclusion is immediate from here. □
The above lemma lets us rewrite the empirical distribution, which then lets us write the test statistic Tn with no reference to F0. Below, we set Ui:=F0(Xi), so that by the lemma, these are all i.i.d. samples from Unif(0,1).
That last expression is the definition of the Kolmogorov-Smirnov distributionKSn, which does not depend on F0. ■
And, of course, the above theorem easily gives rise to a Kolmogorov-Smirnov Test of level α. Just compute the test statistic Tn and reject H0 if Tn>KSn,α.
§ The Kolmogorov-Lilliefors Test
To test whether a random variable is Gaussian, we rework our test statistic like so:
Tn:=tsupF^n(t)−Φμ^,σ^2(t) where μ^=sample mean and σ^2=sample variance
Theorem. (Kolmogorov-Lilliefors Distribution) Assuming the null hypothesis, suppose X1,…,Xn are sampled (i.i.d.) from the distribution N(μ,σ2). Then the distribution of the test statistic Tn does not depend on μ or σ2.
Remark. This one really shouldn't be unexpected. It should be clear why the CDFs F0(t) and F0(σt−μ) would yield the same test statistic, because scaling or shifting the x-axis shouldn't affect the maximum-detected difference in y-values.
Proof: Say that Xi=μ+σ⋅Zi, where Z1,…,Zn∼N(0,1). The goal is to rewrite Tn so that its value is dependent only on the values of {Zi}i=1n (which, of course, do not depend on μ or σ2).
Here are the relevant lemmas. Their proofs are very straightforward.
Lemma 1. Let G^n(t) denote the empirical CDF of the {Zi}i=1n. Then F^n(t)=G^n([σt−μ]).
Lemma 2. We have σ^2=σ2⋅σ^Z,n2, where σ^Z,n is a function of only the {Zi}i=1n.
Lemma 3. As a corollary of Lemma 2, if Φ is the CDF of N(0,1), then we have:
The RHS of the above is dependent only on the {Zi}i=1n, so its distribution is dependent only on n. It follows the Kolmogorov-Lilliefors distributionKLn. ■
And, of course, you get a Kolmogorov-Lilliefors test out of this, too.
Remark. It turns out that KLn,α<KSn,α for all n. This means that if we mistakenly used the KS quantiles for a KL test, we would reject the null too infrequently.
§ The Two-Sample Test
To check if two sets of samples {Xi}i=1n and {Yi}i=1m came from the same CDF, we use the following test statistic:
Tn,m:=tsupF^X,n(t)−F^Y,m(t).
Theorem. (Two-Sample Distribution) Assuming the null hypothesis, suppose {Xi}i=1n and {Yi}i=1m are both sampled from the same continuous CDF F. Then the distribution of the test statistic Tn,m does not depend on F.
Proof: Same proof as with the KS distribution. Say Ui:=F(Xi) and Vi:=F(Yi), which by the lemma are i.i.d. samples from Unif(0,1). Then: