#######################################################
# The rooting example:
# Calculate confidence intervals for the
# difference of proportions between the 3 doses of IBA,
# separately for 4 combinations of "Age" and "Position".
# Note: we pool over Rep in that way. Whether this makes
# sense or not, is decision of the user.
data(rooting)
# Pairwise Chi-square tests:
aproots<-pairwiseTest(cbind(root, noroot) ~ IBA,
data=rooting, by=c("Age", "Position"), method="Prop.test")
aproots
# With Holm adjustment for multiple hypotheses testing:
summary(aproots, p.adjust.method="holm")
#########################################################
data(Oats)
apc <- pairwiseTest(yield ~ nitro, data=Oats,
by="Variety", method="wilcox.test")
apc
summary(apc)
summary(apc, p.adjust.method="holm")
# # many to one comparisons, with variety Marvellous as control,
# for each level of nitro separately:
m21 <- pairwiseTest(yield ~ Variety, data=Oats,
by="nitro", method="perm.test", control="Marvellous")
m21
############################################################
set.seed(1234)
resp<-rnorm(n=100,
mean=rep(c(2,5,5,5,5,10,18,5,5,5),each=10),
sd=rep(c(1,2,2,2,3,5,5,2,2,2), each=10)
)
noise<-rbinom(n=100, size=1, prob=0.05)
resp<-resp + noise*rnorm(n=100,mean=10, sd=10)
fact<-as.factor(rep(LETTERS[1:10], each=10))
data<-data.frame(resp=resp, fact=fact)
boxplot(resp~fact)
# All pairwise comparisons using Welch-tests
aptestW<-pairwiseTest(resp~fact, data=data, method="t.test",
var.equal=FALSE)
aptestW
summary(aptestW, p.adjust.method="holm", letters=TRUE)
# All pairwise comparisons using Wilcoxon tests
aptestWi<-pairwiseTest(resp~fact, data=data, method="wilcox.test")
aptestWi
summary(aptestWi, p.adjust.method="holm", letters=TRUE)
# All pairwise comparisons using Permutation tests
# from library exactRankTests
aptestP<-pairwiseTest(resp~fact, data=data, method="perm.test")
aptestP
summary(aptestP, p.adjust.method="holm", letters=TRUE)
#####################################
# Petersens bean example:
data(bean)
boxplot(yield ~ P*T, data=bean)
bean$trt<-paste(bean$P, bean$T, sep="")
bean
# There might be interaction AND heterogeneity of variances.
# There are definitely smarter ways to analyze these data.
# But a simple-minded way is:
pairwiseTest(yield~trt,data=bean, method="var.test")
# or
# Might there be different variances between the
# comparisons of interest?
pairwiseTest(yield~P,data=bean, by="T", control="P0",
method="var.test")
# Which Phosphor doses lead to increase of yield
# compared to P0, separate for the two types?
compP<-pairwiseTest(yield~P,data=bean, by="T",
control="P0", method="t.test", var.equal=FALSE,
alternative="greater")
# P-values adjusted according to Holm:
summary(compP, p.adjust.method="holm")
# confidence intervals for the same problem,
# using Bonferroni-adjustment:
CIcompP<-pairwiseCI(yield~P, data=bean, by="T",
control="P0", method="Param.diff", var.equal=FALSE,
alternative="greater", conf.level=1-0.05/4)
plot(CIcompP)Run the code above in your browser using DataLab