Learn R Programming

asbio (version 1.9-7)

pairw.anova: Conducts pairwise post hoc and planned comparisons associated with an ANOVA

Description

The function pairw.anova replaces the defunct Pairw.test. Conducts all possible pairwise tests with adjustments to P-values using one of five methods: Least Significant difference (LSD), Bonferroni, Tukey-Kramer honest significantly difference (HSD), Scheffe's method, or Dunnett's method. Dunnett's method requires specification of a control group, and does not return adjusted P-values. The functions scheffe.cont and bonf.cont allow Bonferroni and Scheffe's family-wise adjustment of individual planned pairwise contrasts.

Usage

pairw.anova(y, x, conf.level = 0.95, method = "tukey", 
MSE = NULL, df.err = NULL, control = NULL)

lsdCI(y, x, conf.level = 0.95, MSE = NULL, df.err = NULL)

bonfCI(y, x, conf.level = 0.95, MSE = NULL, df.err = NULL)

tukeyCI(y, x, conf.level = 0.95, MSE = NULL, df.err = NULL)

scheffeCI(y, x, conf.level = 0.95, MSE = NULL, df.err = NULL)

dunnettCI(y, x, conf.level = 0.95, control = NULL)

scheffe.cont(y, x, lvl = c("x1", "x2"), conf.level = 0.95, MSE = NULL, df.err = NULL)

bonf.cont(y, x, lvl = c("x1", "x2"), conf.level = 0.95, MSE = NULL, df.err = NULL, comps = 1)

Value

The function pairw.anova and the confidence interval functions it calls return a list of class = "pairw". For all but the LSD test (which also returns LSD) and Dunnett's test (which does not return adjusted P-values), the utility function print.pairw returns a descriptive head and a six column summary dataframe containing:

1) the type of contrast (names are taken from levels in x),

2) the mean difference,

3) the lower confidence bound of the true mean difference,

4) the upper confidence bound of the true mean difference,

5) the hypothesis decision, given the prescribed significance level, and

6) the adjusted P-value.

Other invisible objects include:

cont

a vector of contrasts.

conf

The confidence level.

band

A two column matrix containing the lower and upper confidence bounds.

The pairw class also has a utility function plot.pairw which provides either a barplot of location measures with errors and letters indicating whether true effects are significant and the defined significance level (argument type = 1) or confidence intervals for the true difference of each comparison (argument type = 2). See code below and and plot.pairw for examples.

Arguments

y

A quantitative vector containing the response variable

x

A categorical vector containing the groups (e.g. factor levels or treatments)

conf.level

1 - P(type I error)

method

One of five possible choices: "lsd", "bonf", "tukey", "scheffe", "dunnett"

MSE

Value of MSE from the ANOVA model. Default = NULL

df.err

Degrees of freedom error from the omnibus ANOVA. Default = NULL

control

Control group for Dunnett's test.

lvl

A two element vector defining two factor levels to be compared using Scheffe's and the Bonferroni method.

comps

The number of comparisons to be made in the Bonferroni method.

Author

Ken Aho

Details

Adjustment of comparison type I error for simultaneous inference is a contentious subject and will not be discussed here. For description of methods go to Kutner et al. (2005). For models where the number of factors is \(\ge 2\), MSE and the residual degrees of freedom (used in the computation of confidence intervals for all pairwise methods used here) will vary depending on the experimental design and the number of factors. Thus, for multifactor designs the user should specify the residual degrees of freedom and MSE from the overall ANOVA. This will be unnecessary for one-way ANOVAs.

References

Kutner, M. H., Nachtsheim, C. J., Neter, J., and Li., W (2005) Applied Linear Statistical Models, 5th edition. McGraw-Hill, Boston.

See Also

plot.pairw. Functions from library mult.comp provide more sophisticated comparisons including customized contrasts and one tailed tests.

Examples

Run this code
eggs<-c(11,17,16,14,15,12,10,15,19,11,23,20,18,17,27,33,22,26,28)
trt<-as.factor(c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,4,4))

pairw.anova(y = eggs, x = trt, method = "lsd")##LSD method
pairw.anova(y = eggs, x = trt, method = "bonf")##Bonferroni
pairw.anova(y = eggs, x = trt, method = "scheffe")##Sheffe
tukey <- pairw.anova(y = eggs, x = trt, method = "tukey")##Tukey HSD

plot(tukey)
# you can also try plot(tukey, type = 2)

blood.count <- data.frame(bc=c(7.4,8.5,7.2,8.24,9.84,8.32,9.76,8.8,
7.68,9.36,12.8,9.68,12.16,9.2,10.55), trt=c(rep("C",6),rep("A",4),rep("B",5)))
with(blood.count,pairw.anova(y=bc,x=trt,control="C",method="dunnett"))## Dunnett

scheffe.cont(y = eggs, x = trt, lvl = c(1, 3)) 
scheffe.cont(y = eggs, x = trt, lvl = c(1,2))

bonf.cont(y = eggs, x = trt, lvl = c(1,3), comps = 2) 
bonf.cont(y = eggs, x=trt, lvl = c(1,2), comps = 2) 

Run the code above in your browser using DataLab