#LM 03 ANCOVA SINGLE FACTOR #KNNL TABLE 22.1 setwd("c:/DATA/Models") K=read.table("CH22TA01.txt",header=TRUE) K attach(K) T=factor(treatment) plot(X,Y,pch=20) points(X[treatment==1],Y[treatment==1],pch=20,col="red") points(X[treatment==2],Y[treatment==2],pch=20,col="blue") points(X[treatment==3],Y[treatment==3],pch=20,col="green") library(nlme) LM=lmList(Y~X|T,data=K) plot(fitted(LM)) # GLM TEST OF TREATMENT EFFECT (INTERCEPT): FM=lm(Y~X+T) #FULL MODEL summary(FM) anova(FM) RM=lm(Y~X) #REDUCED MODEL summary(RM) anova(RM) n=length(Y) #number of objects in dataset c=4 #number of estimated parameters (3 classes of T + 1 for X) anova(FM,RM) #GLM TEST OF PARALLEL SLOPE: FMs=lm(Y~X*T) summary(FMs) anova(FMs) RMs=lm(Y~X+T) #same model as FM above but now used as the reduced model summary(RMs) anova(RMs) anova(FMs,RMs)