kstest for uniform distribution
Show older comments
Hi,
I have been testing the use of kstest for the detection of a discrete uniform distribution. However, I believe that I am encountering an error, or using the function incorrectly. For example, if I define a variable array
x = randi([1 4],1900,1);
where tabluate gives the following very uniform distribution
tablate(x)
Value Count Percent
1 449 23.63%
2 482 25.37%
3 482 25.37%
4 487 25.63%
and I then run the test
kstest(x, 'CDF', [x unidcdf(x,4)])
I get a result of h = 1, i.e. rejection of the hypothesis that x is discrete uniform, which is clearly not the case (at least in my eyes). Would someone with more experience with this test potentially be able to helpfully provide an explanation as to why I'm getting this result? And whether I'm doing something wrong?
Many thanks.
Accepted Answer
More Answers (1)
the cyclist
on 12 Oct 2021
0 votes
From the documentation: "The one-sample Kolmogorov-Smirnov test is only valid for continuous cumulative distribution functions." (Emphasis added.)
1 Comment
John Smith
on 13 Oct 2021
Categories
Find more on Univariate Discrete Distributions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!