all4=read.table("/Users/pcaragea/teaching/Stat401/STAT401F07/Compute/anscombe.txt",header=TRUE) attach(all4) MS1=lm(y[set==1]~x[set==1]) MS2=lm(y[set==2]~x[set==2]) MS3=lm(y[set==3]~x[set==3]) MS4=lm(y[set==4]~x[set==4]) pdf("/Users/pcaragea/teaching/Stat401/STAT401F07/Compute/Anscombe_R.pdf") #plots: plot(x[set==1],y[set==1],pch=20,xlab="X",ylab="Y",main="Set 1") abline(MS1$coef) plot(x[set==2],y[set==2],pch=20,xlab="X",ylab="Y",main="Set 2") abline(MS2$coef) plot(x[set==3],y[set==3],pch=20,xlab="X",ylab="Y",main="Set 3") abline(MS3$coef) plot(x[set==4],y[set==4],pch=20,xlab="X",ylab="Y",main="Set 4") abline(MS4$coef) #residual plots plot(MS1,which=1,pch=20) plot(MS2,which=1,pch=20) plot(MS3,which=1,pch=20) plot(MS4,which=1,pch=20) #cooks' distance plot(MS1,which=4,pch=20) plot(MS2,which=4,pch=20) plot(MS3,which=4,pch=20) plot(MS4,which=4,pch=20) #to compute just Cook's distance: cooks.distance(MS1) cooks.distance(MS2) cooks.distance(MS3) cooks.distance(MS4) dev.off()