mmc {HH} | R Documentation |
Constructs a "mmc.multicomp"
object from the formula and
other arguments. The object must be explicitly plotted.
glht.mmc(model, ...) ## R ## S3 method for class 'glht': glht.mmc(model, ...) ## S3 method for class 'lm': glht.mmc(model, ## lm object linfct=NULL, focus= if (is.null(linfct)) { if (length(model$contrasts)==1) names(model$contrasts) else stop("focus or linfct must be specified.") } else { if (is.null(names(linfct))) stop("focus must be specified.") else names(linfct) }, ylabel=as.character(terms(model)[[2]]), lmat=t(linfct), lmat.rows=-1, lmat.scale.abs2=TRUE, estimate.sign=1, order.contrasts=TRUE, level=.95, calpha=NULL, alternative = c("two.sided", "less", "greater"), ... ) multicomp.mmc(..., comparisons="mca", ## S-Plus lmat, lmat.rows=-1, lmat.scale.abs2=TRUE, ry, plot=TRUE, crit.point, iso.name=TRUE, estimate.sign=1, x.offset=0, order.contrasts=TRUE, main, main2) ## S3 method for class 'mmc.multicomp': x[..., drop = TRUE]
model |
"aov" object in "lm" method. |
ylabel |
name of the response variable. |
lmat |
contrast matrix as in the S-Plus multicomp .
The convention for lmat in R is to use
the transpose of the linfct component produced by
glht . Required for user-specified contrasts. |
lmat.rows |
rows in lmat for the focus factor. |
focus |
define the factor to compute contrasts of.
See mcp in R. |
linfct |
In R, see glht . |
... |
other arguments. alternative and
base are frequently used with glht . |
comparisons |
argument to multicomp |
lmat.scale.abs2 |
logical, scale the contrasts in the columns of
lmat to make the sum of the absolute values of each column equal 2. |
estimate.sign |
numeric. If 0 , leave contrasts in the
default lexicographic direction. If positive, force all contrasts to positive,
reversing their names if needed (if contrast A-B is negative, reverse it
to B-A). If negative, the force all contrasts to positive. |
order.contrasts |
sort the contrasts in the (mca , none ,
lmat ) components by height on the MMC plot. This will place the
contrasts in the multicomp plots in the same order as in the MMC plot. |
alternative |
Direction of alternative hypothesis.
See confint in R. S-Plus multicomp
uses the argument bounds for this concept.
|
level |
Confidence level. Defaults to 0.95. |
crit.point, calpha |
critical value for the tests. The value from the
specified multicomp method is used for the user-specified
contrasts when lmat is specified. This argument is called
crit.point with multicomp in S-Plus and calpha
when used with glht and confint in R.
In R, with a large number of levels for the focus factor, calpha
should
be specified. See notes below for discussion of the timing issues
and the examples for an illustration how to use calpha . |
plot |
logical, display the plot if TRUE . |
ry, iso.name, x.offset, main, main2 |
arguments to
plot.mmc.multicomp . |
x, drop |
See "[" . |
By default, if lmat
is not specified, we plot the isomeans grid
and the pairwise comparisons for the focus
factor. By default,
we plot the specified contrasts if the lmat
is specified.
We get the right contrasts automatically if the aov is oneway. If we specify an lmat for oneway it must have a leading row of 0.
For any more complex design, we must study the lmat
from the mca
component of the result to see how to construct the lmat
(with the
extra rows as needed) and how to specify the lmat.rows
corresponding to the rows for the focus factor.
glht.mmc
in R works from either an "glht"
object or an
"aov"
object. multicomp.mmc
in S-Plus works from an
"aov"
object.
An "mmc.multicomp"
object contains either the first two or all
three of the "multicomp"
components
mca |
|
none |
|
lmat |
|
mca |
Object containing the pairwise comparisons. |
none |
Object comparing each mean to 0. |
lmat |
Object for the contrasts specified in
the lmat argument. |
"[.mmc.multicomp"
is a subscript method.
The multiple comparisons calculations in R and S-Plus use
completely different functions.
MMC plots in R are constructed by glht.mmc
based on glht
.
MMC plots in S-Plus are constructed by
multicomp.mmc
based on the S-Plus multicomp
.
The MMC plot is the same in both systems. The details of getting the
plot differ.
Function glht.mmc
calls glht
and
confint.glht
. With a large number of levels
for the focus factor, the confint
function is exceedingly slow
(80 minutes for 30 levels on 1.5GHz Windows XP). Therefore,
always specify calpha
to reduce the time to under a second for
the same example.
plot.mmc.multicomp
chooses sensible defaults for its many
arguments. They will often need manual adjustment. The examples show
several types of adjustments. We have changed the centering and scaling
to avoid overprinting of label information. By default the significant
contrasts are shown in a more intense color than the nonsignificant
contrasts.
We have an option to reduce the color intensity of the isomeans grid.
Richard M. Heiberger <rmh@temple.edu>
Heiberger, Richard M. and Holland, Burt (2004b). Statistical Analysis and Data Display: An Intermediate Course with Examples in S-Plus, R, and SAS. Springer Texts in Statistics. Springer. ISBN 0-387-40270-5.
Heiberger, R.~M. and Holland, B. (2006). "Mean–mean multiple comparison displays for families of linear contrasts." Journal of Computational and Graphical Statistics, 15:937–955.
Hsu, J. and Peruggia, M. (1994). "Graphical representations of {Tukey's} multiple comparison method." Journal of Computational and Graphical Statistics, 3:143–161.
as.multicomp
, plot.mmc.multicomp
## Use glht.mmc with R. ## Use multicomp.mmc with S-Plus. ## data and ANOVA catalystm <- read.table(hh("datasets/catalystm.dat"), header=FALSE, col.names=c("catalyst","concent")) catalystm$catalyst <- factor(catalystm$catalyst, labels=c("A","B","C","D")) if.R(r= bwplot(concent ~ catalyst, data=catalystm, scales=list(cex=1.5), ylab=list("concentration", cex=1.5), xlab=list("catalyst",cex=1.5)) ,s= t(bwplot(catalyst ~ concent, data=catalystm, scales=list(cex=1.5), xlab=list("concentration", cex=1.5), ylab=list("catalyst",cex=1.5))) ) catalystm1.aov <- aov(concent ~ catalyst, data=catalystm) summary(catalystm1.aov) catalystm.mca <- if.R(r=glht(catalystm1.aov, linfct = mcp(catalyst = "Tukey")), s=multicomp(catalystm1.aov, plot=FALSE)) plot(catalystm.mca) ## S-Plus always and R for small number of levels if.R(s={}, r=plot(confint(catalystm.mca, calpha=qtukey(.95, 4, 12)/sqrt(2)))) ## R for large number of levels catalystm.mca ## pairwise comparisons catalystm.mmc <- if.R(r=glht.mmc(catalystm1.aov, linfct = mcp(catalyst = "Tukey")), s=multicomp.mmc(catalystm1.aov, plot=FALSE)) catalystm.mmc plot(catalystm.mmc) plot(catalystm.mmc$mca) plot(catalystm.mmc$none) if.R(s={}, r={## R for large number of levels plot(confint(catalystm.mmc$mca$glht, calpha=catalystm.mmc$mca$crit.point)) plot(confint(catalystm.mmc$none$glht, calpha=catalystm.mmc$none$crit.point)) } ) ## user-specified contrasts catalystm.lmat <- cbind("AB-D" =c(0, 1, 1, 0,-2), "A-B" =c(0, 1,-1, 0, 0), "ABD-C"=c(0, 1, 1,-3, 1)) if.R(r=catalystm.lmat <- catalystm.lmat[-2,], s={}) dimnames(catalystm.lmat)[[1]] <- dimnames(catalystm.mmc$mca$lmat)[[1]] zapsmall(catalystm.lmat) if.R(s=dimnames(catalystm.mca$lmat)[[1]], r=dimnames(catalystm.mca$linfct)[[2]]) catalystm.mmc <- if.R(r=glht.mmc(catalystm1.aov, linfct = mcp(catalyst = "Tukey"), lmat=catalystm.lmat) ,s=multicomp.mmc(catalystm1.aov, lmat=catalystm.lmat, plot=FALSE) ) catalystm.mmc plot(catalystm.mmc) plot(catalystm.mmc$mca) plot(catalystm.mmc$none) plot(catalystm.mmc$lmat) ## Dunnett's test weightloss <- read.table(hh("datasets/weightloss.dat"), header=TRUE) weightloss <- data.frame(loss=unlist(weightloss), group=rep(names(weightloss), rep(10,5))) if.R(r= bwplot(loss ~ group, data=weightloss, scales=list(cex=1.5), ylab=list("Weight Loss", cex=1.5), xlab=list("group",cex=1.5)) ,s= t(bwplot(group ~ loss, data=weightloss, scales=list(cex=1.5), xlab=list("Weight Loss", cex=1.5), ylab=list("group",cex=1.5))) ) weightloss.aov <- aov(loss ~ group, data=weightloss) summary(weightloss.aov) if.R(r={ group.count <- table(weightloss$group) },s={}) tmp.dunnett <- if.R(r= glht(weightloss.aov, linfct=mcp(group=contrMat(group.count, base=4)), alternative="greater") ,s= multicomp(weightloss.aov, method="dunnett", comparisons="mcc", bounds="lower", control=4, valid.check=FALSE) ) plot(tmp.dunnett) tmp.dunnett.mmc <- if.R(r= glht.mmc(weightloss.aov, linfct=mcp(group=contrMat(group.count, base=4)), alternative="greater") ,s= multicomp.mmc(weightloss.aov, method="dunnett", comparisons="mcc", bounds="lower", control=4, valid.check=FALSE, plot=FALSE) ) tmp.dunnett.mmc plot(tmp.dunnett.mmc) ## two-way ANOVA display <- read.table(hh("datasets/display.dat"), header=TRUE) display$panel <- factor(display$panel) ## display$panel <- positioned(display$panel, value=(1:3)+.5) display$emergenc <- factor(display$emergenc) displayf.aov <- aov(time ~ emergenc * panel, data=display) anova(displayf.aov) ## multiple comparisons tmp <- if.R( r=glht(displayf.aov, linfct=mcp(panel="Tukey")), s=multicomp(displayf.aov, "panel", plot=FALSE)) zapsmall( if.R(r=t(tmp$linfct), s=tmp$lmat) ) ## MMC plot displayf.mmc <- if.R(r=glht.mmc(displayf.aov, linfct=mcp(panel="Tukey"), focus="panel", lmat.rows=5:6), s=multicomp.mmc(displayf.aov, "panel", lmat.rows=6:8, plot=FALSE)) plot(displayf.mmc) ## orthogonal contrasts zapsmall(mca.lmat <- displayf.mmc$mca$lmat) panel.lmat <- cbind("3-12"=mca.lmat[,1] + mca.lmat[,2], "1-2"=mca.lmat[,3]) displayf.mmc <- if.R(r=glht.mmc(displayf.aov, linfct=mcp(panel="Tukey"), focus="panel", lmat.rows=5:6, lmat=panel.lmat), s=multicomp.mmc(displayf.aov, "panel", lmat.rows=6:8, lmat=panel.lmat, plot=FALSE)) plot(displayf.mmc) ## split plot design with tiebreaker plot ## ## This example is based on the query by Tomas Goicoa to R-news ## http://article.gmane.org/gmane.comp.lang.r.general/76275/match=goicoa ## It is a split plot similar to the one in HH Section 14.2 based on ## Yates 1937 example. I am using the Goicoa example here because its ## MMC plot requires a tiebreaker plot. maiz <- read.table(hh("datasets/maiz.dat"), header=TRUE) maiz$hibrido <- factor(maiz$hibrido, levels=c("P3747","P3732","Mol17","A632","LH74")) maiz$nitrogeno <- factor(maiz$nitrogeno) position(maiz$nitrogeno) <- c(1, 2.5, 4, 5.5) ## forces class="ordered" interaction2wt(yield ~ hibrido+nitrogeno+bloque, data=maiz) interaction2wt(yield ~ hibrido+nitrogeno, data=maiz) maiz.aov <- aov(yield ~ nitrogeno*hibrido + Error(bloque/nitrogeno), data=maiz) summary(maiz.aov) summary(maiz.aov, split=list(hibrido=list(P3732=1, Mol17=2, A632=3, LH74=4))) ## multicomp(maiz.aov, focus="hibrido") ## can't use 'aovlist' objects ## glht(maiz.aov, linfct=mcp(hibrido="Tukey")) ## can't use 'aovlist' objects sapply(maiz[-1], contrasts) if.R(r={ ## R glht.mmc requires treatment contrasts contrasts(maiz$nitrogeno) <- "contr.treatment" sapply(maiz[-1], contrasts) }, s={}) ## Both R and S-Plus require aov, not aovlist maiz2.aov <- aov(terms(yield ~ bloque*nitrogeno + hibrido/nitrogeno, keep.order=TRUE), data=maiz) summary(maiz2.aov) if.R(s={ maiz2.mca <- multicomp(maiz2.aov, focus="hibrido") ## plot(maiz2.mca) dimnames(maiz2.mca$lmat)[[1]] maiz2.mmc <- multicomp.mmc(maiz2.aov, focus="hibrido", lmat.rows=16:20, plot=FALSE) old.mar <- par(mar=c(15,4,4,7)+.1) plot(maiz2.mmc) par(mar=c(2,4,28,7)+.1, new=TRUE) old.cex <- par(cex=.8) plot(maiz2.mmc$mca, col.signif=8, lty.signif=1, xlabel.print=FALSE, xaxs="d", plt=par()$plt+c(0,0,-.25,.05), xrange.include=c(-30,40)) par(old.cex) par(old.mar) },r={ maiz2.mca <- glht(maiz2.aov, linfct=mcp(hibrido="Tukey")) dimnames(maiz2.mca$linfct)[[2]] maiz2.mmc <- glht.mmc(maiz2.aov, linfct=mcp(hibrido="Tukey"), lmat.rows=9:12) old.oma <- par(oma=c(12,3,0,4)) plot(maiz2.mmc) par(oma=c(0,3,22,4), new=TRUE) plot(maiz2.mmc$mca, xlim=par()$usr[1:2], xaxs="i", main="", xlab="", cex.axis=.7) par(old.oma) })