just wanted to ask if it's possible to check whether a given sample of data is drawn from a random distribution? If so, can I use some statistical test like the Anderson-Darling test or Chi-squared test to know this? Sorry if the question is easy but I just wanted to be certain about this before moving on with my lab assignment.
-
3$\begingroup$ If you're asking about any random distribution rather than a specified form, the answer is no. The term "random" itself is philosophically complicated and there are people who think that nothing is really random in the world. This cannot be disproved as they could always say, we just don't have the detailed knowledge to know why the data set has turned out like this. $\endgroup$– Christian HennigCommented Oct 17, 2021 at 13:48
-
1$\begingroup$ Of course if you mean by "random" something specific like i.i.d. uniform, it's a different story, see answer by @Aksakal. $\endgroup$– Christian HennigCommented Oct 17, 2021 at 13:50
-
$\begingroup$ I don't know if this helps but for context, I'm trying to test if a particular random number generator is truly "random" in nature. I'm trying to look up on ways on how to do this other than the DIEHARD test. $\endgroup$– MathNewbCommented Oct 17, 2021 at 14:44
-
$\begingroup$ The 'Diehard' tests exist for a reason. A proposed pseudorandom generator needs extensive vetting. Maybe starting with using it to 'roll a fair die' and checking results with chi-squared GOF test. Then maybe plot several thousand $(r_i, r_{i+1})$ pairs to see if dots in unit square have unwarranted patterns. Etc. Any failure is enough to show the generator shouldn't be used for general purposes. // For routine simulation, it's best to use a thoroughly vetted generator (e.g., Mersenne twister, default in R). In a large simulation maybe include a trivial related simulation with known answ. $\endgroup$– BruceETCommented Oct 17, 2021 at 15:40
-
$\begingroup$ Maybe see Wikipedia for discussion of the flawed pseudorandom number generator RANDU, which was used on some early IBM computers for several years before discovery that it has bad behavior even in three dimensions. $\endgroup$– BruceETCommented Oct 17, 2021 at 15:54
3 Answers
NIST maintains the test suite for random number generators, see https://csrc.nist.gov/projects/random-bit-generation/documentation-and-software That’s where I’d start. You may adapt what’s suitable for your case
-
$\begingroup$ Thank you, I will try researching more about this! $\endgroup$– MathNewbCommented Oct 17, 2021 at 14:41
RANDU vs. runif
in R (using Mersenne Twister). One preliminary test in vetting a pseudorandom number generator might be to look at the distribution of points in the unit cube.
# RANDU (multiplicative congruential generator)
a = 65539; d = 2^31; s = 11
m = 20000; r = numeric(m); r[1] = s
for (i in 1:(m-1)) {r[i+1] = (a*r[i]) %% d}
u = (r-.5)/(d-1)
u1 = u[1:(m-2)]; u2 = u[2:(m-1)]; u3=u[3:m]
par(mfrow=c(1,2))
plot(u1,u2, pch=20, xlim=c(0,.1), ylim=c(0,.1))
plot(u1[u3<.01], u2[u3<.01], pch=20, xlim=0:1, ylim=0:1)
par(mfrow=c(1,1))
In the figure below, the left panel shows "random" points in the square with vertices $(0,0), (0.1,0.1),$ which look OK. By contrast, points near one face of the unit cube indicate that points in the cube lie on only a few planes.
# 'runif' in R using Mersenne Twister
set.seed(2021); m = 20000; u = runif(m)
u1 = u[1:(m-2)]; u2 = u[2:(m-1)]; u3=u[3:m]
par(mfrow=c(1,2))
plot(u1,u2, pch=20, xlim=c(0,.1), ylim=c(0,.1))
plot(u1[u3<.01], u2[u3<.01], pch=20, xlim=0:1, ylim=0:1)
par(mfrow=c(1,1))
Below, plotting regions are the same as above, and both panels seem to have points at random.
-
1$\begingroup$ This approach is much more visual and easier to do, I think. Thank you for showing me this. I'll try doing it as well on Julia. $\endgroup$– MathNewbCommented Oct 17, 2021 at 23:33
Chi square test will allow you to determine things such as, after a series of die rolls, is the die “fair” ie each face has equal probability of being landed on. Your question is unclear, but I would guess this is what you want.
-
$\begingroup$ Sorry for not including some context for my inquiry. For context, I want to test if a particular random number generator is truly "random" in nature. $\endgroup$– MathNewbCommented Oct 17, 2021 at 14:46
-
1$\begingroup$ Chi square test will allow you to determine things such as, after a series of die rolls, is the die “unfair”. Contingency table tests provide evidence, or fail to provide evidence, for $\text{H}_{\text{A}}$, not for $\text{H}_{0}$. $\endgroup$– AlexisCommented Oct 17, 2021 at 17:20
-
$\begingroup$ Other than the Chi square test, can I use the Mann-Kendall test instead since it says on the internet that it can tell us if our data has any trends? $\endgroup$– MathNewbCommented Oct 17, 2021 at 18:00