data.source<-"http://www.math.mcgill.ca/dstephens/Regression/Data/2-1-RocketProp.csv" RocketProp<-read.csv(file=data.source) names(RocketProp)<-c('i','Strength','Age') x<-RocketProp$Age y<-RocketProp$Strength ############################################ #Fit the simple linear regression using lm fit.RP<-lm(y~x) RP.resids<-residuals(fit.RP) RP.fitted<-fitted(fit.RP) #Sum of residuals sum(RP.resids) #Sum of x times residuals sum(x*RP.resids) t(x) %*% RP.resids #Sum of fitted values times residuals sum(RP.fitted*RP.resids) t(RP.fitted) %*% RP.resids #Sum of y values times residuals sum(y*RP.resids) t(y) %*% RP.resids ##Non-zero !! #par(mfrow=c(2,1)) plot(x,RP.resids,xlab='x',ylab='Residuals',pch=19,ylim=range(-250,250));abline(h=0,lty=2) title('Residuals vs X (Age)') plot(RP.fitted,RP.resids,xlab=expression(hat(y)),ylab='Residuals', pch=19,ylim=range(-250,250));abline(h=0,lty=2) title('Residuals vs Fitted values') #dev.copy2pdf(file='RocketProp-Resids.pdf',width=9,height=11)