slrR - # prediction interval for a future observation

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 # Simple Linear Regression example - fuel efficiency(example 10.1) # read data gas<-read.table("eg10_001.txt",head=T) names(gas) attach(gas) # draw scatterplot plot(MPH,MPG) abline(lm(MPG~MPH)) # log-transform MPH plot(LOGMPH,MPG) model<-lm(MPG~LOGMPH) abline(model) summary(model) anova(model) # check the model: residual plot resid = residuals(model) x11() # This command will open a new window for a graph plot(LOGMPH,resid,xlab="LOGMPH",ylab="residuals") abline(h=0) x11() qqnorm(resid) # confidence interval for a mean response new<-data.frame(LOGMPH=3) predict(model,new,interval="confidence")
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # prediction interval for a future observation predict(model,new,interval=&quot;prediction&quot;) # compare two intervals new2 &lt;- data.frame(LOGMPH = seq(2.5, 4, 0.1)) conf&lt;-predict(model,new2,interval=&quot;confidence&quot;) pred&lt;-predict(model,new2,interval=&quot;prediction&quot;) plot(LOGMPH,MPG) abline(model2) lines(new2$LOGMPH,conf[,2],lty=&quot;dashed&quot;,col=&quot;red&quot; ) lines(new2$LOGMPH,conf[,3],lty=&quot;dashed&quot;,col=&quot;red&quot; ) lines(new2$LOGMPH,pred[,2],lty=&quot;dashed&quot;,col=&quot;blue&quot; ) lines(new2$LOGMPH,pred[,3],lty=&quot;dashed&quot;,col=&quot;blue&quot; ) # correlation test cor.test(LOGMPH,MPG)...
View Full Document

Ask a homework question - tutors are online