1.2 In R
###outlier example
IQ<-c(90,90,110,120,80,130,125,95,100)
shoesize<-c(8.25,8.5,12,12,7.75,12.5,12,9.5,9.7)
###The original shoe IQ data
###I add an outlier, that is influential
shoesize2<-c(shoesize,20)
IQ1<-c(IQ,115)
###to the original shoe IQ data
###I add an outlier that is not influential
shoesize2<-c(shoesize,15)
IQ2<-c(IQ,140)
###all of the data with the affected regression lines
shoesize3<-c(shoesize,20,15)
IQ3<-c(IQ,115,140)
shoeIQdata<-as.data.frame(cbind(shoesize3,IQ3))
names(shoeIQdata)<-c("shoesize","IQ")
regline1<-lm(IQ ~ shoesize,data=shoeIQdata[1:9,])
regline2<-lm(IQ ~ shoesize,data=shoeIQdata[1:10,])
regline3<-lm(IQ ~ shoesize,data=shoeIQdata[-10,])
plot(shoesize3,IQ3,type="n")
points(shoesize3[1:9],IQ3[1:9],col="black")
points(shoesize3[10],IQ3[10],col="red")
2