rivers<-read.table("Rivers.txt",header=T) attach(rivers) ?plot.lm plot(Agr,Nitrogen,col="blue",lwd=3) agr.lm=lm(Nitrogen~Agr); plot(agr.lm,which=3)# fitted versus std. res. plot(agr.lm,which=2) # qqnorm of std res. plot(agr.lm, which=4) # Cook's distance plot(ComIndl,Nitrogen,col="blue",lwd=3) ComIndl.lm=lm(Nitrogen~ComIndl); plot(hatvalues(ComIndl.lm)) plot(ComIndl.lm,which=3) plot(ComIndl.lm,which=2) plot(agr.lm, which=4) plot(ComIndl.lm,which=5) # leverage versus residuals # Try these measures of influence influence.measures(ComIndl.lm) hatvalues(ComIndl.lm) # hatvalues in R is same thing as leverage. dffits(ComIndl.lm) dfbetas(ComIndl.lm) cooks.distance(ComIndl.lm) # You can plot them, for example: plot(hatvalues(ComIndl.lm),type="h") # Use the help documentation to learn more about what each does. ?dffits ?dfbetas # Take out a data point and do a fit without it. # Here, I took out datapoint number 4 in the slides. ComIndl.lm.no4=lm(Nitrogen[-4]~ComIndl[-4]) plot(ComIndl,Nitrogen,col="blue",lwd=3) abline(ComIndl.lm,col="red",lwd=2) abline(ComIndl.lm.no4,col="green",lwd=2)