= Kolmogorov-Smirnov test
{c}
The one-sample <Kolmogorov-Smirnov test> checks <goodness of fit> by comparing an <empirical distribution function> $F_n$ with a specified <cumulative distribution function> $F_0$. Its <Kolmogorov-Smirnov statistic> $D_n$ is the largest vertical gap anywhere between the two curves. Every threshold asks the same concrete question: what proportion of the observations are at or below it, and what <probability> does the proposed <probability distribution> assign there? A large discrepancy supplies evidence against the <null hypothesis>.
For example, four stipulated observations $(1/10,2/5,4/5,9/10)$ compared with the <uniform distribution> on $[0,1]$ give $D_4=3/10$. Just before $4/5$, only two observations have been counted, so the <empirical distribution function> approaches $1/2$, while $F_0$ approaches $4/5$. The <Kolmogorov-Smirnov statistic> section calculates every jump-side gap. These are exact illustrative numbers, not experimental measurements or a claim of <statistical significance>.
The ordinary one-sample calibration assumes <independent and identically distributed> real observations and a <simple hypothesis> $H_0:F=F_0$, with $F_0$ a <continuous function> fixed before inspecting these observations. All <statistical parameters> of $F_0$ must be specified.<NIST and SEMATECH e-Handbook of Statistical Methods/1.3.5.16. Kolmogorov-Smirnov Goodness-of-Fit Test>{ref} Under that <null hypothesis>, the <probability integral transform> gives $U_i=F_0(X_i)$ with the <uniform distribution> on $(0,1)$, retaining <independence>. Consequently the <sampling distribution> of $D_n$ depends on the <sample size> $n$, but not on the particular <continuous> $F_0$. This is the useful sense in which the calibration is distribution-free.
For the <exponential distribution> of rate one, $F_0(x)=1-e^{-x}$ for $x\geq0$. Take $x_i=-\log(1-u_i)$ for the four stipulated $u_i$ above. The <probability integral transform> changes the horizontal coordinates but preserves both the <order statistics> and their cumulative heights, so the same <Kolmogorov-Smirnov statistic> $3/10$ appears on both scales. More generally, for <continuous> $F_0$, the jump-side formulas depend only on $F_0(X_{(i)})$. Strict increase everywhere is unnecessary: intervals on which $F_0$ is constant have <probability> zero under the <null hypothesis>. This explains the invariance without assuming a strictly positive <probability density function>.
\Image[/kolmogorov-smirnov-probability-integral-transform.png]
{title=The probability integral transform preserves the Kolmogorov-Smirnov gap on exponential and uniform scales}
{description=The same four stipulated points are shown as $x_i=-\log(1-u_i)$ on the left and $u_i\in\{1/10,2/5,4/5,9/10\}$ on the right. Open circles indicate left limits of the <empirical distribution function>, filled circles its values. The gap $3/10$ is approached from below the third observation on both scales.}
The observed <Kolmogorov-Smirnov statistic> is a discrepancy, whereas its <p-value> is a tail <probability> under the <null hypothesis>:
$$
p=\Pr_{H_0}(D_n^{\mathrm{new}}\geq d_{\mathrm{obs}}).
$$
Here $D_n^{\mathrm{new}}$ is computed from a fresh sample of the same <sample size>. Choose a <significance level> $\alpha$ before the test and reject when the calibrated <p-value> is at most $\alpha$. The value $D_4=3/10$ alone supplies neither a <p-value> nor a rejection decision. Failure to reject does not establish that the <null hypothesis> is true. A finite-sample calibration and the asymptotic <Kolmogorov-Smirnov theorem> are distinct; a cutoff for $D_n$ must be rescaled before use with $\sqrt nD_n$.<NIST and SEMATECH e-Handbook of Statistical Methods/1.3.5.16. Kolmogorov-Smirnov Goodness-of-Fit Test>{ref}
Fitting <statistical parameters> on the tested observations replaces $F_0$ by the random $F_{\widehat\theta}$. The resulting transformed observations need not be <independent and identically distributed> uniforms, so the ordinary reference law fails. The <Lilliefors test> addresses a particular fitted <normal distribution>. More general <parametric bootstrap> calibration must simulate from the fitted <statistical model> and repeat the fitting in every replicate; holding the fitted <statistical parameters> fixed during those comparisons calibrates a different procedure. Such a <parametric bootstrap> requires its own validity justification rather than inheriting exactness from the simple-null test.
For a <discrete probability distribution>, $F_0(X)$ is generally not uniform. Equal observations also arise from rounding, so tied data require a calibration that accounts for the <discrete probability distribution> or the rounding rule. The discrepancy remains meaningful, but continuous-null <p-values> are not automatically valid. <Statistical dependence> likewise changes the reference law. The <two-sample Kolmogorov-Smirnov test> compares two <empirical distribution functions> and has a different calibration.<Kolmogorov-Smirnov Tests (ks.test, R stats documentation)>{ref}
Back to article page