Kolmogorov-Smirnov Test Calculator
The Kolmogorov-Smirnov test measures the largest vertical distance between the empirical cumulative distribution function of a sample, Fₙ(x), and the cumulative function F(x) of a theoretical normal distribution. That distance is the D statistic: when it is small the observed distribution tracks the theoretical curve, and when it is large the sample departs systematically from it in some region.
The most common mistake with this test is to estimate the mean and standard deviation from the same sample and then read the classical Kolmogorov table. When the parameters are estimated from the data, D comes out smaller than it should and the classical p-value systematically understates the real departure; the correct reference is the Lilliefors distribution. This calculator computes both p-values, places them side by side, states plainly which one is valid, and reports how many times larger the classical value is.
Kolmogorov-Smirnov Test Statistic
Fₙ(x) = (number of observations ≤ x) / n — empirical distribution
F(x) = Φ( (x − μ) / σ ) — theoretical distribution
D⁺ = maxᵢ [ i/n − F(x₍ᵢ₎) ]
D⁻ = maxᵢ [ F(x₍ᵢ₎) − (i−1)/n ]
D = max(D⁺, D⁻) = supₓ |Fₙ(x) − F(x)|
λ = ( √n + 0.12 + 0.11/√n ) · D
p_classical = Q(λ) = 2·Σ_{j≥1} (−1)^{j−1} · e^{−2j²λ²}
Critical D (classical, α = 0.05): 1.358 / (√n + 0.12 + 0.11/√n)
Critical D (Lilliefors, α = 0.05): 0.895 / (√n − 0.01 + 0.85/√n)
H₀: the data come from the specified normal distributionWhen μ and σ are estimated from the same sample, the distribution of D changes, and the classical Q(λ) approximation then makes p look larger than it is. The correct reference is the Lilliefors (Dallal-Wilkinson) distribution — SPSS marks this with the "Lilliefors Significance Correction" footnote, and in R it corresponds to lillie.test() from the nortest package.
How to Calculate
- Paste all the values of your numeric variable into the box; at least 4 observations are required.
- Choose where the parameters of the theoretical distribution come from: pick "I will specify them" if you know μ and σ (from theory, a standard, or an earlier study), and "Estimate from the data" if you do not.
- Set the significance level; the default is α = 0.05.
- Read D, D⁺, and D⁻: a large D⁺ means the data pile up to the left of the theoretical curve, and a large D⁻ means they pile up to the right.
- Study the classical and Lilliefors p-values together in the comparison table; if the parameters were estimated, report only the Lilliefors row.
- Check the point of greatest separation between the two curves in the cumulative distribution chart, and the pattern of departure in the Q-Q plot.
Worked Examples
A right-skewed series where classical p and Lilliefors p diverge (n = 20)
D = 0.2493 (D⁺ = 0.2493; D⁻ = 0.2086), with the largest departure at x = 6.70. The classical Kolmogorov p = 0.141 fails to reject normality, while Lilliefors, the correct reference, rejects it clearly with p = 0.002; the classical approach makes p about 68.4 times larger. The same D value leads to entirely opposite conclusions depending on which reference distribution is used.
D statistic: 0.2493 · D⁺ (empirical curve above): 0.2493 · D⁻ (theoretical curve above): 0.2086
Exam scores that follow a normal distribution (n = 20)
With D = 0.0903, the Lilliefors p = 0.939 and normality cannot be rejected. The Lilliefors critical D (n = 20; α = 0.05) is 0.1924, so the observed D falls well below that threshold. The classical p = 0.995 points the same way, so both approaches agree here — they only diverge for D values close to the threshold.
D statistic: 0.0903 · D⁺ (empirical curve above): 0.0903 · D⁻ (theoretical curve above): 0.0684
Testing the fit to a known N(100; 15) distribution
Because the parameters come from theory, the classical KS is valid: D = 0.3806 with p = 0.004 rejects the hypothesis that the sample comes from N(100; 15.00). The largest departure is D⁻ = 0.3806 at x = 105, showing that the observations have shifted to the right of the theoretical curve. Had the same data been tested with estimated parameters, Lilliefors p = 0.956 would have left normality unrejected: the shape of the distribution is normal, the problem is its location.
D statistic: 0.3806 · D⁺ (empirical curve above): 0.0011 · D⁻ (theoretical curve above): 0.3806