MIT 18.650 — Lecture 19

Non-parametric Tests

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:

All three of these tests share the same idea behind their test statistic.

Definition. Given X1,,XnX_1, \dots, X_n sampled (i.i.d.) from a distribution, their empirical CDF is F^n(t):=1ni=1n1(Xit)\hat{F}_n(t) := \frac{1}{n} \sum_{i = 1}^n \mathds{1}(X_i \leq t).

Then the test statistic for all three tests will look something like Tn:=suptF^n(t)F0(t)T_n := \sup_t \left|\hat{F}_n(t) - F_0(t)\right|, which represents the greatest absolute difference between the empirical CDF F^n(t)\hat{F}_n(t) and the expected CDF F0(t)F_0(t).

§ The Kolmogorov-Smirnov Test

Here's the main idea behind the test.

Theorem. (Kolmogorov-Smirnov Distribution) Assuming the null hypothesis, suppose X1,,XnX_1, \dots, X_n are sampled (i.i.d.) from the distribution with continuous CDF F0F_0. Then the distribution of the test statistic TnT_n does not depend on F0F_0.

Remark. This should not be particularly surprising. For example, it should be clear why F0(t)F_0(t) and F0(t2)F_0(\frac{t}{2}) would yield the same test statistic: scaling the xx-axis of a CDF shouldn't affect the maximum-detected difference in yy-values.

Proof: The point is that the CDF F0F_0 has no relevance at all, and the lemma below explains why.

Lemma. If a random variable XX has continuous CDF F0F_0, then F0(X)Unif(0,1)F_0(X) \sim \mathrm{Unif}(0, 1).

Proof: Ignoring the real-analysis technicalities, here's the gist of why this should feel true.

When we say XX has continuous CDF F0F_0, that just means XX can be generated by picking a random number λUnif(0,1)\lambda \sim \mathrm{Unif}(0, 1), then setting X=F01(λ)X = F_0^{-1}(\lambda). The conclusion is immediate from here.   \square

The above lemma lets us rewrite the empirical distribution, which then lets us write the test statistic TnT_n with no reference to F0F_0. Below, we set Ui:=F0(Xi)U_i := F_0(X_i), so that by the lemma, these are all i.i.d. samples from Unif(0,1)\mathrm{Unif}(0, 1).

Tn=suptRF^n(t)F0(t)=suptR[1ni=1n1(Xit)]F0(t)=suptR[1ni=1n1(UiF0(t))]F0(t)=sups[0,1][1ni=1n1(Uis)]sKSn.\begin{align*}T_n = \sup_{t \in \mathbb{R}} \left|\hat{F}_n(t) - F_0(t)\right| & = \sup_{t \in \mathbb{R}} \left|\left[ \frac{1}{n}\sum_{i = 1}^n \mathds{1}(X_i \leq t) \right] - F_0(t)\right| \\ & = \sup_{t \in \mathbb{R}} \left|\left[ \frac{1}{n}\sum_{i = 1}^n \mathds{1}(U_i \leq F_0(t)) \right] - F_0(t)\right| = \sup_{s \in [0, 1]} \left|\left[ \frac{1}{n}\sum_{i = 1}^n \mathds{1}(U_i \leq s) \right] - s\right| \sim \mathrm{KS}_n.\end{align*}

That last expression is the definition of the Kolmogorov-Smirnov distribution KSn\mathrm{KS}_n, which does not depend on F0F_0.   \blacksquare

And, of course, the above theorem easily gives rise to a Kolmogorov-Smirnov Test of level α\alpha. Just compute the test statistic TnT_n and reject H0H_0 if Tn>KSn,αT_n > \mathrm{KS}_{n, \alpha}.

§ The Kolmogorov-Lilliefors Test

To test whether a random variable is Gaussian, we rework our test statistic like so:

Tn:=suptF^n(t)Φμ^,σ^2(t)    where    μ^=sample mean    and    σ^2=sample varianceT_n := \sup_t\left| \hat{F}_n(t) - \Phi_{\hat{\mu}, \hat{\sigma}^2}(t) \right| ~~~ \text{ where } ~~~ \hat{\mu} = \text{sample mean} ~~~ \text{ and } ~~~ \hat{\sigma}^2 = \text{sample variance}

Theorem. (Kolmogorov-Lilliefors Distribution) Assuming the null hypothesis, suppose X1,,XnX_1, \dots, X_n are sampled (i.i.d.) from the distribution N(μ,σ2)\mathcal{N}(\mu, \sigma^2). Then the distribution of the test statistic TnT_n does not depend on μ\mu or σ2\sigma^2.

Remark. This one really shouldn't be unexpected. It should be clear why the CDFs F0(t)F_0(t) and F0(tμσ)F_0\left(\frac{t - \mu}{\sigma}\right) would yield the same test statistic, because scaling or shifting the xx-axis shouldn't affect the maximum-detected difference in yy-values.

Proof: Say that Xi=μ+σZiX_i = \mu + \sigma \cdot Z_i, where Z1,,ZnN(0,1)Z_1, \dots, Z_n \sim \mathcal{N}(0, 1). The goal is to rewrite TnT_n so that its value is dependent only on the values of {Zi}i=1n\{Z_i\}_{i = 1}^n (which, of course, do not depend on μ\mu or σ2\sigma^2).

Here are the relevant lemmas. Their proofs are very straightforward.

Lemma 1. Let G^n(t)\hat{G}_n(t) denote the empirical CDF of the {Zi}i=1n\{Z_i\}_{i = 1}^n. Then F^n(t)=G^n([tμσ])\hat{F}_n(t) = \hat{G}_n\left( \left[\frac{t - \mu}{\sigma}\right] \right).

Lemma 2. We have σ^2=σ2σ^Z,n2\hat{\sigma}^2 = \sigma^2 \cdot \hat{\sigma}_{Z, n}^2, where σ^Z,n\hat{\sigma}_{Z, n} is a function of only the {Zi}i=1n\{Z_i\}_{i = 1}^n.

Lemma 3. As a corollary of Lemma 2, if Φ\Phi is the CDF of N(0,1)\mathcal{N}(0, 1), then we have:

Φμ^,σ^2(t)=Φ(tXˉnσ^)=Φ(tμσZˉnσσ^Z,n)=Φ([tμσ]Zˉnσ^Z,n).\Phi_{\hat{\mu}, \hat{\sigma}^2}(t) = \Phi\left(\frac{t - \bar{X}_n}{\hat{\sigma}}\right) = \Phi\left(\frac{ t - \mu - \sigma \cdot \bar{Z}_n }{ \sigma \cdot \hat{\sigma}_{Z, n} }\right) = \Phi\left( \frac{\left[\frac{t - \mu}{\sigma}\right] - \bar{Z}_n}{\hat{\sigma}_{Z, n}} \right).

Using Lemma 1 and Lemma 3, we can now rewrite TnT_n like so:

Tn=suptRF^n(t)Φμ^,σ^2(t)=suptRG^n([tμσ])Φ([tμσ]Zˉnσ^Z,n)=supsRG^n(s)Φ(sZˉnσ^Z,n)KLn.T_n = \sup_{t \in \mathbb{R}} \left| \hat{F}_n(t) - \Phi_{\hat{\mu}, \hat{\sigma}^2}(t) \right| = \sup_{t \in \mathbb{R}} \left| \hat{G}_n\left( \left[\frac{t - \mu}{\sigma}\right] \right) - \Phi\left( \frac{\left[\frac{t - \mu}{\sigma}\right] - \bar{Z}_n}{\hat{\sigma}_{Z, n}} \right) \right| = \sup_{s \in \mathbb{R}} \left| \hat{G}_n(s) - \Phi\left(\frac{s - \bar{Z}_n}{\hat{\sigma}_{Z, n}}\right) \right| \sim \mathrm{KL}_n.

The RHS of the above is dependent only on the {Zi}i=1n\{Z_i\}_{i = 1}^n, so its distribution is dependent only on nn. It follows the Kolmogorov-Lilliefors distribution KLn\mathrm{KL}_n.   \blacksquare

And, of course, you get a Kolmogorov-Lilliefors test out of this, too.

Remark. It turns out that KLn,α<KSn,α\mathrm{KL}_{n, \alpha} < \mathrm{KS}_{n, \alpha} for all nn. This means that if we mistakenly used the KS\mathrm{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\{X_i\}_{i = 1}^n and {Yi}i=1m\{Y_i\}_{i = 1}^m came from the same CDF, we use the following test statistic:

Tn,m:=suptF^X,n(t)F^Y,m(t).T_{n, m} := \sup_t \left| \hat{F}_{X, n}(t) - \hat{F}_{Y, m}(t) \right|.

Theorem. (Two-Sample Distribution) Assuming the null hypothesis, suppose {Xi}i=1n\{X_i\}_{i = 1}^n and {Yi}i=1m\{Y_i\}_{i = 1}^m are both sampled from the same continuous CDF FF. Then the distribution of the test statistic Tn,mT_{n, m} does not depend on FF.

Proof: Same proof as with the KS\mathrm{KS} distribution. Say Ui:=F(Xi)U_i := F(X_i) and Vi:=F(Yi)V_i := F(Y_i), which by the lemma are i.i.d. samples from Unif(0,1)\mathrm{Unif}(0, 1). Then:

Tn,m=suptR[1ni=1n1(Xit)][1mi=1m1(Yit)]=suptR[1ni=1n1(UiF(t))][1mi=1m1(ViF(t))]=sups[0,1][1ni=1n1(Uis)][1mi=1m1(Vis)].\begin{align*}T_{n, m} & = \sup_{t \in \mathbb{R}}\left| \left[\frac{1}{n}\sum_{i = 1}^n \mathds{1}(X_i \leq t)\right] - \left[\frac{1}{m}\sum_{i = 1}^m \mathds{1}(Y_i \leq t)\right] \right| \\ & = \sup_{t \in \mathbb{R}}\left| \left[\frac{1}{n}\sum_{i = 1}^n \mathds{1}(U_i \leq F(t))\right] - \left[\frac{1}{m}\sum_{i = 1}^m \mathds{1}(V_i \leq F(t))\right] \right| \\ & = \sup_{s \in [0, 1]}\left| \left[\frac{1}{n}\sum_{i = 1}^n \mathds{1}(U_i \leq s)\right] - \left[\frac{1}{m}\sum_{i = 1}^m \mathds{1}(V_i \leq s)\right] \right|.\end{align*}

And that doesn't depend on FF.   \blacksquare

And, yeah, you can perform tests with this, too.