##one-way ANOVA example
data(turkey)
##convert diet to factor
turkey$Diet <- as.factor(turkey$Diet)
##run one-way ANOVA
m.aov <- lm(Weight.gain ~ Diet, data = turkey)
##compute models with different grouping patterns
##and also compute model-averaged group means
out <- multComp(m.aov, factor.id = "Diet", correction = "none")
##look at results
out
##look at grouping structure of a given model
##and compare with original variable
cbind(model.frame(out$models[[2]]), turkey$Diet)
##evidence ratio
evidence(out$model.table)
##compute Bonferroni-adjusted confidence intervals
multComp(m.aov, factor.id = "Diet", correction = "bonferroni")
##two-way ANOVA with interaction
if (FALSE) {
data(calcium)
m.aov2 <- lm(Calcium ~ Hormone + Sex + Hormone:Sex, data = calcium)
##multiple comparisons
multComp(m.aov2, factor.id = "Hormone")
##returns an error because 'Hormone' factor is
##involved in an interaction
##create interaction variable
calcium$inter <- interaction(calcium$Hormone, calcium$Sex)
##run model with interaction
m.aov.inter <- lm(Calcium ~ inter, data = calcium)
##compare both
logLik(m.aov2)
logLik(m.aov.inter)
##both are identical
##multiple comparisons
multComp(m.aov.inter, factor.id = "inter")
}
##Poisson regression
if (FALSE) {
##example from ?glm
##Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
print(d.AD <- data.frame(treatment, outcome, counts))
glm.D93 <- glm(counts ~ outcome + treatment, data = d.AD, family = poisson)
multComp(mod = glm.D93, factor.id = "outcome")
}
##example specifying 'newdata'
if (FALSE) {
data(dry.frog)
m1 <- lm(log_Mass_lost ~ Shade + Substrate +
cent_Initial_mass + Initial_mass2,
data = dry.frog)
multComp(m1, factor.id = "Substrate",
newdata = data.frame(
Substrate = c("PEAT", "SOIL", "SPHAGNUM"),
Shade = 0, cent_Initial_mass = 0,
Initial_mass2 = 0))
}
Run the code above in your browser using DataLab