Skip to content

Lilliefors test

The Lilliefors test checks a fitted distribution using a KS distance calibrated for estimated parameters. Work through a normality example and see why fitting, dependence and calibration matter.

The Lilliefors test is a goodness-of-fit test that uses the largest gap between an empirical CDF and a fitted distribution, with calibration that accounts for estimating parameters from the tested sample. Its best-known version asks whether independent observations could come from a normal distribution with an unknown mean and variance. For a quant checking return-model assumptions, the crucial point is that fitting the mean and volatility changes the reference distribution of the test statistic.

The curve has already seen the data

An ordinary one-sample Kolmogorov–Smirnov test compares observations with a continuous distribution specified in advance. A normality check usually estimates the normal curve from those very observations. The fitted curve adapts to the sample, so the ordinary fixed-CDF KS calibration no longer applies. R's official ks.test documentation explicitly excludes estimating the reference parameters from the tested data. R documentation
Lilliefors keeps the maximum-gap idea and changes its calibration. This is a composite null: some mean and some positive variance within the normal family may have generated the data. Rejecting it challenges that family; failing to reject does not establish normality. CRAN nortest manual

Compute the distance, then calibrate it

For sorted observations x(1)≤⋯≤x(n)x_{(1)}\le\cdots\le x_{(n)}, define the fitted normal CDF by

F^(x)=Φ(x−xˉs),s2=1n−1∑j=1n(xj−xˉ)2.\widehat F(x)=\Phi\left(\frac{x-\bar x}{s}\right), \qquad s^2=\frac{1}{n-1}\sum_{j=1}^{n}(x_j-\bar x)^2.
Here Φ\Phi is the standard normal CDF and ss uses the sample variance divisor n−1n-1. Both sides of each empirical-CDF jump matter:
D+=max⁡1≤i≤n{in−F^(x(i))},D−=max⁡1≤i≤n{F^(x(i))−i−1n},D=max⁡(D+,D−).\begin{aligned} D^+&=\max_{1\le i\le n}\left\{\frac{i}{n}-\widehat F(x_{(i)})\right\},\\ D^-&=\max_{1\le i\le n}\left\{\widehat F(x_{(i)})-\frac{i-1}{n}\right\},\\ D&=\max(D^+,D^-). \end{aligned}
This article uses the unscaled distance DD, without a n\sqrt n multiplier. The formulas follow the normality version in the nortest manual; statsmodels likewise standardises with divisor n−1n-1. A fitting rule, statistic convention and critical-value calibration must match. Replacing ss with a divisor-nn estimate without checking the calibration changes the procedure. Statsmodels implementation
Take five fictional observations in arbitrary units, sorted as −1,0,0.5,1,3-1,0,0.5,1,3. They give xˉ=0.7\bar x=0.7 and s=2.2≈1.48324s=\sqrt{2.2}\approx1.48324.
iix(i)x_{(i)}Fitted normal CDFi/n−F^i/n-\widehat FF^−(i−1)/n\widehat F-(i-1)/n
1−10.125870.074130.12587
200.318480.081520.11848
30.50.446370.153630.04637
410.580140.21986−0.01986
530.939510.060490.13951

Thus D+≈0.21985675D^+\approx0.21985675, D−≈0.13950837D^-\approx0.13950837 and D≈0.21985675D\approx0.21985675. The largest gap occurs at x=1x=1, where the empirical CDF has jumped to 4/5=0.84/5=0.8.

Fictional observations minus 1, 0, 0.5, 1 and 3 have fitted mean 0.7 and sample standard deviation 1.48324. The largest gap is 0.21986 at x equal to 1, between fitted normal CDF 0.58014 and empirical CDF 0.8.
Fictional observations minus 1, 0, 0.5, 1 and 3 have fitted mean 0.7 and sample standard deviation 1.48324. The largest gap is 0.21986 at x equal to 1, between fitted normal CDF 0.58014 and empirical CDF 0.8.
Original fictional example. The highlighted vertical distance is the unscaled statistic D; it is not a p-value or a rejection threshold.

The table establishes the statistic only. It supplies neither a significance result nor persuasive evidence of normality from five observations.

What a usable result needs

A valid p-value needs a null distribution calibrated for this fitting procedure and sample size. Statsmodels provides separate normal and exponential versions, with simulation-based tables. The exponential version estimates its mean with the origin fixed at zero; it is not a normality test, and its calibration is not interchangeable with the normal version. Statsmodels API, implementation
For a simulation calibration, each replicate must repeat the fitting step before computing its distance. Holding the original fitted parameters fixed in every replicate recreates the wrong testing problem. A parametric bootstrap can implement this fit-and-test workflow, subject to the model and estimator used. SciPy goodness-of-fit documentation
For financial data, check the sampling story too. Standard iid continuous-sample calibration does not automatically cover serial dependence, volatility clustering, or residuals created by fitting a time-series model. Such residuals can inherit estimation constraints and dependence; any simulation needs to reproduce the relevant model-fitting pipeline. R also warns that ties and rounding affect one-sample KS calculations. A fitted-normal p-value cannot repair those sampling mismatches. R documentation
To understand the curve comparison, read The Empirical CDF, Glivenko–Cantelli, and QQ-Plots. Its public preview introduces the lesson; the full teaching requires membership. A QQ-plot helps locate a shape mismatch that a single maximum distance compresses into one number.

Sources

Last updated
  • normality
  • goodness of fit
  • estimated parameters
  • kolmogorov smirnov
  • model diagnostics
← Back to the glossaryBack to top ↑