One-Sample Kolmogorov-Smirnov Test
Test whether a sample comes from a specified continuous distribution, such as the normal. The one-sample KS test measures the largest gap between your data's cumulative distribution and the reference, giving the D-statistic and p-value.
Run One-Sample KS Test →What is the One-Sample KS Test?
The one-sample Kolmogorov-Smirnov (KS) test is a non-parametric test that compares the distribution of a sample against a fully specified continuous reference distribution. It is commonly used to check whether data follows a particular distribution, such as the normal, exponential or uniform.
The test works on cumulative distribution functions. It computes the empirical cumulative distribution of the sample and the theoretical cumulative distribution of the reference, then finds the maximum vertical distance between them. This maximum gap is the D-statistic; the larger it is, the worse the fit.
A key requirement is that the reference distribution be fully specified in advance, including its parameters. If the parameters are estimated from the same data, as when testing for normality using the sample mean and standard deviation, the standard KS p-values are too conservative, and a dedicated normality test such as Shapiro-Wilk or the Lilliefors correction is more appropriate.
In plain terms: You want to know if your data follows a specific distribution, like the normal. The KS test draws your data's cumulative curve and the theoretical curve, then finds the widest gap between them. A big gap means your data doesn't match that distribution.
Key Points
CDF Comparison
Compares the sample's empirical cumulative distribution against a theoretical one, using the largest vertical gap (the D-statistic).
Fully Specified Reference
The reference distribution and its parameters must be specified in advance, not estimated from the same data.
Continuous Data
The KS test is designed for continuous distributions; for discrete data it is conservative.
Key Formulas
Interpreting the Result
The null hypothesis is that the sample comes from the specified distribution. A small p-value means the maximum gap is larger than chance allows, so the data does not fit the reference distribution.
If the parameters of the reference were estimated from the data (a frequent case when testing normality), the standard KS test is overly conservative and loses power. In that situation, a purpose-built normality test such as Shapiro-Wilk is the better choice.
Assumptions & Validation
Continuous Distribution
The reference distribution is continuous.
If violated: For discrete data the test is conservative; use tailored methods.
Fully Specified Reference
The distribution and its parameters are specified independently of the sample.
If violated: Use Shapiro-Wilk or Lilliefors when parameters are estimated from the data.
Independent Sample
Observations are an independent random sample.
If violated: Address dependence in the data.
⚠️ Check assumptions first
The one-sample KS test assumes the reference distribution is fully specified before looking at the data. A very common misuse is testing for normality using the sample's own mean and standard deviation as the reference parameters, which makes the standard KS p-values too conservative and the test underpowered. For normality specifically, use the Shapiro-Wilk test or the Lilliefors correction instead.
When NOT to Use One-Sample Kolmogorov-Smirnov Test
Estimated Parameters
When testing normality with parameters from the data, use Shapiro-Wilk or the Lilliefors-corrected KS test.
Two Samples
To compare two samples' distributions, use the two-sample KS test.
Categorical Data
For category counts against expected proportions, use the chi-square goodness-of-fit test.
Industry Applications
Distribution Checking
Test whether data plausibly follows a specified continuous distribution before applying methods that assume it.
Simulation Validation
Check whether generated or sampled data matches a target distribution.
Model Input Verification
Confirm that an input variable follows the distribution a model assumes.
Quality Data Screening
Assess whether measurement data conforms to an expected distributional shape.
Frequently Asked Questions
What does the one-sample KS test check?
It checks whether a sample of continuous data comes from a specified reference distribution, such as the normal or exponential. The test computes the largest vertical gap between the sample's empirical cumulative distribution function and the theoretical one, called the D-statistic. A large gap, and a correspondingly small p-value, indicates that the data does not fit the specified distribution.
What is the D-statistic?
The D-statistic is the maximum absolute difference between the empirical cumulative distribution function of the sample and the cumulative distribution function of the reference distribution. It captures the single point where the two curves diverge most. A larger D indicates a poorer fit between the data and the reference distribution, and it is the basis for the test's p-value.
Why shouldn't I use the KS test for normality with estimated parameters?
The standard one-sample KS test assumes the reference distribution's parameters are known in advance. When you estimate the mean and standard deviation from the same data to test for normality, the test becomes overly conservative and loses power, meaning it too often fails to detect non-normality. For normality testing, the Shapiro-Wilk test or the Lilliefors-corrected KS test is more appropriate.
How does the KS test differ from the chi-square goodness-of-fit test?
The KS test works on continuous data and compares cumulative distribution functions using the maximum gap, without binning. The chi-square goodness-of-fit test works on categorical or binned data, comparing observed and expected counts within categories. For continuous distributions the KS test avoids the arbitrary choice of bins that the chi-square test requires, making it often preferable for continuous data.
Is the KS test suitable for discrete data?
The Kolmogorov-Smirnov test is designed for continuous distributions. Applied to discrete data, it becomes conservative, meaning it is less likely to reject the null hypothesis than it should be, which reduces its power. For discrete distributions, tailored approaches or the chi-square goodness-of-fit test on the categories are generally more appropriate.
What does a significant KS result mean?
A significant result, shown by a small p-value, means the maximum distance between the sample and reference cumulative distributions is larger than would occur by chance if the data truly came from the reference distribution. You therefore reject the hypothesis that the sample follows that distribution. It does not, by itself, tell you which alternative distribution the data follows.
Test Whether Data Fits a Distribution
Run a one-sample KS test with the D-statistic and p-value. Free during Beta.
Run One-Sample KS Test →