library(car)
states<-as.data.frame(state.x77[,c("Murder","Population","Illiteracy",
"Income","Frost")])
fit<-lm(Murder~Population+Illiteracy+Income+Frost,data=states)
hat.plot<-function(fit){
p<-length(coefficients(fit))
n<-length(fitted(fit))
plot(hatvalues(fit),main="Index Plot of Hat Values")
abline(h=c(2,3)*p/n,col="red",lty=2)
identify(1:n,hatvalues(fit),names(hatvalues(fit)))
}
hat.plot(fit)
代码如上,做完回归然后检验高杠杆值,图是出来了,然后点击高杠杆点总是显示
警告:没有点在0.25英尺内