# kstest for uniform distribution

44 ビュー (過去 30 日間)
John Smith 2021 年 10 月 12 日
コメント済み: John Smith 2021 年 10 月 14 日
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.

サインインしてコメントする。

### 採用された回答

Jeff Miller 2021 年 10 月 12 日
you can test for the fit of a discrete distribution, including uniform, with chi2gof. One of the examples (about 1/3 of the way down the page) shows how to test for a Poisson distribution. With the uniform discrete, your expected counts expCounts are just the total number of observations divided by the number of possible discrete values.
##### 3 件のコメント表示非表示 2 件の古いコメント
John Smith 2021 年 10 月 14 日
Thank you, I appreciate the correction, and have edited the reply to avoid anyone reading this making the same mistake.

サインインしてコメントする。

### その他の回答 (1 件)

the cyclist 2021 年 10 月 12 日
From the documentation: "The one-sample Kolmogorov-Smirnov test is only valid for continuous cumulative distribution functions." (Emphasis added.)
##### 1 件のコメント表示非表示 なし
John Smith 2021 年 10 月 13 日
Thank you, I missed that part on the first read. I suspect Jeff Miller's answer is the way to go then, as chi square will allow for a test of discrete distributions.

サインインしてコメントする。

R2020b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by