Problem is that government wants to close electronic roulette and they claim that roulette failed at statistical test.
Sorry for my language but this is translated from Slovenian law as good as possible Official (by law) requirements are:
- frequency of each event should not differ from expected frequency by more than 3 sigma
- chi square test of normal distribution has to be within risk level of 0.025
- test of consecutive correlation has to pass 3 sigma test and chi squared test
I have tested first 2 requirements and they pass tests, but I have problems whith understanding 3rd requirement. (keep in mind that this is translated and "consecutive correlation" can be something else)
How should I test 3rd requirement?
Data if somebody is interested:
http://pastebin.com/ffbSKpr1
EDIT: chi squared fails 2% of the time (what I expect that is expected due to fact that alpha is 0.025) and sigma3 test fails 5% where i expect 9% failure for 3sigma (it looks like that frequencies are not distributed according to normal distribution even for random numbers)
I might not understand this law correctly, but it is almost 0% probability to pass 3sigma test for all autocorrelation vectors, since it is 9% probability to fail in single run and 2.5 for chi squared test.
Python code:
from math import sqrt
from itertools import *
import random
#uncoment for python 2.x
#zip = izip
#range = xrange
#with open("rng.txt","r") as wr:
# n = [int(i) for i in wr]
n = [random.randint(0,36) for i in range(44000)]
def get_freq(n):
r=[0 for i in range(37)]
for i in n:
r[i] += 1
return r
def trisigmatest(freq):
Ef = 1.0*sum(freq)/37
sigma = sqrt(sum(i**2 for i in freq)/37-Ef**2)
return all((abs(i - Ef )< sigma*3) for i in freq)
def chiquaretest(freq):
Ef = 1.0*sum(freq)/37
chi2 = sum((i-Ef)**2 / Ef for i in freq)
# values are from http://itl.nist.gov/div898/handbook/eda/section3/eda3674.htm
# (EDIT) I recaluclated these valuse from inverse cdf chi2
# distribution for interval (0.025/2,1-0.025/2) (alpha = 0.025)
return 20.4441 < chi2 < 58.8954
#whitout autocorelation
gf = get_freq(n)
if not trisigmatest(gf):
print("failed")
raise
if not chiquaretest(gf):
print("failed")
raise
actests = 1000
trifailed = 0;
chifailed = 0;
for i in range(1,actests + 1):
f=((b-a+37) % 37 for (a,b) in zip(n,n[i:]))
gf = get_freq(f)
if not trisigmatest(gf):
trifailed += 1;
if not chiquaretest(gf):
chifailed += 1;
print("trisigmatest failed ", 1.0 * trifailed / actests )
print("chiquaretest failed ", 1.0 * chifailed / actests )