Chisquare test and K-S test for a given set of Random Numbers in range [0,num_max] in R? [closed]

StackOverflow https://stackoverflow.com/questions/22425667

  •  15-06-2023
  •  | 
  •  

I have made a random number generator and generated N numbers in range 0 to 10007, I want to test how good is this generator in R.

有帮助吗?

解决方案

You can use ks.test to test if your sample matches the specified distribution. For instance, we can compare the output of runif to the U(0, 1) distribution:

set.seed(144)
x <- runif(1000, 0, 1)
ks.test(x, "punif", 0, 1)
#   One-sample Kolmogorov-Smirnov test
# 
# data:  x
# D = 0.0326, p-value = 0.2374
# alternative hypothesis: two-sided

The D value states that the empirical cdf of your samples differs from the cdf of the U(0, 1) distribution by a maximum of 0.0326. The p-value says that there's a 0.2374 probability that the empirical cdf of 1000 random samples from a random variable R will differ from the cdf of R by D or more.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top