12.3 ANCOVA with two factors and one continuous covariate

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

names(Gain)

m1 <- lm(Weight~Sex*Age*Genotype)

summary(m1)


m2 <- step(m1)

summary(m2)


newGenotype <- Genotype

levels(newGenotype)

levels(newGenotype)[c(3,5)] <- "ClonesCandE"
levels(newGenotype)[c(2,4)] <- "ClonesBandD"

levels(newGenotype)


m3 <- lm(Weight~Sex+Age+newGenotype)

anova(m2,m3)

summary(m3)

plot(Age,Weight,type="n")
colours <- c("green","red","black","blue")

lines <- c(1,2)


symbols <- c(16,17)
points(Age,Weight,pch=symbols[as.numeric(Sex)],
col=colours[as.numeric(newGenotype)])
xv <- c(1,5)
for (i in 1:2) {
for (j in 1:4) {
a <- coef(m3)[1]+(i>1)* coef(m3)[2]+(j>1)*coef(m3)[j+2]
b <- coef(m3)[3]
yv <- a+b*xv
lines(xv,yv,lty=lines[i],col=colours[j]) } }




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