Analysis of Covariance

regrowth <- read.table("c:\\temp\\ipomopsis.txt",header=T)
attach(regrowth)

names(regrowth)


plot(Root,Fruit,pch=16,col=c("blue","red")[as.numeric(Grazing)])


levels(Grazing)


abline(lm(Fruit[Grazing=="Grazed"]~Root[Grazing=="Grazed"]),col="blue")

abline(lm(Fruit[Grazing=="Ungrazed"]~Root[Grazing=="Ungrazed"]),col="red")


tapply(Fruit,Grazing, mean)


t.test(Fruit~Grazing)

sum(Root);sum(Rootˆ2)

sum(Fruit);sum(Fruitˆ2)

sum(Root*Fruit)

sum(Root[Grazing=="Grazed"]);sum(Root[Grazing=="Grazed"]ˆ2)

sum(Root[Grazing=="Ungrazed"]);sum(Root[Grazing=="Ungrazed"]ˆ2)

sum(Fruit[Grazing=="Grazed"]);sum(Fruit[Grazing=="Grazed"]ˆ2)

sum(Fruit[Grazing=="Ungrazed"]);sum(Fruit[Grazing=="Ungrazed"]ˆ2)

sum(Root[Grazing=="Grazed"]*Fruit[Grazing=="Grazed"])

sum(Root[Grazing=="Ungrazed"]*Fruit[Grazing=="Ungrazed"])

ancova <- lm(Fruit~Grazing*Root)

summary(ancova)

anova(ancova)

ancova2 <- update(ancova, ~ . - Grazing:Root)

anova(ancova,ancova2)


ancova3 <- update(ancova2, ~ . - Grazing)

anova(ancova2,ancova3)


summary(ancova2)

anova(ancova2)


你可能感兴趣的:(Michael,J.,Crawley,Analysis,of,Covariance)