Last data update: 2014.03.03

R: Plot all main effects and twoway interactions in a...
interaction2wtR Documentation

Plot all main effects and twoway interactions in a multifactor design

Description

The main diagonal displays boxplots for the main effects of each factor. The off-diagonals show the interaction plots for each pair of factors. The i,j panel shows the same factors as the j,i but with the trace- and x-factor roles interchanged.

Usage

interaction2wt(x, ...)

## S3 method for class 'formula'
interaction2wt(x, data = sys.parent(), responselab, ...)

## Default S3 method:
interaction2wt(x,
               response.var,
               responselab = deparse(substitute(response.var)),
               responselab.expression = responselab,
               relation = list(x = "same", y = "same"),
               x.relation = relation$x,
               y.relation = relation$y,
               digits = 3,
               x.between=1,
               y.between=1,
               between,
               cex = 0.75,
               rot=c(0,0),
               panel.input = panel.interaction2wt,
               strip.input =
                if (label.as.interaction.formula) strip.default
                else strip.interaction2wt,
               par.strip.text.input = trellis.par.get()$add.text,
               scales.additional,
               main.in =
                 paste(responselab,
                       ": ", c("main", "simple")[1+simple],
                       " effects and 2-way interactions",
                       sep=""),
               xlab = "",
               ylab = "",
               simple=FALSE,
               box.ratio=if (simple) .32 else 1,
               label.as.interaction.formula=TRUE,
               ...,
               main.cex,
               key.cex.title=.8,
               key.cex.text=.7,
               factor.expressions=names.x,
               simple.pch=NULL
)

Arguments

Arguments when x is a formula.

x

The object on which method dispatch is carried out.

For the "formula" method, a formula describing the response variable and factors. The formula is generally of the form y ~ g1 + g2 + .... There may be one or more factors in the formula.

For the "default" method, data.frame of factors. This is usually constructed by formula method from the input data and the input formula.

data

For the formula method, a data frame containing values for any variables in the formula. In the R version, if not found in data, or if data is unspecified, the variables are looked for in the environment of the formula.

responselab

Character name of response variable, defaults to the name of the response variable in the formula.

responselab.expression

plotmath or character name of response variable, defaults to responselab.

...

additional arguments, primarily trellis arguments.

response.var

For the "default" method, the response variable. This is usually constructed by formula method from the input data and the input formula.

simple

logical. TRUE if simple effects are to be displayed. Arguments simple.offset, simple.scale, and col.by.row may also be needed. See panel.interaction2wt for details.

box.ratio

xyplot.

Trellis/Lattice arguments. Default values are set by the the formula method. The user may override the defaults. See also xyplot.

relation

trellis argument.

x.relation

x value of relation argument.

y.relation

y value of relation argument.

digits

doesn't do anything at the moment

x.between

x value of between argument.

y.between

y value of between argument.

between

trellis/lattice between argument. If used, between has precedence over both the x.between and y.between arguments.

cex

S-Plus: changes the size of the median dot in the boxplots. R: doesn't do anything.

panel.input

panel function. Default is panel.interaction2wt.

label.as.interaction.formula

logical. If TRUE, each panel has a single strip label of the form y ~ a | b. If FALSE, each panel has a pair of strip labels, one for the trace factor and one for the x factor.

strip.input

strip function. Default depends on the value of label.as.interaction.formula.

par.strip.text.input

par.strip.text argument.

scales.additional

additional arguments to scales argument of interaction.positioned.

main.in

Text of main title.

xlab

No effect.

ylab

No effect.

main.cex

cex for main title.

key.cex.title

cex key title. Defaults to cex for xlab.

key.cex.text

cex group names in key. Defaults to cex for axis.text.

factor.expressions

Expressions for titles of keys and xlab for each column. Defaults to the names of the factors in the input formula.

rot

Rotation of x tick labels and y tick labels. Only 0 and 90 will look good.

simple.pch

Named list containing plotting characters for each level of one or more of the factors. simple.pch is used only when simple==TRUE. If the argument simple.pch is missing, then the integers for the levels of the factors are used. The characters are used for the median of the box plots in the diagonal panels. They match the trace factor of the interaction panel in the same column of the display.

Value

"trellis" object containing the plot.

Author(s)

Richard M. Heiberger <rmh@temple.edu>

References

Heiberger, Richard M. and Holland, Burt (2015). Statistical Analysis and Data Display: An Intermediate Course with Examples in R, Second Edition. Springer Texts in Statistics. Springer. ISBN 978-1-4939-2121-8.

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.

See Also

panel.interaction2wt

Examples

data(vulcan)
interaction2wt(wear ~ filler + pretreat + raw, data=vulcan,
               par.strip.text=list(cex=.7))
interaction2wt(wear ~ filler + pretreat + raw, data=vulcan)
interaction2wt(wear ~ filler + raw, data=vulcan,
               simple=TRUE)
interaction2wt(wear ~ filler + raw, data=vulcan,
               simple=TRUE, simple.scale=c(filler=.15, raw=.2),
               xlim=c(.3, 5.6))

ToothGrowth$dose <- positioned(ToothGrowth$dose) ## modify local copy
anova(aov(len ~ supp*dose, data=ToothGrowth))
interaction2wt(len ~ supp + dose, data=ToothGrowth)


esoph$rate=with(esoph, ncases/ncontrols) ## modify local copy

position(esoph$alcgp) <- 2:5
position(esoph$tobgp) <- 2:5

interaction2wt(rate ~ agegp + alcgp + tobgp, esoph, rot=c(90,0),
                 par.strip.text=list(cex=.8))

interaction2wt(rate ~ agegp + alcgp + tobgp, esoph, rot=c(90,0),
               par.strip.text=list(cex=.8),
               factor.expressions=c(
                 agegp=expression(Age~~(years)),
                 alcgp=expression(Alcohol~
                   bgroup("(",scriptstyle(frac(gm, day)),")")),
                 tobgp=expression(Tobacco~
                   bgroup("(",scriptstyle(frac(gm, day)),")"))),
               par.settings=list(
                 par.xlab.text=list(cex=.8),
                 par.ylab.text=list(cex=.8)),
               responselab.expression="Cancer\nRate",
               main=list(
"Esophogeal Cancer Rate ~ Alcohol Consumption + Tobacco Consumption",
                 cex=1.2))

esoph.aov <- aov(rate ~ agegp + alcgp + tobgp, data=esoph)
anova(esoph.aov)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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 an HTML browser interface to help.
Type 'q()' to quit R.

> library(HH)
Loading required package: lattice
Loading required package: grid
Loading required package: latticeExtra
Loading required package: RColorBrewer
Loading required package: multcomp
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS

Attaching package: 'TH.data'

The following object is masked from 'package:MASS':

    geyser

Loading required package: gridExtra
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HH/interaction2wt.Rd_%03d_medium.png", width=480, height=480)
> ### Name: interaction2wt
> ### Title: Plot all main effects and twoway interactions in a multifactor
> ###   design
> ### Aliases: interaction2wt interaction2wt.formula interaction2wt.default
> ### Keywords: hplot design
> 
> ### ** Examples
> 
> data(vulcan)
> interaction2wt(wear ~ filler + pretreat + raw, data=vulcan,
+                par.strip.text=list(cex=.7))
> interaction2wt(wear ~ filler + pretreat + raw, data=vulcan)
> interaction2wt(wear ~ filler + raw, data=vulcan,
+                simple=TRUE)
> interaction2wt(wear ~ filler + raw, data=vulcan,
+                simple=TRUE, simple.scale=c(filler=.15, raw=.2),
+                xlim=c(.3, 5.6))
> 
> ToothGrowth$dose <- positioned(ToothGrowth$dose) ## modify local copy
> anova(aov(len ~ supp*dose, data=ToothGrowth))
Analysis of Variance Table

Response: len
          Df  Sum Sq Mean Sq F value    Pr(>F)    
supp       1  205.35  205.35  15.572 0.0002312 ***
dose       2 2426.43 1213.22  92.000 < 2.2e-16 ***
supp:dose  2  108.32   54.16   4.107 0.0218603 *  
Residuals 54  712.11   13.19                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> interaction2wt(len ~ supp + dose, data=ToothGrowth)
> 
> 
> esoph$rate=with(esoph, ncases/ncontrols) ## modify local copy
> 
> position(esoph$alcgp) <- 2:5
> position(esoph$tobgp) <- 2:5
> 
> interaction2wt(rate ~ agegp + alcgp + tobgp, esoph, rot=c(90,0),
+                  par.strip.text=list(cex=.8))
> 
> interaction2wt(rate ~ agegp + alcgp + tobgp, esoph, rot=c(90,0),
+                par.strip.text=list(cex=.8),
+                factor.expressions=c(
+                  agegp=expression(Age~~(years)),
+                  alcgp=expression(Alcohol~
+                    bgroup("(",scriptstyle(frac(gm, day)),")")),
+                  tobgp=expression(Tobacco~
+                    bgroup("(",scriptstyle(frac(gm, day)),")"))),
+                par.settings=list(
+                  par.xlab.text=list(cex=.8),
+                  par.ylab.text=list(cex=.8)),
+                responselab.expression="Cancer\nRate",
+                main=list(
+ "Esophogeal Cancer Rate ~ Alcohol Consumption + Tobacco Consumption",
+                  cex=1.2))
> 
> esoph.aov <- aov(rate ~ agegp + alcgp + tobgp, data=esoph)
> anova(esoph.aov)
Analysis of Variance Table

Response: rate
          Df Sum Sq Mean Sq F value    Pr(>F)    
agegp      5 3.5050 0.70100 14.0430 1.020e-09 ***
alcgp      3 3.4741 1.15804 23.1987 9.194e-11 ***
tobgp      3 0.3364 0.11214  2.2465   0.08969 .  
Residuals 76 3.7938 0.04992                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>