gap.test(u, lower = 0, upper = 1/2, echo = TRUE)0.1/2.TRUEstatistic the value of the chi-squared statistic.
p.value the p-value of the test.
observed the observed counts.
expected the expected counts under the null hypothesis.
residuals the Pearson residuals, (observed - expected) / sqrt(expected).
u, realisation of i.i.d. uniform random
variables $U_1, \dots, U_n$.The gap test works on the 'gap' variables defined as $$G_ i = \left{ \begin{array}{cl} 1 & \textrm{if~} lower \leq U_i \leq upper\ 0 & \textrm{otherwise}\ \end{array} \right.$$ Let $p$ the probability that $G_i$ equals to one. Then we compute the length of zero gaps and denote by $n_j$ the number of zero gaps of length $j$. The chi-squared statistic is given by $$S = \sum_{j=1}^m \frac{(n_j - n p_j)^2}{n p_j},$$ where $p_j$ stands for the probability the length of zero gaps equals to $j$ ($(1-p)^2 p^j$) and $m$ the max number of lengths (at least $\left\lfloor \frac{ \log( 10^{-1} ) - 2\log(1- p)-log(n) }{ \log( p )} \right\rfloor$ ).
L'Ecuyer P. (2001), Software for uniform random number generation distinguishing the good and the bad. Proceedings of the 2001 Winter Simulation Conference. (available online)
L'Ecuyer P. (2007), Test U01: a C library for empirical testing of random number generators. ACM Trans. on Mathematical Software 33(4), 22.
freq.test, serial.test, poker.test,
order.test and coll.test ks.test for the Kolmogorov Smirnov test and acf for
the autocorrelation function.
# (1)
#
gap.test(runif(1000))
print( gap.test( runif(1000000), echo=FALSE ) )
# (2)
#
gap.test(runif(1000), 1/3, 2/3)Run the code above in your browser using DataLab