# For the general linear test approach # by Yu-Ling Tseng on 20090430 ch6pr18 <- matrix(scan("ch06pr18.txt"),ncol=5, byrow=T) ; # y <- ch6pr18[,1]; # x1 <- ch6pr18[,2]; # x2 <- ch6pr18[,3]; # x3 <- ch6pr18[,4]; # x4 <- ch6pr18[,5]; dum <- data.frame(ch6pr18) names(dum) <- c("Rates","Age","OET","VR","TSF") # dum <- data.frame("Rates"=y,"Age"=x1,"OET"=x2,"VR"=x3,"TSF"=x4) attach(dum) fm1234 <- lm(Rates~Age+OET+VR+TSF, dum) SSE1234<-sum((Rates-fitted(fm1234))^2) SSE1234 anova(fm1234) # Ex 1 fm12 <- lm(Rates~Age+OET, dum) # reduced model has only two predictors X1, X2 SSE12<-sum((Rates-fitted(fm12))^2) SSE12 anova(fm12) F34 <- ((SSE12-SSE1234)/2)/(SSE1234/76) # F stat for testing H0: beta3=0 and beta4=0 F34 qf(.95,2,76) # level of the test = 0.05 # Ex 2 fm3 <- lm(Rates~VR, dum) # reduced model has only one predictor X3 SSE3<-sum((Rates-fitted(fm3))^2) SSE3 anova(fm3) F124 <- ((SSE3-SSE1234)/3)/(SSE1234/76) # F stat fpr testing H0: beta1=beta2=beta4=0 F124 qf(.95,3,76) # Ex 3 fm124 <- lm(Rates~Age+OET+TSF, dum) # reduced model has three predictors X1 2 4 SSE124<-sum((Rates-fitted(fm124))^2) SSE124 anova(fm124) F3 <- ((SSE124-SSE1234)/1)/(SSE1234/76) # F stat fpr testing H0: beta3=0 F3 qf(.95,1,76) # If so...... As usual, before you leave R ...... # detach() rm(list=ls())