## ## RNG tests using DKW inequality for rate of convergence ## ## P(sup F_n-F >t)<2exp(-2nt^2) ## ## The 2 in front of exp() was derived by Massart. It is the best possible ## constant valid uniformly in t,n,F. For large nt^2 this agrees with the ## large-sample approximation to the Kolmogorov-Smirnov statistic. ## superror<-function(rfoo,pfoo,sample.size,...){ x<-rfoo(sample.size,...) tx<-table(x) xi<-as.numeric(names(tx)) f<-pfoo(xi,...) fhat<-cumsum(tx)/sample.size max(abs(fhat-f)) } pdkwbound<-function(n,t) 2*exp(-2*n*t*t) qdkwbound<-function(n,p) sqrt(log(p/2)/(-2*n)) dkwtest<-function(stub="norm",sample.size=10000,...,pthreshold=0.001,print.result=TRUE,print.detail=FALSE,stop.on.failure=TRUE){ rfoo<-eval(as.name(paste("r",stub,sep=""))) pfoo<-eval(as.name(paste("p",stub,sep=""))) s<-superror(rfoo,pfoo,sample.size,...) if (print.result | print.detail){ printargs<-substitute(list(...)) printargs[[1]]<-as.name(stub) cat(deparse(printargs)) if (print.detail) cat("\nsupremum error = ",signif(s,2)," with p-value=",min(1,round(pdkwbound(sample.size,s),4)),"\n") } rval<-(s