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.