8
$\begingroup$

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 )
$\endgroup$
4
  • 3
    $\begingroup$ dober dan! do you know if the official law is designed for roulette or for some other gambling devices? (slot machine, poker, etc) The third requirement sounds like autocorrelation, or it could be tested by Wald-Wolfowitz test, etc. $\endgroup$
    – shabbychef
    Commented May 24, 2011 at 18:36
  • $\begingroup$ It is designed for general gambling device. Link for law (in slovene language) is at unpis.gov.si/fileadmin/unpis.gov.si/pageuploads/zakonodaja/… (paragraph 6) $\endgroup$
    – ralu
    Commented May 24, 2011 at 18:41
  • $\begingroup$ My mother-in-law is Slovene, but I do not think she could translate this very well. Perhaps the test to which they refer is the autocorrelation of returns for a gambler who always plays number 17, for example. (and repeat for each number?) Maybe poking around in the en.wikipedia.org/wiki/Diehard_tests would also be instructive. $\endgroup$
    – shabbychef
    Commented Jun 2, 2011 at 17:40
  • $\begingroup$ Perhaps what they are asking for is a time lagged regression, that is - does the previous number predict the subsequent number? $\endgroup$ Commented Jun 18, 2011 at 15:03

1 Answer 1

2
$\begingroup$

For a fair game successive plays should be independent. It sounds like they are asking you to perform a test that consecutive results are uncorrelated. You could do this by pairing the data let $R_1, R_2,...,R_{2n}$ be the first $2n$ results. Then you can form $n$ distnct pairs $(R_1,R_2)$, $(R3, R4),...,(R_{2n-1}, R_{2n})$. Calculate the pearson correlation coefficient is different from zero (if the data is continuous or even a set of integers). If the data are $0/1$ for lose/win you can test for independence in the $2\times2$ table obtained by using the counts for $(0,0), (0,1),(1,0)$ and $(1,1)$. In this case of $0/1$ the runs test of Wald and Wofowitz suggested above could also be used. The way it is described in the rule it sounds like they want you to construct a confidence interval for the correlation with halfwidth equal to $3\sigma$. You would pass if $0$ is contained in the interval. These tests seem to be a little too easy to pass though.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.