[R] testing randomness of random number generators with student t-test?

Phil Spector spector at stat.berkeley.edu
Thu Feb 3 01:18:45 CET 2011


Carl -
    Under the null hypothesis, the distribution of p-values for
any statistical test should be uniform over the range from 0 to
1.   So while the individual p-values you see in an experiment
like the one you carried out aren't really meaningful, their
ensemble behaviour is.  So if you did something like

> pvals = replicate(10000,
      {randa<-runif(1000);randb<-runif(1000);t.test(randa,randb)$p.value})
> ks.test(pvals,'punif')

you'd expect the ks.test to support the hypothesis that the pvals 
follow a U(0,1) distribution.  As others have pointed out, there are
many other issues regarding random number generation, but I think what
I've described addresses the issue of the t.test probabilities.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu

On Wed, 2 Feb 2011, Carl Witthoft wrote:

> Hi, subject more or less says it all.
>
> I freely admit to not having bothered to find some of the online papers about 
> method of testing the quality of random number generators -- but in an idle 
> moment I wondered what to expect from something like the following:
>
>
> randa<-runif(1000)
> randb<-runif(1000)
> t.test(randa,randb)$p.value
> var.test(randa,randb)$p.value
>
> [repeat ad nauseum]
>
>
> Is the range of p-values I get in any way related tothe "quality" of the 
> random number generator?
>
> thanks
> Carl
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list