Title: Test for randomness : Chi square test
1Test for randomness Chi square test
We can say how probable or improbable certain
types of events are. The difference between
observed Ys and expected nps V (Y2 np2) 2
(Y3 np3) 2 (Y12 np12) 2 What is the
probability what V is this high using true dice?
2Suppose that every observation can fall into one
of k categories. We take n independent
observations. Let ps be the probability that
each observation falls into category s, and let
Ys be the number of observations that actually do
fall into category s. Weighted by the prob. of
occurrence nps
3Expanding (Ys nps) 2 Y2 2nps Ys n2 ps 2
and Y1 Y2 Yk n p1 p2 pk 1
v k 1 the number of degree of freedom is k
1.
4Chi-square distribution table says The quantity
V will be less than or equal to x with
approximate probability p, if n is large
enough. How large should n be? Rule of thumb
is nps gt 5
5Example five Chi-square test on three data of
four generators.
6B x0 0, a 3141592653, c 2718281829, m
2 35 C x0 0, a 2 7 1 , c 1, m 2 35 D
x0 47194118, a 23, c 0, m 10 8 1 F
x0 314159265, a 2 18 1, c 1, m 2
35 Conclusion, B and D are satisfactory, C is on
the borderline, F is unsatisfactory.
7Other tests
Kolmogorov-Smirnov test (available in SPSS
package) Frequency test, serial test, gap test,
Poker test (partition test), Coupons collector
test, permutation test, run test, maximum-of-t
test, collision test, serial correlation test,
tests on subsequences Spectral test
8Advise for RNG
The seed number X0 may be chosen arbitrarily. The
number m should be large. The computation (aX
c) mod m must be done exactly with no roundoff
error. If m is the power of 2, pick a so that a
mod 8 5 to ensure max period and high potency.
9The muliplier a should preferably be chosen
between .01m and .99m and is binary digits should
not have a simple, regular pattern. The value of
c is immaterial when a is a good multiplier,
except that c must be no factor in common with
m. The least significant (right-handed) digits of
X are not very random. It is generally best to
think of X as a random fraction X/m between 0 and
1.
10Some good RNG
a, m 137, 256 3141592221, 235 5 15, 2
35 17059465, 2 35 1664525, 2 32 314159269, 2 31 -
1 31167285, 2 48 6364136223846793005, 2 64