Kolmogorov-Smirnov Test Calculator

Test distribution fit or compare samples.

Examples:

Enter sample data to perform the Kolmogorov-Smirnov test

What Is the Kolmogorov-Smirnov Test?

The Kolmogorov-Smirnov (K-S) test is a nonparametric test that compares distributions. It can test whether a sample comes from a specific theoretical distribution (one-sample test) or whether two samples come from the same distribution (two-sample test). Unlike tests that compare specific parameters like means, the K-S test is sensitive to any difference in distribution shape, location, or spread.

The test is named after Russian mathematicians Andrey Kolmogorov and Nikolai Smirnov, who developed it in the 1930s.

The K-S Statistic

The test statistic D measures the maximum absolute difference between cumulative distribution functions (CDFs):

D=sup⁑x∣Fn(x)βˆ’F(x)∣D = \sup_x |F_n(x) - F(x)|

Where:

  • Fn(x)F_n(x) is the empirical CDF of the sample
  • F(x)F(x) is the theoretical CDF (one-sample) or the other sample's empirical CDF (two-sample)
  • sup⁑\sup denotes the supremum (maximum)

The empirical CDF is a step function that increases by 1/n1/n at each data point.

One-Sample Test

The one-sample K-S test compares your data to a theoretical distribution. Common applications include:

Testing for Normality

Before using parametric tests that assume normality, you can use the K-S test to check this assumption. However, the Shapiro-Wilk Test is generally more powerful for normality testing.

Goodness of Fit

Any fully specified continuous distribution can be tested: normal, exponential, uniform, etc. The key requirement is that all parameters must be specified in advance, not estimated from the data.

Important: If you estimate parameters (like mean and standard deviation) from your sample and then test against that distribution, the standard K-S critical values are too conservative. Use the Lilliefors test instead for testing normality with estimated parameters.

Two-Sample Test

The two-sample K-S test compares two independent samples to determine if they come from the same distribution. This is useful when:

  • You want to compare groups without assuming a specific distribution
  • Sample sizes are small
  • Data may be non-normal

The two-sample test statistic is:

Dn,m=sup⁑x∣Fn(x)βˆ’Gm(x)∣D_{n,m} = \sup_x |F_n(x) - G_m(x)|

Where FnF_n and GmG_m are the empirical CDFs of the two samples.

Advantages

Distribution-Free

The K-S test makes no assumptions about the underlying distribution (for the two-sample case). This makes it widely applicable.

Sensitive to Multiple Aspects

Unlike t-tests that only compare means, the K-S test detects differences in:

  • Location (central tendency)
  • Scale (spread)
  • Shape (skewness, kurtosis)

Exact Distribution Known

The null distribution of the K-S statistic is known exactly, enabling precise p-value calculation.

Limitations

Continuous Data Only

The K-S test is designed for continuous distributions. For discrete data, the test becomes conservative (less powerful).

Sensitivity to Tails

The K-S test is most sensitive to differences near the center of the distribution and less sensitive to differences in the tails. The Anderson-Darling test addresses this by giving more weight to tail differences.

Parameter Estimation Problem

Using estimated parameters invalidates the standard critical values, as mentioned above.

Practical Applications

Quality Control

Comparing product measurements against specification distributions to verify manufacturing processes.

Finance

Testing whether stock returns follow assumed distributions like normal or log-normal.

Environmental Science

Comparing pollution measurements across sites or time periods.

A/B Testing

Comparing entire response distributions, not just means, between treatment and control groups.

Related Tests

Summary

The Kolmogorov-Smirnov test is a versatile nonparametric method for comparing distributions. Its ability to detect any distributional difference makes it valuable for exploratory analysis and assumption checking. While not the most powerful test for specific alternatives (like differences in means), its generality and exact null distribution make it a fundamental tool in statistical analysis.