storks=read.table("storks.txt",header=T) attach(storks) plot(storks$storks,people,xlab="storks") storks.lm=lm(people~storks$storks) lines(storks$storks,fitted(storks.lm)) # add fitted line to scatterplot summary(storks.lm) anova(storks.lm) plot(fitted(storks.lm),resid(storks.lm)) # check assumptions qqnorm(resid(storks.lm)) oring=read.table("o-ring.txt") # problem 13.70 on p. 540 of text oring names(oring)=c("flight","temp","damage") attach(oring) plot(temp[damage>0],damage[damage>0]) # plot of damaged o-rings vs. temp # does there look like a relationship between temperature and damage? plot(temp,damage) # plot of all data # does this plot look different? # how do you feel about predicting for a temp of 31? oring.lm=lm(damage~temp) summary(oring.lm) # predicted damage for temp of 31: coef(oring.lm) coef(oring.lm)[1] + coef(oring.lm)[2]*31 # should we launch? lines(temp,fitted(oring.lm)) # does a linear fit look reasonable? plot(fitted(oring.lm),resid(oring.lm)) qqnorm(resid(oring.lm)) olymp=read.table("olympics.txt",header=T) pairs(olymp) attach(olymp) plot(year,long.jump) long.lm=lm(long.jump~year) lines(year,fitted(long.lm)) summary(long.lm) anova(long.lm) plot(fitted(long.lm),resid(long.lm)) plot(year,resid(long.lm)) # plot looks the same plot(long.jump,resid(long.lm)) # bad plot qqnorm(resid(long.lm)) fitted(long.lm) # fitted values hat(year) # diagonal of the hat matrix # next is a prediction interval, by hand, predicting for 1984 (20th datapoint) fitted(long.lm)[20]-qt(.975,18)*11.59*sqrt(1+hat(year)[20]) fitted(long.lm)[20]+qt(.975,18)*11.59*sqrt(1+hat(year)[20]) predict(long.lm,data.frame(year=84),interval="predict") # easier method