Title: | Useful Functions for Box, Hunter and Hunter II |
---|---|
Description: | Functions and data sets reproducing some examples in Box, Hunter and Hunter II. Useful for statistical design of experiments, especially factorial experiments. |
Authors: | Ernesto Barrios |
Maintainer: | Kjetil B.Halvorsen <[email protected]> |
License: | GPL (>= 2) |
Version: | 2016.05.31 |
Built: | 2025-03-04 05:18:07 UTC |
Source: | https://github.com/cran/BHH2 |
Dots plot displaying the deviations of factor levels from the mean showing the residuals as reference distribution.
anovaPlot(obj, stacked = TRUE, base = TRUE, axes = TRUE, faclab = TRUE, labels = FALSE, cex = par("cex"), cex.lab = par("cex.lab"), ...)
anovaPlot(obj, stacked = TRUE, base = TRUE, axes = TRUE, faclab = TRUE, labels = FALSE, cex = par("cex"), cex.lab = par("cex.lab"), ...)
obj |
Object of class |
stacked |
logical. If |
base |
logical. By default a base line is displayed for each factor.
If |
axes |
logical. By default a scaled axes is drawn for each factor.
If |
faclab |
logical. By default factor effect names and ‘Residuals’ are used to label each dot plot. No axis is labelled otherwise. |
labels |
logical. By default, dots are used to the display.
If |
cex |
numeric. Expansion factor of the character used for labelling the factor levels. |
cex.lab |
numeric. Expansion factor of the character used for labelling each factor. |
... |
additional parameters passed to the |
Dots plot are displayed for the scaled deviations of factor levels from
the grand mean and the distribution of the residuals is shown at the bottom
of the plot for graphical comparison. The scaled factor for the factor
deviations is , where
and
are the factor and residuals degrees of freedom reported by
anova(obj)
.
If labels=TRUE
then the factor levels are used for as points
instead of dots. This option is useful to post labelling the dot plots.
See dots
function.
The Anova plot is built in a plot
area. The area plot is divided to accommodate each of the factors and
the residual at the bottom of the plotting area. The function returns a
list with the coordinates of all the dots displayed.
The function is called for graphical display of factor levels mean and residuals as reference distribution. An invisible list with the actual (x,y) coordinates used for each of the factors and residuals.
The function identifies as an interaction factor any factor with the colon character ":" in its name. Factors like "I(A:B)" will give you problems.
The anova plot presented here is thought for graphical comparison of factor effects in one-layer balanced designed experiments. The function is not prepared for general situations. However, representation of some simple split-plot experiments is possible.
Ernesto Barrios
Box G. E. P. (2000). Box on Quality. Edited by G. C. Tiao et al. New York: Wiley.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
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)
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)
Corrosion resistance study data set.
data(corrosion.data)
data(corrosion.data)
A data frame with 24 observations on the following 4 variables.
factor with 6 levels. The casting order.
factor with 3 levels. The casting temperature.
factor with 4 levels. The coating treatment.
numeric vector. Corrosion resistance response.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
data(corrosion.data) str(corrosion.data) plot(corrosion.data)
data(corrosion.data) str(corrosion.data) plot(corrosion.data)
Displays an one-dimensional scatter plot with stacking similar to stem-and-leaf plot or histograms.
dotPlot(x, y = 0, xlim = range(x,na.rm=TRUE), xlab = NULL, scatter = FALSE, hmax = 1, base = TRUE, axes = TRUE, frame = FALSE, pch = 21, pch.size = "x", labels = NULL, hcex = 1, cex =par("cex"), cex.axis = par("cex.axis"),...)
dotPlot(x, y = 0, xlim = range(x,na.rm=TRUE), xlab = NULL, scatter = FALSE, hmax = 1, base = TRUE, axes = TRUE, frame = FALSE, pch = 21, pch.size = "x", labels = NULL, hcex = 1, cex =par("cex"), cex.axis = par("cex.axis"),...)
x |
numeric vector to be displayed. |
y |
numeric. Height of the basis of the plot. |
xlim |
numeric. Range of the x axis. |
xlab |
character string. label for the horizontal axis. |
scatter |
logical. If TRUE a one-dimensional scatter plot of x, similar to |
hmax |
numeric. Height of the highest dot.
|
base |
logical. If |
axes |
logical. If |
frame |
logical. If |
pch |
numeric or character. Character number or character to be used for the display. |
pch.size |
numeric. Character to be used to distribute the "dots" ( |
labels |
character vector. If |
hcex |
numeric. Expansion (shrink) factor for character height. See Details. |
cex |
numeric. Expansion factor used for character display.
See |
cex.axis |
numeric. Expansion factor used in case of labelling the axis. |
... |
additional graphical parameters. |
Basically function dotPlot
calls function dots to display
a stacked one-dimensional scatter plot within vertical limits 0 and 1.
See dots
for more details.
The function is called for its side effect which is to produce one-dimensional scatter plot with stacking as described, for example, in Chambers et al. (1983) It returns invisible a data frame with the actual coordinates (in users units).
Since the dots are stacked vertically, their alignment is subject to rounding errors. Dots may be slightly moved in either side from their actual value.
Ernesto Barrios
Chambers, J. M., Cleveland, W. S., Kleiner, B. and Tukey, P. A. (1983) Graphical Methods for Data Analysis. New York: Chapman \& Hall
library(BHH2) data(tab03B1) attach(tab03B1) stem(yield) #stem-leaf plot 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()
library(BHH2) data(tab03B1) attach(tab03B1) stem(yield) #stem-leaf plot 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()
The function adds to the current plot an one-dimensional scatter plot with stacking similar to a stem-leaf plot or histograms but using characters. .
dots(x = , y = 0.1, xlim = range(x,na.rm=TRUE), stacked = FALSE, hmax= 0.5, base = TRUE, axes = FALSE, pch = 21, pch.size = "x", labels = NULL, hcex = 1, cex = par("cex"), cex.axis = par("cex.axis"))
dots(x = , y = 0.1, xlim = range(x,na.rm=TRUE), stacked = FALSE, hmax= 0.5, base = TRUE, axes = FALSE, pch = 21, pch.size = "x", labels = NULL, hcex = 1, cex = par("cex"), cex.axis = par("cex.axis"))
x |
numeric vector to be displayed in the dot plot. |
y |
numeric. Height of the dots (characters) at the base level. By default
|
xlim |
numeric vector with 2 entries: |
stacked |
logical. If |
hmax |
numeric. The maximum height in user units. By default
|
base |
logical. If |
axes |
logical. If |
pch |
numeric or character. Character number or character to be used for the display. |
pch.size |
numeric. Character to be used to distribute the "dots" ( |
labels |
character vector. If |
hcex |
numeric. Expansion (shrink) factor for character height. See details. |
cex |
numeric. Expansion factor used for character display. See par. |
cex.axis |
numeric. Expansion factor used in case of labelling the axis. |
Function dots
adds to the current plot a dot plot similar to a
stem-and-leaf plot using characters specified by pch
and
labels=NULL
. If labels
is not NULL
then it is
expected to be a character vector and will
will be used to display each of the points. Its use is repeated or cut short if necessary.
The function computes the width and height size using character pch.size
calling
strwidth
and strheight
, but displays pch
instead.
Mainly this is used when pch
is not given by a quoted character,
for example, pch=21
. Also, currently the par("mkh") is ignored so
hcex
is used to compute the "working" height of the characters:
hcex*strheight(pch.size,units="user")
. If stacked=TRUE
,
the base line is divided in subintervals of size strwidth(pch.size)
and computed the number of points in each subinterval. If maximum number
of stacked characters exceed hmax
then the characters are overlapped to
adjust their total height to hmax
.
Invisible data frame with columns (x,y,labels). ‘x’ and ‘y’ are the coordinates in user units of each point and ‘labels’ the corresponding character displayed.
Ernesto Barrios
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)
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)
The function generates the design matrix provided the number of 2-levels design factors and defining relations.
ffDesMatrix(k, gen = NULL)
ffDesMatrix(k, gen = NULL)
k |
numeric. The number of 2-levels design factors in the designs. |
gen |
list. If |
A defining relation is declared by a vector where the first entry
corresponds to the left hand side (LHS) of the defining
equation. For example, if k=5
, and gen=list(c(-5,1,2,3,4))
,
then the defining equation is . A full 2-levels (-1,1)
factorial design is generated. For each defining relation the LHS column
is replaced by the corresponding columns product. At the end repeated
runs are removed from the matrix.
The function returns a 2-levels design matrix with k
columns.
Ernesto Barrios
conf.design
of the
conf.design package,
FrF2
from the FrF2 package.
ffDesMatrix(5) # Full 2^5 factorial design ffDesMatrix(5,gen=list(c(5,1,2,3,4))) # 2^(5-1) factorial design ffDesMatrix(5,gen=list(c(4,1,2),c(-5,1,3))) # 2^(5-2) factorial design
ffDesMatrix(5) # Full 2^5 factorial design ffDesMatrix(5,gen=list(c(5,1,2,3,4))) # 2^(5-1) factorial design ffDesMatrix(5,gen=list(c(4,1,2),c(-5,1,3))) # 2^(5-2) factorial design
The function builds the full matrix with the constant term, main effects and interactions from a design matrix.
ffFullMatrix(X, x, maxInt, blk = NULL)
ffFullMatrix(X, x, maxInt, blk = NULL)
X |
numeric matrix. Design matrix. |
x |
numeric vector. Design matrix entries to use to construct the full model matrix. |
maxInt |
numeric. Highest interaction order. |
blk |
numeric matrix. Each column correspond to a blocking factor. |
Columns x
of matrix X
are used for main effects. All
the 2, ... , maxInt
order interaction are constructed.
The first columns of the final matrix correspond to the constant term (1's)
and block factors.
The function returns list with the following components:
Xa |
matrix |
. Augmented matrix with columns for the constant terms, blocking factors, main effects, second order interactions, ..., etc.
x |
numeric vector. Design matrix |
maxInt |
numeric. The highest interaction order. |
nTerms |
numeric vector. Contains the number of blocking factors, main effects, 2nd order interaction effects, ... , etc. |
Ernesto Barrios
print(X <- ffDesMatrix(5,gen=list(c(5,1,2,3,4)))) ffFullMatrix(X[,1:4],x=c(1,2,3,4),maxInt=2,blk=X[,5]) ffFullMatrix(X[,1:5],x=c(1,3,5),maxInt=3)
print(X <- ffDesMatrix(5,gen=list(c(5,1,2,3,4)))) ffFullMatrix(X[,1:4],x=c(1,2,3,4),maxInt=2,blk=X[,5]) ffFullMatrix(X[,1:5],x=c(1,3,5),maxInt=3)
Data set of the variability of machine heads in a quality improvement experiment.
data(heads.data)
data(heads.data)
A data frame with 30 observations on the following 6 variables.
numeric. Observation number.
factor. Periods factor (P1, ..., P6).
factor. Type of head factor (H1, ..., H5).
factor. Day factor (D1 and D2).
factor. Shift factor (S1, S2, and S3).
numeric. Response.
Box, G. E. P. (1993). "How to Get Lucky". Quality Engineering, Vol. 5, No. 3, pp 517-524.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
data(heads.data) str(heads.data) plot(heads.data)
data(heads.data) str(heads.data) plot(heads.data)
Trace regression coefficients' t-values or F-ratios for different values of in
the Box-Cox transformation.
lambdaPlot(mod, lambda = seq(-1, 1, by = 0.1), stat = "F", global = TRUE, cex = par("cex"), ...)
lambdaPlot(mod, lambda = seq(-1, 1, by = 0.1), stat = "F", global = TRUE, cex = par("cex"), ...)
mod |
list. A list of class |
lambda |
numeric. The values of |
stat |
character. Either |
global |
logical. Applied only for |
cex |
numeric. Expansion factor used to label the trace lines. |
... |
additional graphical parameters passed to |
The response is transformed as
for each value of
(
lambda
) and the model refitted.
The t-values or F-ratios of the coefficients are saved for the display.
If global=TRUE
, then the F-ratio of the whole model is
plotted instead.
The function returns an invisible list with components:
lambda |
numeric. Vector of length |
t.lambda |
matrix ( |
f.lambda |
matrix ( |
For each value of the model is refitted. Computations can be
done more efficiently and will be incorporated in future versions.
Ernesto Barrios
Box, G. E. P. and C. Fung (1995) "The Importance of Data Transformation in Designed Experiments for Life Testing". Quality Engineering, Vol. 7, No. 3, pp. 625-68.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
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") # 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) # 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)
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") # 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) # 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)
Penicillin yield example data set.
data(penicillin.data)
data(penicillin.data)
A data frame with 20 observations on the following 4 variables.
factor with 5 levels: B1
B2
B3
B4
B5
.
Blend factor used to block the experiment.
numeric vector. Run order within the blocking (Blend) factor.
factor with levels: A
B
C
D
.
The process variants called treatment.
numeric vector. Experiment yield response.
Box G. E. P, Hunter, W. C. and Hunter, J. S. (1978). Statistics for Experimenters. New York: Wiley.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
data(penicillin.data) str(penicillin.data) plot(penicillin.data)
data(penicillin.data) str(penicillin.data) plot(penicillin.data)
Permutation test for means and variance comparisons.
permtest(x, y = NULL)
permtest(x, y = NULL)
x |
numeric vector. Sample group X. |
y |
numeric vector. Sample group Y. |
In the one–sample problem, the function builds all
possible
combinations. For the two–sample problem,
all possible
samples size
(=
length(x)
) and (=
length(y)
) are
generated and the permutation distributions for the t-statistics
and F-ratios. p-values are computed based on these
distributions.
The function returns the number of different samples
generated for the permutation distribution, the observed t-statistic,
its p-value, based on both, the parametric and permutation
distributions as well as the observed F-ratio and its corresponding
p-values. The test may take a long time to generate all the possible
combinations. It has been tested for
and
.
The test may take a long time to generate all the possible combinations.
Ernesto Barrios
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
onet.permutation
and towt.permutation
of DAAG package, and perm.test
of the exactRankTests.
library(BHH2) # Permutation test for Tomato Data data(tomato.data) cat("Tomato Data (not paired):\n") attach(tomato.data) a <- pounds[fertilizer=="A"] b <- pounds[fertilizer=="B"] print(round(test <- permtest(b,a),3)) detach() # Permutation test for Boy's Shoes Example data(shoes.data) cat("Shoes Data (paired):\n") attach(shoes.data) x <- matB-matA print(round(test <- permtest(x),3)) detach()
library(BHH2) # Permutation test for Tomato Data data(tomato.data) cat("Tomato Data (not paired):\n") attach(tomato.data) a <- pounds[fertilizer=="A"] b <- pounds[fertilizer=="B"] print(round(test <- permtest(b,a),3)) detach() # Permutation test for Boy's Shoes Example data(shoes.data) cat("Shoes Data (paired):\n") attach(shoes.data) x <- matB-matA print(round(test <- permtest(x),3)) detach()
Poison data from Biological Experiment
data(poison.data)
data(poison.data)
This data frame contains the following columns:
factor with 3 levels: P1, P2 and P3.
factor with 4 levels: trA, trB, trC and trD.
numeric. Survival time as response.
Box, G. E. P. and D. R. Cox, An Analysis of Transformations (with discussion), Journal of the Royal Statistical Society, Series B, Vol. 26, No. 2, pp. 211–254.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
data(poison.data) str(poison.data) plot(poison.data)
data(poison.data) str(poison.data) plot(poison.data)
Data for the Boys' Shoes Example.
data(shoes.data)
data(shoes.data)
A data frame with 10 observations on the following 5 variables.
numeric. Boy number.
numeric. Amount of wear of shoe made from material A.
factor. Foot side which shoe of material A is used.
numeric. Amount of wear of shoe made from material B.
factor. Foot side which shoe of material B is used.
Box G. E. P, Hunter, W. C. and Hunter, J. S. (1978). Statistics for Experimenters. New York: Wiley.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
data(shoes.data) str(shoes.data) plot(shoes.data)
data(shoes.data) str(shoes.data) plot(shoes.data)
Generates all different subsets of size chosen from
different elements.
subsets(n, r, v = 1:n)
subsets(n, r, v = 1:n)
n |
numeric. Number of elements to choose from. |
r |
numeric. Size of the subsets. |
v |
vector. Numeric or character vector of size |
A matrix of dimension (), where
is
the total number of different combinations of
elements chosen
from
possible.
This particular version of the function was taken from a message from Bill Venables to ‘r-help’ list on Sun, 17 Dec 2000.
Bill Venables [email protected]
Venables, Bill. "Programmers Note", R-News, Vol 1/1, Jan. 2001. http://cran.r-project.org/doc/Rnews
combinations
of the gtools package.
library(BHH2) subsets(5,3) subsets(5,3,letters) subsets(5,3,c(10,20,30,50,80))
library(BHH2) subsets(5,3) subsets(5,3,letters) subsets(5,3,c(10,20,30,50,80))
Production record of 210 consecutive batch yield values
data(tab03B1)
data(tab03B1)
This data frame contains the following columns:
a numeric vector
a numeric vector. Moving average of last 10 observations. First 9 entries NA
The tab03B1
data frame has 210 rows and 2 columns.
Box G. E. P, Hunter, W. C. and Hunter, J. S. (1978). Statistics for Experimenters. New York: Wiley.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
library(BHH2) data(tab03B1) attach(tab03B1) stem(yield) stem(ave10) plot(yield,xlab="time order",ylab="yield") detach()
library(BHH2) data(tab03B1) attach(tab03B1) stem(yield) stem(ave10) plot(yield,xlab="time order",ylab="yield") detach()
Reference set of differences between averages of two adjacent sets of 10 successive batches.
data(tab03B2)
data(tab03B2)
This data frame contains the following columns:
a numeric vector
The tab03B2
data frame has 200 rows and 1 column.
First 9 entries are NA
.
Box G. E. P, Hunter, W. C. and Hunter, J. S. (1978). Statistics for Experimenters. New York: Wiley.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
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()
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()
Yield of tomato plants under two different fertilizers.
data(tomato.data)
data(tomato.data)
This data frame contains the following columns:
numeric. Row position
numeric. Plant's yield in pounds.
factor. Type of fertilizer (A or B).
Box G. E. P, Hunter, W. C. and Hunter, J. S. (1978). Statistics for Experimenters. New York: Wiley.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
data(tomato.data) str(tomato.data) plot(tomato.data)
data(tomato.data) str(tomato.data) plot(tomato.data)
Woolen thread experiment data set.
data(woolen.data)
data(woolen.data)
This data frame with 27 observations contains the following columns:
numeric. Length of test specimens factor.
numeric. Amplitude of loading cycle factor.
numeric. Load factor.
numeric. Cycles to failure response.
Box, G. E. P. and D. R. Cox (1964). "An Analysis of Transformations (with discussion)", Journal of the Royal Statistical Society, Series B, Vol. 26, No. 2, pp. 211–254.
Box G. E. P, Hunter, J. S. and Hunter, W. C. (2005). Statistics for Experimenters II. New York: Wiley.
data(woolen.data) str(woolen.data) plot(woolen.data)
data(woolen.data) str(woolen.data) plot(woolen.data)