x <- sample(-10:10,200,replace=TRUE) y <- -2*x + 50 + rnorm(200,sd=5) # normal population of ys for each x plot(x,y) m0 <- lm(y~x) abline(m0) for (i in -10:10) { points(i,mean(y[x==i]),col='green')} pc <- predict(m0,newdata=data.frame(x=-10:10),interval='confidence') pp <- predict(m0,newdata=data.frame(x=-10:10),interval='prediction') lines(-10:10,pc[,2],col='red') lines(-10:10,pp[,2],col='blue') lines(-10:10,pc[,3],col='red') lines(-10:10,pp[,3],col='blue') Prostate <- read.table('http://math.uttyler.edu/nathan/classes/statistics/data/prostate.data',header=TRUE) attach(Prostate) names(Prostate) plot(Prostate) m1 <- lm(lpsa ~ .,data=Prostate) summary(m1) grandpa <- data.frame(lcavol=1, lweight=3, age=68, lbph=1.2, svi=0, lcp=.12, gleason=6,pgg45=282.35) men.like.grandpa <- data.frame(lcavol=1, lweight=3, age=68, lbph=1.2, svi=0, lcp=.12, gleason=6,pgg45=282.35) predict(m1,newdata=grandpa,interval='prediction') predict(m1,newdata=men.like.grandpa,interval='confidence')