R version 4.5.0 RC (2025-04-04 r88113 ucrt) -- "How About a Twenty-Six" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. > ############################################################################# > ## ## > ## Tests for wrapper functions for special distributions ## > ## ## > ############################################################################# > ## ## > ## Discrete distributions ## > ## ## > ############################################################################# > ## ## > ## Remark: You must use named arguments when calling the test routines! ## > ## ## > ############################################################################# > > ## --- Load test routines and test parameters ------------------------------- > > source("test_routines.R") > > ## --- Chi^2 goodness-of-fit test ------------------------------------------- > > ## Binomial distribution - (replacement for rbinom) ------------------------- > for (i in 1:n.rep.domains) { + d <- sort(rbinom(2,size=200,prob=0.29)) + d[2] <- d[2]+1 ## protect agains domains of length 1 + unur.test.discr("binom", size=200, prob=0.3, domain=d) + } binom(200,0.3) domain=(61,68): chisq test PASSed with p-value=0.163705 binom(200,0.3) domain=(62,64): chisq test PASSed with p-value=0.107004 > for (i in 1:n.rep.params) { + s <- as.integer(runif(1,min=10,max=1000)) + p <- runif(1,min=0.01,max=0.99) + unur.test.discr("binom", size=s, prob=p, domain=c(0,s)) + } binom(972,0.447047312469222) domain=(0,972): chisq test PASSed with p-value=0.492252 binom(782,0.379500992698595) domain=(0,782): chisq test PASSed with p-value=0.0956939 binom(625,0.161496477220207) domain=(0,625): chisq test PASSed with p-value=0.323916 binom(579,0.380390802510083) domain=(0,579): chisq test PASSed with p-value=0.684619 binom(102,0.0637112101120874) domain=(0,102): chisq test PASSed with p-value=0.0180506 > > > size <- 1000 > prob <- 0.2 > binom.pmf <- function (x) { dbinom(x, size, prob) } > rud <- function (n,lb=0,ub=size) { + dist <- udbinom(size=size,prob=prob) + gen <- unuran.new(dist) + ur(gen,n) + } > unur.test.discr("rud.binom", rfunc=rud, dfunc=binom.pmf, domain=c(0,size)) rud.binom() domain=(0,1000): chisq test PASSed with p-value=0.243122 > rm(rud) > rm(size,prob,binom.pmf) > > ## Geometric distribution - (replacement for rgeom) ------------------------- > for (i in 1:n.rep.domains) { + d <- sort(rbinom(2,size=200,prob=0.29)) + d[2] <- d[2]+1 ## protect agains domains of length 1 + unur.test.discr("geom", prob=0.1, domain=d) + } geom(0.1) domain=(48,58): chisq test PASSed with p-value=0.894035 geom(0.1) domain=(63,64): chisq test PASSed with p-value=0.623191 > for (i in 1:n.rep.params) { + p <- runif(1,min=0.03,max=0.99) + unur.test.discr("geom", prob=p, domain=c(0,1000)) + } geom(0.649238223955035) domain=(0,1000): chisq test PASSed with p-value=0.143352 geom(0.603533997014165) domain=(0,1000): chisq test PASSed with p-value=0.532611 geom(0.41745155878365) domain=(0,1000): chisq test PASSed with p-value=0.887785 geom(0.411882148683071) domain=(0,1000): chisq test PASSed with p-value=0.863712 geom(0.471435358151793) domain=(0,1000): chisq test PASSed with p-value=0.126136 > for (i in 1:n.rep.params) { + p <- runif(1,min=0.001,max=0.02) + unur.test.discr("geom", prob=p, domain=c(0,1000)) + } geom(0.0129916057945229) domain=(0,1000): chisq test PASSed with p-value=0.0522093 geom(0.0178291206290014) domain=(0,1000): chisq test PASSed with p-value=0.546622 geom(0.0171452961897012) domain=(0,1000): chisq test PASSed with p-value=0.62674 geom(0.00376768555422314) domain=(0,1000): chisq test PASSed with p-value=0.497425 geom(0.0128671072602738) domain=(0,1000): chisq test PASSed with p-value=0.35909 > > > ## -- Print statistics ------------------------------------------------------ > > unur.test.statistic() Tests for discrete distributions number of tests = 20 (number of warnings = 0 ) > > ## -- End ------------------------------------------------------------------- > > detach("package:Runuran",unload = TRUE) > > ## -------------------------------------------------------------------------- > > proc.time() user system elapsed 0.65 0.14 0.78