data=read.table("softdrink.txt") y=data[,1] x=data[,2] fit=lm(y~x) fit2=lm(y~x,data=data) summary(fit) summary(fit2) anova(fit) MSE=17.4976 # Scatter plot plot(x,y,pch="*",xlab="no. of cases", ylab="waiting time") abline(fit) # Residual plots par(mfrow=c(2,2)) e=fit$residuals hist(e,prob=T,col=2,xlab="residuals",ylab=" ") plot(fit$fitted.values,e,pch="*") qqnorm(e) qqline(e) ts.plot(e,xlab="index") # res=lm.influence(fit) res$hat # these are the hi's # standardized residuals et= e/sqrt(MSE*(1-res$hat)) par(mfrow=c(2,2)) hist(et,prob=T,col=2,xlab="residuals",ylab=" ") plot(fit$fitted.values,et,pch="*") qqnorm(et) qqline(et) ts.plot(et,xlab="index") # predict.lm(fit,new=data.frame(x=12),level=0.95,interval="prediction") predict.lm(fit,new=data.frame(x=12),level=0.95,interval="confidence")