R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 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 a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("SuppDists-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('SuppDists') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Friedman" > > ### * Friedman > > flush(stderr()); flush(stdout()) > > ### Name: Friedman > ### Title: Friedman's chi-square > ### Aliases: dFriedman pFriedman qFriedman rFriedman sFriedman > ### Keywords: distribution > > ### ** Examples > > > pFriedman(2, r=5, N=10) [1] 0.2466344 > pFriedman(c(.8,3.5,9.3), r=5, N=10) ## approximately 5% 50% and 95% [1] 0.0554274 0.5045533 0.9505933 > sFriedman(r=5, N=10) $title [1] "Friedman's chi-square" $r [1] 5 $N [1] 10 $Mean [1] 4 $Median [1] 3.52 $Mode [1] 2.204724 $Variance [1] 7.2 $SD [1] 2.683282 $ThirdCentralMoment [1] 23.04 $FourthCentralMoment [1] 83.14291 $PearsonsSkewness...mean.minus.mode.div.SD [1] 0.6690597 $Skewness...sqrtB1 [1] 1.192570 $Kurtosis...B2.minus.3 [1] -1.396163 > plot(function(x)dFriedman(x, r=5, N=10),0,10) > > > > > cleanEx(); ..nameEx <- "Johnson" > > ### * Johnson > > flush(stderr()); flush(stdout()) > > ### Name: Johnson > ### Title: The Johnson distributions > ### Aliases: dJohnson pJohnson qJohnson rJohnson sJohnson moments > ### JohnsonFit > ### Keywords: distribution > > ### ** Examples > > > xx<-rnorm(500) > parms<-JohnsonFit(xx) > sJohnson(parms) $title [1] "Johnson Distribution" $gamma [1] -0.2704623 $delta [1] 2.208208 $xi [1] -0.2513960 $lambda [1] 2.012716 $type SU 3 $Mean [1] 0.02242493 $Median [1] -0.004260907 $Mode [1] -0.05435587 $Variance [1] 1.044111 $SD [1] 1.021817 $ThirdCentralMoment [1] -0.2173286 $FourthCentralMoment [1] 4.579047 $PearsonsSkewness...mean.minus.mode.div.SD [1] 0.07514141 $Skewness...sqrtB1 [1] -0.2037028 $Kurtosis...B2.minus.3 [1] 1.200316 > plot(function(xx)dJohnson(xx,parms),-2,2) > pJohnson(1,parms) [1] 0.8476952 > parms2<-JohnsonFit(rexp(50)) > qJohnson(p=0.5,list(parms,parms2)) [1] -0.004260907 0.630239519 > > ## JohnsonFit with moment="find" and moment="use" is not always possible, > ## and even when possible, may produce odd results. > ## parms<-JohnsonFit(x,moment="find") > > parms<-JohnsonFit(c(0,1,-.5,4),moment="use") > > sJohnson(parms) $title [1] "Johnson Distribution" $gamma [1] 1.191400 $delta [1] 2.739060 $xi [1] 0.556846 $lambda [1] 2.321434 $type SU 3 $Mean [1] -0.556846 $Median [1] -0.4850433 $Mode [1] -0.3623749 $Variance [1] 1 $SD [1] 1 $ThirdCentralMoment [1] -0.508333 $FourthCentralMoment [1] 4.011607 $PearsonsSkewness...mean.minus.mode.div.SD [1] -0.1944711 $Skewness...sqrtB1 [1] -0.508333 $Kurtosis...B2.minus.3 [1] 1.011607 > > # Fit illustration > data(cars) > xx<-cars$speed > parms<-JohnsonFit(xx) > hist(xx,freq=FALSE) > plot(function(x)dJohnson(x,parms),0,25,add=TRUE) > > > > > cleanEx(); ..nameEx <- "Kendall" > > ### * Kendall > > flush(stderr()); flush(stdout()) > > ### Name: Kendall > ### Title: The distribution of Kendall's tau > ### Aliases: dKendall pKendall qKendall rKendall sKendall > ### Keywords: distribution > > ### ** Examples > > > pKendall(0, N=10) [1] 0.5690997 > pKendall(c(-.42,0.02,.42), N=10) ## approximately 5% 50% and 95% [1] 0.05415675 0.56909970 0.96372492 > qKendall(.95,N=c(10,20)) [1] 0.4222222 0.2631579 > sKendall(N=10) $title [1] "Kendall's Tau" $N [1] 10 $Mean [1] 0 $Median [1] 0 $Mode [1] 0 $Variance [1] 0.0617284 $SD [1] 0.248452 $ThirdCentralMoment [1] 0 $FourthCentralMoment [1] 0.007319304 $PearsonsSkewness...mean.minus.mode.div.SD [1] 0 $Skewness...sqrtB1 [1] 0 $Kurtosis...B2.minus.3 [1] -1.079122 > plot(function(x)dKendall(x, N=10),-0.5,0.5) > > > > > cleanEx(); ..nameEx <- "KruskalWallis" > > ### * KruskalWallis > > flush(stderr()); flush(stdout()) > > ### Name: KruskalWallis > ### Title: Kruskall-Wallis distribution > ### Aliases: Kruskal KruskalWallis dKruskalWallis pKruskalWallis > ### qKruskalWallis rKruskalWallis sKruskalWallis > ### Keywords: distribution > > ### ** Examples > > > # Assuming three treatments, each with a sample size of 5. > pKruskalWallis(1, 3, 15, 0.6) [1] 0.3744376 > pKruskalWallis(c(.1,1.5,5.7), 3, 15, 0.6) ## approximately 5% 50% and 95% [1] 0.05218525 0.50337032 0.95107082 > sKruskalWallis(3, 15, 0.6) $title [1] "Kruskal Wallis" $c [1] 3 $N [1] 15 $U [1] 0.6 $Mean [1] 2 $Median [1] 1.485505 $Mode [1] 0.01621802 $Variance [1] 3.24 $SD [1] 1.8 $ThirdCentralMoment [1] 4.533323 $FourthCentralMoment [1] 27.48076 $PearsonsSkewness...mean.minus.mode.div.SD [1] 1.102101 $Skewness...sqrtB1 [1] 0.7773187 $Kurtosis...B2.minus.3 [1] -0.3821866 > plot(function(x)dKruskalWallis(x, 3, 15, 0.6),0.5,8) > > > > > cleanEx(); ..nameEx <- "MWC1019" > > ### * MWC1019 > > flush(stderr()); flush(stdout()) > > ### Name: MWC1019 > ### Title: A very long period pseudo-random generator > ### Aliases: rMWC1019 > ### Keywords: distribution > > ### ** Examples > > > rMWC1019(50,new.start=TRUE,seed=492166) [1] 0.60548715 0.15576769 0.90648628 0.44354049 0.70812371 0.83541904 [7] 0.15063995 0.04490980 0.08766492 0.38245984 0.51583843 0.74633285 [13] 0.88160851 0.69049519 0.52988982 0.47621251 0.19297964 0.06866930 [19] 0.57610470 0.17250269 0.12035562 0.35449891 0.70226299 0.53246368 [25] 0.45179421 0.70112654 0.25398168 0.01233980 0.52161630 0.25582614 [31] 0.83074379 0.35840710 0.23509159 0.69847117 0.91526503 0.21191841 [37] 0.11419786 0.84986951 0.60559911 0.07173439 0.17393346 0.28978156 [43] 0.84774292 0.23100496 0.10399894 0.63706631 0.15240021 0.15351668 [49] 0.50971803 0.44430783 > rMWC1019(50) [1] 0.22411096 0.76808128 0.13233495 0.84630917 0.53340165 0.99076381 [7] 0.52341210 0.96142503 0.35538491 0.50962629 0.55528291 0.70665447 [13] 0.26065178 0.23864927 0.98768011 0.84608053 0.72683578 0.85856857 [19] 0.12840059 0.35446470 0.15793083 0.70918603 0.18017472 0.52120733 [25] 0.71934035 0.25130026 0.88323958 0.61593554 0.23849084 0.44461705 [31] 0.87874975 0.41537874 0.50216534 0.73574614 0.48001463 0.42403925 [37] 0.70509248 0.97908263 0.72206114 0.32547434 0.74512352 0.46936768 [43] 0.84623621 0.93752473 0.82844161 0.90037250 0.20651306 0.04032835 [49] 0.17742936 0.72065938 > > > > > cleanEx(); ..nameEx <- "NormalScore" > > ### * NormalScore > > flush(stderr()); flush(stdout()) > > ### Name: NormalScore > ### Title: Normal Scores distribution > ### Aliases: NormScore dNormScore pNormScore qNormScore rNormScore > ### sNormScore normOrder > ### Keywords: distribution > > ### ** Examples > > > #Assuming three treatments, each with a sample size of 5 > pNormScore(2, 3, 15, 0.6) [1] 0.6050315 > pNormScore(c(0.11,1.5,5.6), 3, 15, 0.6) ## approximately 5% 50% and 95% [1] 0.04981046 0.49689354 0.95137315 > sNormScore(3, 15, 0.6) $title [1] "Normal Scores" $c [1] 3 $N [1] 15 $U [1] 0.6 $Mean [1] 2 $Median [1] 1.513024 $Mode [1] 0.02066517 $Variance [1] 3.08272 $SD [1] 1.755768 $ThirdCentralMoment [1] 4.135728 $FourthCentralMoment [1] 24.6069 $PearsonsSkewness...mean.minus.mode.div.SD [1] 1.127333 $Skewness...sqrtB1 [1] 0.7641011 $Kurtosis...B2.minus.3 [1] -0.4106624 > plot(function(x)dNormScore(x,c=5, N=15, U=0.6),0,5) > > > > > cleanEx(); ..nameEx <- "Pearson" > > ### * Pearson > > flush(stderr()); flush(stdout()) > > ### Name: Pearson > ### Title: The Pearson product moment correlation coefficient > ### Aliases: Pearson dPearson pPearson qPearson rPearson sPearson > ### Keywords: distribution > > ### ** Examples > > > pPearson(0.5, N=10) [1] 0.9294946 > pPearson(q=0.5, N=10, rho=0.3) [1] 0.7270447 > sPearson(N=10) $title [1] "Correlation coefficient" $rho [1] 0 $N [1] 10 $Mean [1] 0 $Median [1] -2.519357e-05 $Mode [1] -0.007874016 $Variance [1] 0.1018066 $SD [1] 0.3190715 $ThirdCentralMoment [1] 0 $FourthCentralMoment [1] 0.02549744 $PearsonsSkewness...mean.minus.mode.div.SD [1] 0.0246779 $Skewness...sqrtB1 [1] 0 $Kurtosis...B2.minus.3 [1] -0.5399479 > plot(function(x)dPearson(x,N=10,rho=0.7),-1,1) > > > > > cleanEx(); ..nameEx <- "Spearman" > > ### * Spearman > > flush(stderr()); flush(stdout()) > > ### Name: Spearman > ### Title: Spearman's rho > ### Aliases: dSpearman pSpearman qSpearman rSpearman sSpearman > ### Keywords: distribution > > ### ** Examples > > > pSpearman(.95, 10) [1] 0.9999755 > pSpearman(c(-0.55,0,0.55), 10) ## approximately 5% 50% and 95% [1] 0.0524413 0.5000000 0.9518607 > sSpearman(10) $title [1] "Spearman's rho" $r [1] 10 $Mean [1] 0 $Median [1] 0 $Mode [1] 0 $Variance [1] 0.1111111 $SD [1] 0.3333333 $ThirdCentralMoment [1] 0 $FourthCentralMoment [1] 0.03130864 $PearsonsSkewness...mean.minus.mode.div.SD [1] 0 $Skewness...sqrtB1 [1] 0 $Kurtosis...B2.minus.3 [1] -0.464 > plot(function(x)dSpearman(x, 10),-.9,.9) > > > > > > cleanEx(); ..nameEx <- "ghyper" > > ### * ghyper > > flush(stderr()); flush(stdout()) > > ### Name: ghyper > ### Title: Generalized hypergeometric distributions > ### Aliases: dghyper pghyper qghyper rghyper sghyper tghyper Generalized > ### hypergeometric Negative hypergeometric Inverse hypergeometric > ### Hypergeometric waiting time Beta-binomial Beta-negative-binomial > ### Beta-Pascal Generalized Waring > ### Keywords: distribution > > ### ** Examples > > > tghyper(a=4, k=4, N=10) ## classic [1] "type = classic -- 0 <= x <= 4" > tghyper(a=4.1, k=5, N=10) ## type IA(i) Real classic [1] "type = IAi -- 0 <= x <= 5" > tghyper(a=5, k=4.1, N=10) ## type IA(ii) Real classic [1] "type = IAii -- 0 <= x <= 5" > tghyper(a=4.2, k=4.6, N=12.2) ## type IB [1] "type = IB -- x = 0,1,2,..." > tghyper(a=-5.1, k=10, N=-7) ## type IIA [1] "type = IIA -- 0 <= x <= 10" > tghyper(a=-0.5, k=5.9, N=-0.7) ## type IIB [1] "type = IIB -- x = 0,1,2,..." > tghyper(a=10, k=-5.1, N=-7) ## type IIIA Negative hypergeometric [1] "type = IIIA -- 0 <= x <= 10" > tghyper(a=5.9, k=-0.5, N=-0.7) ## type IIIB [1] "type = IIIB -- x = 0,1,2,..." > tghyper(a=-1, k=-1, N=5) ## type IV Generalized Waring [1] "type = IV -- x = 0,1,2,..." > > sghyper(a=-1, k=-1, N=5) $title [1] "Generalized Hypergeometric" $a [1] -1 $k [1] -1 $N [1] 5 $Mean [1] 0.2 $Median [1] 0 $Mode [1] 0 $Variance [1] 0.36 $SD [1] 0.6 $ThirdCentralMoment [1] 1.176 $FourthCentralMoment [1] 8.9712 $PearsonsSkewness...mean.minus.mode.div.SD [1] 0.3333333 $Skewness...sqrtB1 [1] 5.444444 $Kurtosis...B2.minus.3 [1] 66.22222 > plot(function(x)dghyper(x,a=-1,k=-1,N=5),0,5) > > #Fisher's exact test: contingency table with rows (1,3),(3,1) > pghyper(1,4,4,8) [1] 0.2428571 > pghyper(3,4,4,8,lower.tail=FALSE) [1] 0.01428571 > > > #Beta-binomial applications: > > #Application examples: > tghyper(-4,3,-6) [1] "type = IIA -- 0 <= x <= 3" > pghyper(2,-4,3,-6,lower=FALSE) [1] 0.3571429 > pghyper(0,-2,10,-101) [1] 0.825688 > sghyper(-1,95,-6)$Mean+1 [1] 16.83333 > > > > > > cleanEx(); ..nameEx <- "invGauss" > > ### * invGauss > > flush(stderr()); flush(stdout()) > > ### Name: invGauss > ### Title: The inverse Gaussian and Wald distributions > ### Aliases: inverse Gaussian Wald distribution dinvGauss pinvGauss > ### qinvGauss rinvGauss sinvGauss > ### Keywords: distribution > > ### ** Examples > > > pinvGauss(1, 1, 16) [1] 0.5491225 > pinvGauss(c(.65,1,1.45), 1, 16) ## approximately 5% 50% and 95% [1] 0.05187512 0.54912255 0.94832541 > pars<-sinvGauss(1, 16) > plot(function(x)dinvGauss(x,1, 16),pars$Mean-3*pars$SD,pars$Mean+3*pars$SD) > > > > cleanEx(); ..nameEx <- "maxFratio" > > ### * maxFratio > > flush(stderr()); flush(stdout()) > > ### Name: maxFratio > ### Title: The maximum F-ratio distribution > ### Aliases: maxFratio dmaxFratio pmaxFratio qmaxFratio rmaxFratio > ### smaxFratio > ### Keywords: distribution > > ### ** Examples > > > pmaxFratio(4, 10, 10) [1] 0.4794943 > pmaxFratio(c(2.3, 4, 8.5), 10, 10) ## approximately 5% 50% and 95% [1] 0.04271746 0.47949428 0.94668291 > qmaxFratio(p=.95,df=c(10,20), k=10) [1] 8.644153 4.345125 > smaxFratio(10, 10) ## Wait for this, it may take a while $title [1] "Maximum F ratio" $df [1] 10 $k [1] 10 $Mean [1] 4.44 $Median [1] 4.08 $Mode [1] 3.33 $Variance [1] 3.35 $SD [1] 1.83 $ThirdCentralMoment [1] 9.59 $FourthCentralMoment [1] 63.82 $PearsonsSkewness...mean.minus.mode.div.SD [1] 0.61 $Skewness...sqrtB1 [1] 1.56 $Kurtosis...B2.minus.3 [1] 2.68 > plot(function(x)dmaxFratio(x, 10, 10),1,10) > > > > > cleanEx(); ..nameEx <- "ziggurat" > > ### * ziggurat > > flush(stderr()); flush(stdout()) > > ### Name: ziggurat > ### Title: The Ziggurat normal and exponential generator > ### Aliases: rziggurat > ### Keywords: distribution > > ### ** Examples > > > rziggurat(50,new.start=TRUE) [1] 0.59106567 -1.11930264 0.79352872 -0.23820327 -0.51171886 -0.25338383 [7] -2.18325597 1.18908427 -0.67961886 -0.88701723 0.73884706 0.67639929 [13] 0.23795807 -0.91126943 -0.43497588 0.87997233 0.58191970 -0.07409267 [19] -0.07506587 0.98944569 0.77815815 0.03316388 -0.03441163 -1.75053649 [25] 0.13018085 -0.81422930 -0.18216239 -0.30131548 -1.32228353 -1.36686973 [31] -1.38106599 -0.95395327 -0.86705744 0.28296206 0.75566871 1.61638532 [37] 2.25877021 3.02676461 -1.08778285 -0.95887843 0.35134487 -0.20997029 [43] -0.31388549 0.67799867 -0.79522108 -1.33155124 1.08769556 0.65130188 [49] -0.41127147 0.78602268 > rziggurat(50) [1] 1.28272657 0.20623824 -0.23019625 -0.26145110 -0.10612492 0.34488234 [7] 0.24628814 0.27619163 1.46863191 0.07460477 1.26594971 -1.00488052 [13] -1.60879197 0.53906731 -0.82807795 -0.81475984 0.39657798 -0.96041810 [19] -0.95392015 -0.10502001 -1.14402251 -0.75801938 1.27641697 0.11614016 [25] 1.27148426 1.32604353 1.17550845 -1.68494040 1.44983995 -0.57534811 [31] -0.39521659 -0.79566233 -0.15404830 -1.40161629 -0.47934860 0.05880256 [37] 0.78476323 0.19600984 -1.61853513 -0.93283829 -0.08371414 0.89649589 [43] -0.75718686 -0.03707774 -0.84233587 0.15272447 -0.50215383 -2.43722767 [49] 1.91529407 0.17305623 > rziggurat(50,new.start=TRUE) [1] 0.59106567 -1.11930264 0.79352872 -0.23820327 -0.51171886 -0.25338383 [7] -2.18325597 1.18908427 -0.67961886 -0.88701723 0.73884706 0.67639929 [13] 0.23795807 -0.91126943 -0.43497588 0.87997233 0.58191970 -0.07409267 [19] -0.07506587 0.98944569 0.77815815 0.03316388 -0.03441163 -1.75053649 [25] 0.13018085 -0.81422930 -0.18216239 -0.30131548 -1.32228353 -1.36686973 [31] -1.38106599 -0.95395327 -0.86705744 0.28296206 0.75566871 1.61638532 [37] 2.25877021 3.02676461 -1.08778285 -0.95887843 0.35134487 -0.20997029 [43] -0.31388549 0.67799867 -0.79522108 -1.33155124 1.08769556 0.65130188 [49] -0.41127147 0.78602268 > > > > > ### *