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="prediction") # compare two intervals new2 <- data.frame(LOGMPH = seq(2.5, 4, 0.1)) conf<-predict(model,new2,interval="confidence") pred<-predict(model,new2,interval="prediction") plot(LOGMPH,MPG) abline(model2) lines(new2$LOGMPH,conf[,2],lty="dashed",col="red" ) lines(new2$LOGMPH,conf[,3],lty="dashed",col="red" ) lines(new2$LOGMPH,pred[,2],lty="dashed",col="blue" ) lines(new2$LOGMPH,pred[,3],lty="dashed",col="blue" ) # correlation test cor.test(LOGMPH,MPG)...
View Full Document

This note was uploaded on 09/11/2011 for the course STAT 200 taught by Professor Agniel during the Spring '09 term at University of Illinois at Urbana–Champaign.

Ask a homework question - tutors are online