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("BHH2-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('BHH2') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "anovaPlot" > > ### * anovaPlot > > flush(stderr()); flush(stdout()) > > ### Name: anovaPlot > ### Title: Graphical Anova > ### Aliases: anovaPlot > ### Keywords: design hplot regression > > ### ** Examples > > library(BHH2) > data(heads.data) > heads.data$periods <- factor(heads.data$periods) > heads.data$heads <- factor(heads.data$heads) > > heads.aov <- aov(resp~periods+heads,data=heads.data) > anovaPlot(heads.aov) > > anovaPlot(heads.aov,labels=TRUE,faclab=TRUE) > > > > > cleanEx(); ..nameEx <- "corrosion.data" > > ### * corrosion.data > > flush(stderr()); flush(stdout()) > > ### Name: corrosion.data > ### Title: Corrosion data > ### Aliases: corrosion.data > ### Keywords: datasets > > ### ** Examples > > data(corrosion.data) > str(corrosion.data) `data.frame': 24 obs. of 4 variables: $ run : Factor w/ 6 levels "r1","r2","r3",..: 1 1 1 1 2 2 2 2 3 3 ... $ heats : Factor w/ 3 levels "T360","T370",..: 1 1 1 1 2 2 2 2 3 3 ... $ coating : Factor w/ 4 levels "C1","C2","C3",..: 2 3 1 4 1 3 4 2 3 1 ... $ resistance: int 73 83 67 89 65 87 86 91 147 155 ... > plot(corrosion.data) > > > > cleanEx(); ..nameEx <- "dotPlot" > > ### * dotPlot > > flush(stderr()); flush(stdout()) > > ### Name: dotPlot > ### Title: Dot plot: scatter plot with stacked dots similar to the > ### stem-and-leaf plot > ### Aliases: dotPlot > ### Keywords: hplot > > ### ** Examples > > library(BHH2) > data(tab03B1) > attach(tab03B1) > stem(yield) #stem-leaf plot The decimal point is at the | 76 | 5 77 | 59 78 | 14 79 | 0355566778 80 | 0012233455667799 81 | 00144566678888999 82 | 00012222333344566778899 83 | 000000111233333455555556667789 84 | 00112223344445566777778888899 85 | 0000011222344445666778899 86 | 01222234555666667777788 87 | 12222233478 88 | 002246899 89 | 034779 90 | 04558 91 | 7 > plt <- dotPlot(yield) # equivalent dotPlot > > # same dot plot with max and min observations labelled > plt <- dotPlot(yield,xlim=c(75,95),xlab="yield",pch.size="x",hcex=1) > text(c(min(yield),max(yield),80),rep(0.05,3),c("min","max",80)) > segments(80,min(plt$y),80,max(plt$y),lty=2) > detach() > > > > cleanEx(); ..nameEx <- "dots" > > ### * dots > > flush(stderr()); flush(stdout()) > > ### Name: dots > ### Title: Dots display > ### Aliases: dots > ### Keywords: aplot hplot > > ### ** Examples > > library(BHH2) > set.seed(4) > # Defines the height of the plot area between c(0,1) > dotPlot(rnorm(100),xlab="x") > > x <- rnorm(100) > > # plots (possibly) overlapping points at y=0.3 > dots(x,y=0.3) > # plots (possibly) overlapping points at y=0.4 > dots(x,y=0.4,stacked=TRUE,base=FALSE) > # plots (hopefully) stacked points at y=0.5 allowing the dots to as high as 0.9 > dots(x,y=0.5,stacked=TRUE,base=FALSE,hmax=.9) > > > > cleanEx(); ..nameEx <- "ffDesMatrix" > > ### * ffDesMatrix > > flush(stderr()); flush(stdout()) > > ### Name: ffDesMatrix > ### Title: Full or fractional factorial design matrix generation > ### Aliases: ffDesMatrix > ### Keywords: design > > ### ** Examples > > ffDesMatrix(5) # Full 2^5 factorial design [,1] [,2] [,3] [,4] [,5] [1,] -1 -1 -1 -1 -1 [2,] 1 -1 -1 -1 -1 [3,] -1 1 -1 -1 -1 [4,] 1 1 -1 -1 -1 [5,] -1 -1 1 -1 -1 [6,] 1 -1 1 -1 -1 [7,] -1 1 1 -1 -1 [8,] 1 1 1 -1 -1 [9,] -1 -1 -1 1 -1 [10,] 1 -1 -1 1 -1 [11,] -1 1 -1 1 -1 [12,] 1 1 -1 1 -1 [13,] -1 -1 1 1 -1 [14,] 1 -1 1 1 -1 [15,] -1 1 1 1 -1 [16,] 1 1 1 1 -1 [17,] -1 -1 -1 -1 1 [18,] 1 -1 -1 -1 1 [19,] -1 1 -1 -1 1 [20,] 1 1 -1 -1 1 [21,] -1 -1 1 -1 1 [22,] 1 -1 1 -1 1 [23,] -1 1 1 -1 1 [24,] 1 1 1 -1 1 [25,] -1 -1 -1 1 1 [26,] 1 -1 -1 1 1 [27,] -1 1 -1 1 1 [28,] 1 1 -1 1 1 [29,] -1 -1 1 1 1 [30,] 1 -1 1 1 1 [31,] -1 1 1 1 1 [32,] 1 1 1 1 1 > ffDesMatrix(5,gen=list(c(5,1,2,3,4))) # 2^(5-1) factorial design [,1] [,2] [,3] [,4] [,5] [1,] -1 -1 -1 -1 1 [2,] 1 -1 -1 -1 -1 [3,] -1 1 -1 -1 -1 [4,] 1 1 -1 -1 1 [5,] -1 -1 1 -1 -1 [6,] 1 -1 1 -1 1 [7,] -1 1 1 -1 1 [8,] 1 1 1 -1 -1 [9,] -1 -1 -1 1 -1 [10,] 1 -1 -1 1 1 [11,] -1 1 -1 1 1 [12,] 1 1 -1 1 -1 [13,] -1 -1 1 1 1 [14,] 1 -1 1 1 -1 [15,] -1 1 1 1 -1 [16,] 1 1 1 1 1 > ffDesMatrix(5,gen=list(c(4,1,2),c(-5,1,3))) # 2^(5-2) factorial design [,1] [,2] [,3] [,4] [,5] [1,] -1 -1 -1 1 -1 [2,] 1 -1 -1 -1 1 [3,] -1 1 -1 -1 -1 [4,] 1 1 -1 1 1 [5,] -1 -1 1 1 1 [6,] 1 -1 1 -1 -1 [7,] -1 1 1 -1 1 [8,] 1 1 1 1 -1 > > > > cleanEx(); ..nameEx <- "ffFullMatrix" > > ### * ffFullMatrix > > flush(stderr()); flush(stdout()) > > ### Name: ffFullMatrix > ### Title: Full model matrix from a design matrix > ### Aliases: ffFullMatrix > ### Keywords: design > > ### ** Examples > > print(X <- ffDesMatrix(5,gen=list(c(5,1,2,3,4)))) [,1] [,2] [,3] [,4] [,5] [1,] -1 -1 -1 -1 1 [2,] 1 -1 -1 -1 -1 [3,] -1 1 -1 -1 -1 [4,] 1 1 -1 -1 1 [5,] -1 -1 1 -1 -1 [6,] 1 -1 1 -1 1 [7,] -1 1 1 -1 1 [8,] 1 1 1 -1 -1 [9,] -1 -1 -1 1 -1 [10,] 1 -1 -1 1 1 [11,] -1 1 -1 1 1 [12,] 1 1 -1 1 -1 [13,] -1 -1 1 1 1 [14,] 1 -1 1 1 -1 [15,] -1 1 1 1 -1 [16,] 1 1 1 1 1 > ffFullMatrix(X[,1:4],x=c(1,2,3,4),maxInt=2,blk=X[,5]) $Xa one bk1 x1 x2 x3 x4 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 $nTerms blk main int.2 int.3 0 3 3 1 > > > > cleanEx(); ..nameEx <- "heads.data" > > ### * heads.data > > flush(stderr()); flush(stdout()) > > ### Name: heads.data > ### Title: Machine heads data > ### Aliases: heads.data > ### Keywords: datasets > > ### ** Examples > > data(heads.data) > str(heads.data) `data.frame': 30 obs. of 6 variables: $ obs : int 1 2 3 4 5 6 7 8 9 10 ... $ periods: Factor w/ 6 levels "P1","P2","P3",..: 1 1 1 1 1 2 2 2 2 2 ... $ heads : Factor w/ 5 levels "H1","H2","H3",..: 1 2 3 4 5 1 2 3 4 5 ... $ days : Factor w/ 2 levels "D1","D2": 1 1 1 1 1 1 1 1 1 1 ... $ shifts : Factor w/ 3 levels "S1","S2","S3": 1 1 1 1 1 2 2 2 2 2 ... $ resp : int 20 14 17 12 22 16 19 16 17 21 ... > plot(heads.data) > > > > cleanEx(); ..nameEx <- "lambdaPlot" > > ### * lambdaPlot > > flush(stderr()); flush(stdout()) > > ### Name: lambdaPlot > ### Title: Lambda plot: traces the t and F statistics in Box-Cox > ### transformation of the response > ### Aliases: lambdaPlot > ### Keywords: design hplot > > ### ** Examples > > library(BHH2) > # Lambda Plot tracing t values. > data(woolen.data) > woolen.lm <- lm(y~x1+x2+x3+I(x1^2)+I(x2^2)+I(x3^2)+ + I(x1*x2)+I(x1*x3)+I(x2*x3)+I(x1*x2*x3),data=woolen.data) > lambdaPlot(woolen.lm,cex=.8,stat="t") term label 1 (Intercept) 2 x1 A 3 x2 B 4 x3 C 5 `I(x1^2)` D 6 `I(x2^2)` E 7 `I(x3^2)` F 8 `I(x1 * x2)` G 9 `I(x1 * x3)` H 10 `I(x2 * x3)` I 11 `I(x1 * x2 * x3)` J > > # Lambda Plot tracing F values. > woolen2.lm <- lm(y~x1+x2+x3,data=woolen.data) > lambdaPlot(woolen2.lm,lambda=seq(-1,1,length=41),stat="F",global=TRUE) [1] "y" term label 1 Model A > > # Lambda Plot tracing F values. > data(poison.data) > poison.lm <- lm(y~treat*poison,data=poison.data) > lambdaPlot(poison.lm,lambda=seq(-3,1,by=.1),stat="F",global=FALSE) [1] "y" term label 1 treat A 2 poison B 3 treat:poison C > > > > cleanEx(); ..nameEx <- "penicillin.data" > > ### * penicillin.data > > flush(stderr()); flush(stdout()) > > ### Name: penicillin.data > ### Title: Penicillin data > ### Aliases: penicillin.data > ### Keywords: datasets > > ### ** Examples > > data(penicillin.data) > str(penicillin.data) `data.frame': 20 obs. of 4 variables: $ blend: Factor w/ 5 levels "B1","B2","B3",..: 1 2 3 4 5 1 2 3 4 5 ... $ run : int 1 4 2 1 3 3 2 1 3 4 ... $ treat: Factor w/ 4 levels "A","B","C","D": 1 1 1 1 1 2 2 2 2 2 ... $ yield: int 89 84 81 87 79 88 77 87 92 81 ... > plot(penicillin.data) > > > > cleanEx(); ..nameEx <- "permtest" > > ### * permtest > > flush(stderr()); flush(stdout()) > > ### Name: permtest > ### Title: Permutation test: randomization test for small size samples > ### Aliases: permtest > ### Keywords: design distribution > > ### ** Examples > > library(BHH2) > > # Permutation test for Tomato Data > data(tomato.data) > cat("Tomato Data (not paired):\n") Tomato Data (not paired): > attach(tomato.data) > a <- pounds[fertilizer=="A"] > b <- pounds[fertilizer=="B"] > print(round(test <- permtest(b,a),3)) N t.obs t-Dist:P(>t) PermDist:P(>t) F.obs 462.000 0.444 0.334 0.327 0.562 F-Dist:P(>F) PermDist:P(>F) 0.730 0.784 > detach() > > # Permutation test for Boy's Shoes Example > data(shoes.data) > cat("Shoes Data (paired):\n") Shoes Data (paired): > attach(shoes.data) > x <- matB-matA > print(round(test <- permtest(x),3)) N t.obs t-Dist-P(>t) PermDist-P(>t) 1024.000 3.349 0.004 0.005 > detach() > > > > > cleanEx(); ..nameEx <- "poison.data" > > ### * poison.data > > flush(stderr()); flush(stdout()) > > ### Name: poison.data > ### Title: Poison example data set > ### Aliases: poison.data > ### Keywords: datasets > > ### ** Examples > > data(poison.data) > str(poison.data) `data.frame': 48 obs. of 3 variables: $ poison: Factor w/ 3 levels "I","II","III": 1 1 1 1 2 2 2 2 3 3 ... $ treat : Factor w/ 4 levels "A","B","C","D": 1 1 1 1 1 1 1 1 1 1 ... $ y : num 0.31 0.45 0.46 0.43 0.36 0.29 0.4 0.23 0.22 0.21 ... > plot(poison.data) > > > > cleanEx(); ..nameEx <- "shoes.data" > > ### * shoes.data > > flush(stderr()); flush(stdout()) > > ### Name: shoes.data > ### Title: Boys' shoes data set > ### Aliases: shoes.data > ### Keywords: datasets > > ### ** Examples > > data(shoes.data) > str(shoes.data) `data.frame': 10 obs. of 5 variables: $ boy : int 1 2 3 4 5 6 7 8 9 10 $ matA : num 13.2 8.2 10.9 14.3 10.7 6.6 9.5 10.8 8.8 13.3 $ sideA: Factor w/ 2 levels "L","R": 1 1 2 1 2 1 1 1 2 1 $ matB : num 14 8.8 11.2 14.2 11.8 6.4 9.8 11.3 9.3 13.6 $ sideB: Factor w/ 2 levels "L","R": 2 2 1 2 1 2 2 2 1 2 > plot(shoes.data) > > > > cleanEx(); ..nameEx <- "subsets" > > ### * subsets > > flush(stderr()); flush(stdout()) > > ### Name: subsets > ### Title: Generation of all the combinations of k elements from n possible > ### Aliases: subsets > ### Keywords: manip misc > > ### ** Examples > > library(BHH2) > subsets(5,3) [,1] [,2] [,3] [1,] 1 2 3 [2,] 1 2 4 [3,] 1 2 5 [4,] 1 3 4 [5,] 1 3 5 [6,] 1 4 5 [7,] 2 3 4 [8,] 2 3 5 [9,] 2 4 5 [10,] 3 4 5 > subsets(5,3,letters) [,1] [,2] [,3] [1,] "a" "b" "c" [2,] "a" "b" "d" [3,] "a" "b" "e" [4,] "a" "c" "d" [5,] "a" "c" "e" [6,] "a" "d" "e" [7,] "b" "c" "d" [8,] "b" "c" "e" [9,] "b" "d" "e" [10,] "c" "d" "e" > subsets(5,3,c(10,20,30,50,80)) [,1] [,2] [,3] [1,] 10 20 30 [2,] 10 20 50 [3,] 10 20 80 [4,] 10 30 50 [5,] 10 30 80 [6,] 10 50 80 [7,] 20 30 50 [8,] 20 30 80 [9,] 20 50 80 [10,] 30 50 80 > > > > cleanEx(); ..nameEx <- "tab03B1" > > ### * tab03B1 > > flush(stderr()); flush(stdout()) > > ### Name: tab03B1 > ### Title: Table 3.2 > ### Aliases: tab03B1 > ### Keywords: datasets > > ### ** Examples > > library(BHH2) > data(tab03B1) > attach(tab03B1) > stem(yield) The decimal point is at the | 76 | 5 77 | 59 78 | 14 79 | 0355566778 80 | 0012233455667799 81 | 00144566678888999 82 | 00012222333344566778899 83 | 000000111233333455555556667789 84 | 00112223344445566777778888899 85 | 0000011222344445666778899 86 | 01222234555666667777788 87 | 12222233478 88 | 002246899 89 | 034779 90 | 04558 91 | 7 > stem(ave10) The decimal point is 1 digit(s) to the left of the | 828 | 2 830 | 298 832 | 12384 834 | 33466790113455788889 836 | 1122588889900122344577 838 | 2234455788899990111122233444668999 840 | 01244456667788889991122455566678899 842 | 01133667882333356788 844 | 0001122224770111347889 846 | 678002467788899 848 | 122556700024555 850 | 138 852 | 0147 854 | 75 > plot(yield,xlab="time order",ylab="yield") > detach() > > > > cleanEx(); ..nameEx <- "tab03B2" > > ### * tab03B2 > > flush(stderr()); flush(stdout()) > > ### Name: tab03B2 > ### Title: Table 3.3 > ### Aliases: tab03B2 > ### Keywords: datasets > > ### ** Examples > > library(BHH2) > data(tab03B2) > attach(tab03B2) > # displays the differences as dot plot (similar to histograms) > plt <- dotPlot(diff10,xlim=2.55*c(-1,+1),xlab="differences") > segments(1.3,0,1.3,max(plt$y)) #vertical line at x=1.3 > detach() > > > > cleanEx(); ..nameEx <- "tomato.data" > > ### * tomato.data > > flush(stderr()); flush(stdout()) > > ### Name: tomato.data > ### Title: Tomato plants data set > ### Aliases: tomato.data > ### Keywords: datasets > > ### ** Examples > > data(tomato.data) > str(tomato.data) `data.frame': 11 obs. of 3 variables: $ pos : int 1 2 3 4 5 6 7 8 9 10 ... $ pounds : num 29.9 11.4 26.6 23.7 25.3 28.5 14.2 17.9 16.5 21.1 ... $ fertilizer: Factor w/ 2 levels "A","B": 1 1 2 2 1 2 2 2 1 1 ... > plot(tomato.data) > > > > cleanEx(); ..nameEx <- "woolen.data" > > ### * woolen.data > > flush(stderr()); flush(stdout()) > > ### Name: woolen.data > ### Title: Textile experiment data set > ### Aliases: woolen.data > ### Keywords: datasets > > ### ** Examples > > data(woolen.data) > str(woolen.data) `data.frame': 27 obs. of 4 variables: $ x1: int -1 -1 -1 -1 -1 -1 -1 -1 -1 0 ... $ x2: int -1 -1 -1 0 0 0 1 1 1 -1 ... $ x3: int -1 0 1 -1 0 1 -1 0 1 -1 ... $ y : int 674 370 292 338 266 210 170 118 90 1414 ... > plot(woolen.data) > > > > ### *