Skip to content

ADescribe · Guide test 116

One sample Kolmogorov–Smirnov test

Compares an empirical distribution with a fully specified continuous distribution; fitted parameters require different calibration.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Fit a distribution (goodness of fit), choose Parameters = Specified in advance.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · One-sample Kolmogorov–Smirnov test

40
0.30
1.00
0.050

Your data

Drag a point or use ↑/↓ to change it
D = 0.227F₀ = N(0, 1)

If H₀ were true

D = 0.23
  1. The reference: how D varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .027).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

D=sup⁡x∣Fn(x)−F0(x)∣D = \sup_x \lvert F_n(x) - F_0(x) \rvert

With your numbers

D=0.23,n=40,n D=1.44D = 0.23,\qquad n = 40,\qquad \sqrt{n}\,D = 1.44
FnF_n
the sample's empirical CDF
F0F_0
the hypothesized CDF, with parameters fixed in advance
DD
the largest vertical gap between them

The verdict

D = 0.227, p = .027

p ≤ α = .050: reject H₀

Effect size: largest ECDF gap D = 0.227

Parameters must be specified, not estimated from the same data — estimating them makes this p-value far too large (use Lilliefors for normality). R uses D's exact distribution below n = 100 without ties.

Statistic
0.227
p-value
0.0267
One-sample Kolmogorov–Smirnov test on Sample: n = 40: D = 0.227, p = .027. The p-value is below α = .050, so the data are hard to reconcile with H0.

One-sample Kolmogorov–Smirnov test on Sample: n = 40: D = 0.227, p = .027. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: the population CDF is the fully specified continuous F0.

Assumptions

Independent identically distributed observations; no parameters estimated from the tested sample for the standard distribution-free reference.

Formula

D=max⁡i{in−F0(x(i)), F0(x(i))−i−1n}D=\max_i\left\{\frac in-F_0(x_{(i)}),\ F_0(x_{(i)})-\frac{i-1}n\right\}

Parameters and notation

n observations; F0 includes all known parameters. One-sided D+ and D− use one discrepancy direction.

Structure of the method

Sort observations, evaluate a completely specified continuous null CDF, and examine empirical jumps immediately before and after each order statistic. The maximum one- or two-sided deviation is calibrated using the corresponding finite-sample or asymptotic KS distribution.

Estimated and nuisance parameters

No distributional parameter may be estimated from the tested observations for the ordinary distribution-free reference. Any CDF location, scale or shape must be externally fixed or explicitly handled by another calibrated procedure.

Settings and design choices

Prespecify CDF, parameter values, tail direction and exact/asymptotic method. Directional CDF inequalities should be translated carefully into statements about larger observations. There is no bin width or smoothing parameter.

Fitting and adaptation

Evaluate the fixed CDF directly for new data. If fitting becomes necessary, replace the simple-null reference with a justified composite-null method or parametric bootstrap that refits each replicate. Simulation must include measurement rounding if relevant. This changes inferential calibration rather than fine-tuning a statistical test to obtain a desired p-value.

Sensitivity and robustness

Ties and discrete outcomes destroy the usual continuous distribution-free law. KS emphasizes the largest vertical difference and can miss diffuse or extreme-tail departures. Dependent data and fitted regression residuals require simulations preserving their dependence and model-fitting steps.

How to use and calibrate

Use the exact finite sample KS distribution or a justified asymptotic reference.

Example application

Check a fully specified continuous calibration distribution.

Interpretation and pitfalls

Watch out

Fitted parameters, ties and discrete null distributions require adjusted or simulated calibration.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
  • Rewritten in the review: Python code.
  • Not in the correction log: The Python example was rewritten in an equivalent form with the same output; not in the correction log.

Python and R

The null N(0,1) is fully specified; substituting sample mean and standard deviation invalidates ordinary KS calibration.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x=rng.normal(size=60)
print(stats.kstest(x,stats.norm(0,1).cdf))
Output
KstestResult(statistic=np.float64(0.1212679063906185), pvalue=np.float64(0.3148852599980074), statistic_location=np.float64(-0.8855331545554961), statistic_sign=np.int8(-1))
R

Validated — Executed successfully in the validation environment · needs Base/standard library

set.seed(2026)
x <- rnorm(60)
print(ks.test(x,"pnorm",mean=0,sd=1))
Output
	Exact one-sample Kolmogorov-Smirnov test

data:  x
D = 0.095374, p-value = 0.6119
alternative hypothesis: two-sided

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 116, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT116.