- Plot the data along with the regression line.
m1 <- lm(dist ~ speed)
summary(m1)
plot(speed,dist)
abline(m1)
lines(lowess(speed,dist),col='red')
- Test for outliers.
plot(c(0,51),c(0,3.6),type='n',main='Jacknife Residuals m1')
points(abs(rstudent(m1)))
abline(h=qt(1-.05/100,df=48))
qt(1-.05/100,df=48)
abs(rstudent(m1))[abs(rstudent(m1))>3]
#28 and 49 are close, but no outliers according to this test
- Test for influential points.
plot(abs(dffits(m1)),main='Dffits m1')
abline(h=2*sqrt(2/50))
dffits(m1)[abs(dffits(m1))>2*sqrt(2/50)]
# 23 and 49
identify(abs(dffits(m1)))
plot(abs(dfbetas(m1)[,1]),main='dfbetas m1 (intercept)')
abline(h=2/sqrt(50))
dfbetas(m1)[,1][abs(dfbetas(m1)[,1])>2/sqrt(50)]
# 2 and 49
identify(abs(dfbetas(m1)[,1]))
plot(abs(dfbetas(m1)[,2]),main='dfbetas m1 (slope)')
abline(h=2/sqrt(50))
dfbetas(m1)[,2][abs(dfbetas(m1)[,2])>2/sqrt(50)]
# 49
identify(abs(dfbetas(m1)[,2]),main='dfbetas m1 (slope)')
- Test for high leverage points.
plot(hat(model.matrix(m1)))
abline(h=4/50)
identify(hat(model.matrix(m1)))
#1 2 and 50
- Give a 95% confidence interval for the effect of speed on the
stopping distance.
confint(m1)
# 3.096964 to 4.767853
detach(Cars)