Solved – use Kolmogorov Smirnov test to check if the data are uniformly distributed

distributionshypothesis testingkolmogorov-smirnov testuniform distribution

I'd like to check if distribution of my data is significantly different from a uniform distribution. I know that the K-S test is used for checking the normality of data, but I wonder if it can be applied also to check the uniformity of data as well?

Best Answer

The Kolmogorov-Smirnov test can be used to test with a null of any fully specified continuous distribution.

Since the statistic is only a function of the largest difference in cdf, if you use a probability integral transform on the data, that won't change the test statistic but turns it into a test against uniformity.

enter image description here

The top plot shows the situation in a test for normality, the bottom plot shows a test for standard uniform on transformed data. The distance, (D, marked in blue) is the same given any monotonic transformation of the x-axis.

So every KS test will be exactly the same as if you were doing a test of uniformity -- i.e. it's distribution-free -- as long as the distribution is continuous and fully specified (no parameters to estimate), it doesn't matter what the distribution is, the test works exactly the same.

So uniform, normal, gamma, beta, Cauchy, logistic, Student t, or whatever else you like.

(If the distribution is not fully specified - i.e. if you don't know one or more parameters, then it's not actually a Kolmogorov-Smirnov test, but a Lilliefors test*, and no longer distribution free, though in the case of uniformity there's a neat trick which could be used to take it back to a fully specified distribution.)

* Lilliefors himself did the normal and exponential cases

--

In respect of your title, there's nothing that will tell you your data are from a uniformly distributed population -- but a goodness of fit test may tell you that they aren't.