Chi-Square Test
The chi-square test measures the
distribution of the random number generator
used in datagen. If the test passes,
the numbers produced by datagen
are spread evenly across the spectrum
of possible numbers. Each number generated
has an equal probability of occurrence.
Syntax
The syntax for programs with chi-square tests:
chisq size categories
realchi size categories
binchi size categories
flip size flips
dice size #dice
binom size n_trials p_success
bnmerr confidence
error_rate n_trials p_success
poisson size mu
poierr confidence error_rate mu
smpl size x_length
pwrball size
pkrhnd size
dicepkr size
bingo size
roulette size
slots coins value
Example
chisq 10000 17
realchi 10000 17
binchi 10000 17
flip 10000 17
dice 10000 5
binom 10000 17 0.6
bnmerr 95.0 0.01 17 0.6
poisson 10000 2.0
poierr 95.0 0.002 2.0
smpl 10000 17
pwrball 10000
pkrhnd 10000
dicepkr 10000
bingo 10000
roulette 10000
slots 10000 0.10
-
The first three chi-square programs run different
randomizing routines. They should all pass the
test with equal probability.
-
The coin flip program, flip, runs a
goodness of fit chi-square test to evaluate whether
the observed number of heads matches its probability.
-
The dice rolling program, dice, runs a
goodness of fit chi-square test to evaluate whether
the observed score matches its probability.
-
The binomial distribution program, binom, runs a
goodness of fit chi-square test to evaluate whether
the observed number of trials matches its probability.
-
The binomial distribution program, bnmerr
is similar to binom. Only the parameters
are different.
-
The poisson distribution program, poisson, runs a
goodness of fit chi-square test to evaluate whether
the observed number of trials matches its probability.
-
The parameter mu for the poisson
program is the population mean.
-
The poisson distribution program, poierr
is similar to poisson. Only the parameters
are different.
-
The sample mean distribution program, smpl, runs a
goodness of fit chi-square test to evaluate whether
the observed number of trials matches its probability.
-
The powerball lottery program, pwrball, runs a
goodness of fit chi-square test to evaluate whether
the lottery matched all the prizes after a large
number of tickets have been played.
-
The 52 card poker hand program, pkrhnd, runs a
goodness of fit chi-square test to evaluate whether
the dealt hands match all patterns after a large number
of deals.
-
The dice poker program, dicepkr, runs a
goodness of fit chi-square test to evaluate whether
the rolled dice match all patterns after a large number
of rolls.
-
The bingo program, bingo, runs a
goodness of fit chi-square test to evaluate how many
draws it takes to score a bingo and cover a bingo
card with 12 bingos.
-
The roulette program, roulette, runs a
goodness of fit chi-square test to evaluate winning
squares.
-
The slot machine program, slots, runs a
goodness of fit chi-square test to evaluate winning
combinations.
-
Read the
Powerball
write-up for documentation about its chi-square
test. It only uses 9 degrees of freedom. The first
three chi-square tests use 16 degrees of freedom.
-
The chi-square should consistently be between within
the chi-square range for the given degrees of freedom,
95 percent of the time. If the test does not succeed
within this range, rerun the test. If the test consistently
fails, then the random number generator has failed.
-
If the chi-square is less than the low end of the range,
then the random number generator is performing too well.
The results are not random enough. You should look into
your test program to make sure that you are randomizing
the data properly.
-
If the chi-square is beyond the high end of the range,
then the random number generator is too chaotic. The
chances are that you have a rounding error, or an incorrect
assumption about the data. The standard deviation may
also be unusually large, in this case.
-
The degrees of freedom is one less than the number of
categories. In this example, the number of categories
is 17. The degrees of freedom is 16.
-
The desired margin is twice the square root
of categories.
-
The test program uses a formula from
Knuth
to calculate the predicted range.
-
For example, if you want to test the random number
generator for the letters of the alphabet, calculate
the chi-square with 25 degrees of freedom.
Table of Contents
Job and Record Level Definitions
Field Level Definitions
Datagen Syntax
Supporting Routines
Powerball Test
FAQ
Copying