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("bindata-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('bindata') Loading required package: e1071 Loading required package: class Loading required package: mvtnorm > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "check.commonprob" > > ### * check.commonprob > > flush(stderr()); flush(stdout()) > > ### Name: check.commonprob > ### Title: Check Joint Binary Probabilities > ### Aliases: check.commonprob > ### Keywords: distribution multivariate > > ### ** Examples > > check.commonprob(cbind(c(0.5, 0.4), c(0.4, 0.8))) [1] TRUE attr(,"message") character(0) > > check.commonprob(cbind(c(0.5, 0.25), c(0.25, 0.8))) [1] FALSE attr(,"message") [1] "Error in Element ( 1 , 2 ): Admissible values are in [ 0.3 , 0.5 ]." > > check.commonprob(cbind(c(0.5, 0, 0), c(0, 0.5, 0), c(0, 0, 0.5))) [1] FALSE attr(,"message") [1] "The sum of the common probabilities of 1 , 2 , 3 must be at least 0.5 ." > > > > cleanEx(); ..nameEx <- "commonprob2sigma" > > ### * commonprob2sigma > > flush(stderr()); flush(stdout()) > > ### Name: commonprob2sigma > ### Title: Calculate a Covariance Matrix for the Normal Distribution out of > ### a Matrix of Joint Probabilites > ### Aliases: commonprob2sigma > ### Keywords: distribution multivariate > > ### ** Examples > > m <- cbind(c(1/2,1/5,1/6),c(1/5,1/2,1/6),c(1/6,1/6,1/2)) > sigma <- commonprob2sigma(m) > > > > cleanEx(); ..nameEx <- "ra2ba" > > ### * ra2ba > > flush(stderr()); flush(stdout()) > > ### Name: ra2ba > ### Title: Convert Real Valued Array to Binary Array > ### Aliases: ra2ba > ### Keywords: array > > ### ** Examples > > x <- array(rnorm(10), dim=c(2,5)) > ra2ba(x) [,1] [,2] [,3] [,4] [,5] [1,] 0 0 1 1 1 [2,] 1 1 0 1 0 > > > > cleanEx(); ..nameEx <- "rmvbin" > > ### * rmvbin > > flush(stderr()); flush(stdout()) > > ### Name: rmvbin > ### Title: Multivariate Binary Random Variates > ### Aliases: rmvbin > ### Keywords: multivariate distribution > > ### ** Examples > > ## uncorrelated columns: > rmvbin(10, margprob=c(0.3,0.9)) [,1] [,2] [1,] 0 1 [2,] 0 1 [3,] 0 1 [4,] 1 0 [5,] 0 1 [6,] 0 1 [7,] 0 1 [8,] 1 1 [9,] 1 1 [10,] 0 1 > > ## correlated columns > m <- cbind(c(1/2,1/5,1/6),c(1/5,1/2,1/6),c(1/6,1/6,1/2)) > rmvbin(10,commonprob=m) [,1] [,2] [,3] [1,] 1 1 0 [2,] 1 0 0 [3,] 0 1 1 [4,] 0 1 1 [5,] 1 0 0 [6,] 1 0 0 [7,] 0 0 1 [8,] 0 1 1 [9,] 0 1 0 [10,] 0 1 1 > > ## same as the second example, but faster if the same probabilities are > ## used repeatedly (commonprob2sigma rather slow) > sigma <- commonprob2sigma(m) > rmvbin(10,margprob=diag(m),sigma=sigma) [,1] [,2] [,3] [1,] 0 1 0 [2,] 0 1 0 [3,] 0 1 1 [4,] 0 1 0 [5,] 1 0 0 [6,] 1 0 0 [7,] 1 0 1 [8,] 0 1 0 [9,] 1 0 0 [10,] 0 1 0 > > > > cleanEx(); ..nameEx <- "simul.commonprob" > > ### * simul.commonprob > > flush(stderr()); flush(stdout()) > > ### Name: simul.commonprob > ### Title: Simulate Joint Binary Probabilities > ### Aliases: simul.commonprob > ### Keywords: distribution multivariate > > ### ** Examples > > simul.commonprob(seq(0,1,0.5), seq(-1,1,0.5), meth="mo", n1=10^4) -1 0 0 : done -1 0 0.5 : done -1 0 1 : done -1 0.5 0.5 : done -1 0.5 1 : done -1 1 1 : done -0.5 0 0 : done -0.5 0 0.5 : done -0.5 0 1 : done -0.5 0.5 0.5 : done -0.5 0.5 1 : done -0.5 1 1 : done 0 0 0 : done 0 0 0.5 : done 0 0 1 : done 0 0.5 0.5 : done 0 0.5 1 : done 0 1 1 : done 0.5 0 0 : done 0.5 0 0.5 : done 0.5 0 1 : done 0.5 0.5 0.5 : done 0.5 0.5 1 : done 0.5 1 1 : done 1 0 0 : done 1 0 0.5 : done 1 0 1 : done 1 0.5 0.5 : done 1 0.5 1 : done 1 1 1 : done , , -1 0 0.5 1 0 0 0.0 0.0 0.5 0 0.0 0.5 1 0 0.5 1.0 , , -0.5 0 0.5 1 0 0 0.00000 0.0 0.5 0 0.16772 0.5 1 0 0.50000 1.0 , , 0 0 0.5 1 0 0 0.00 0.0 0.5 0 0.25 0.5 1 0 0.50 1.0 , , 0.5 0 0.5 1 0 0 0.00000 0.0 0.5 0 0.33304 0.5 1 0 0.50000 1.0 , , 1 0 0.5 1 0 0 0.0 0.0 0.5 0 0.5 0.5 1 0 0.5 1.0 > > data(SimulVals) Warning in data(SimulVals) : data set 'SimulVals' not found > > > > > ### *