Last data update: 2014.03.03

R: Adaptive Chi-Square Test
adaptive.chi.squareR Documentation

Adaptive Chi-Square Test

Description

Performs Adaptive Chi-Square test of Ryabko et al.(2004) to evaluate the randomness of an RNG.

Usage

adaptive.chi.square(x, B, S, alpha = 0.05, prop=0.5, bit=FALSE)

Arguments

x

a vector or matrix that includes random data. See details for further information.

B

the length of words (B-bit) that the chippered file will be divided into.

S

the number of subsets where letters of an alphabet are combined, and S ≥ 2

alpha

a predetermined value of significance level with the default value of 0.05.

prop

a predetermined value of proportion of training data set.

bit

if x contains a sequence of bits, bit is set TRUE. Otherwise, a sequence of integers is entered and bit is set FALSE.

Details

It is possible to apply adaptive Chi-Square to smaller samples than that required for the regular chi-square test.

If x contains a sequence of bits, then x should be a matrix of Bxk, where k is the number of words (integers) generated by the RNG of interest. Otherwise, x is a kx1 vector of the words. Because bits will be converted to base 10 before application of the test, implementation time will be shorter with integer input.

The degrees of freedom of the resulting chi-square test is S-1. The value of S should be much less than 2^B.

Value

statistic

calculated value of the test statistic.

p.value

p-value of the test.

result.acsq

returns 0 if H0 is rejected and 1 otherwise.

Author(s)

Haydar Demirhan

Maintainer: Haydar Demirhan <haydarde@hacettepe.edu.tr>

References

Ryabko, B.Ya., Stognienko, V.S., Shokin Yu.I., A new test for randomness and its application to some cryptographic problems. Journal of Statistical Planning and Inference (2004), 123, 365–376.

Examples


RNGkind(kind = "Super-Duper")
B=16                  # Bit length is 16.
k=5000                # Generate 5000 integers.
x=0
x=round(runif(k,0,(2^B-1)))
S=2                   # Divide alphabet to two subsets.
alpha = 0.05
test=adaptive.chi.square(x, B, S, alpha, bit =FALSE)
print(test)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(CryptRndTest)
Loading required package: MissMech
Loading required package: kSamples
Loading required package: SuppDists
Loading required package: sfsmisc
Loading required package: Rmpfr
Loading required package: gmp

Attaching package: 'gmp'

The following objects are masked from 'package:sfsmisc':

    factorize, is.whole

The following objects are masked from 'package:base':

    %*%, apply, crossprod, matrix, tcrossprod

C code of R package 'Rmpfr': GMP using 64 bits per limb


Attaching package: 'Rmpfr'

The following objects are masked from 'package:stats':

    dbinom, dnorm, dpois, pnorm

The following objects are masked from 'package:base':

    cbind, pmax, pmin, rbind

Loading required package: parallel
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/CryptRndTest/adaptive.chi.square.Rd_%03d_medium.png", width=480, height=480)
> ### Name: adaptive.chi.square
> ### Title: Adaptive Chi-Square Test
> ### Aliases: adaptive.chi.square
> ### Keywords: goodness-of-fit test randomness test nonparametric
> 
> ### ** Examples
> 
> 
> RNGkind(kind = "Super-Duper")
> B=16                  # Bit length is 16.
> k=5000                # Generate 5000 integers.
> x=0
> x=round(runif(k,0,(2^B-1)))
> S=2                   # Divide alphabet to two subsets.
> alpha = 0.05
> test=adaptive.chi.square(x, B, S, alpha, bit =FALSE)
> print(test)

    Test results for Adaptive Chi-Square test
    -----------------------------------------
     Value  : 0.101
      p-Value: 0.75
     Result : Not reject H0
    -----------------------------------------> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>