我开始深入研究plot.lm函数,该函数给出了lm的六个图,它们是:
- 残差与拟合值的关系图
- sqrt(|残差|)对拟合值的比例位置图
- 普通QQ图,库克距离与行标签的图
- 残差与杠杆的关系图
- 库克距离与杠杆/(1-杠杆)的关系图
我想知道线性图还存在电流图的其他常见/有用扩展,以及它们如何在R中完成?(也欢迎链接到包装的文章)
因此,boxcox函数(来自{MASS})是另一个有用的诊断图的示例(这样的答案会很好),但是,我对R中lm的现有默认诊断图的变化/扩展感到好奇(尽管一般始终欢迎您对此主题发表其他评论)。
这是我的意思的一些简单示例:
#Some example code for all of us to refer to
set.seed(2542)
x1 <- rnorm(100)
x2 <- runif(100, -2,2)
eps <- rnorm(100,0,2)
y <- 1 + 2*x1 + 3*x2 + eps
y[1:4] <- 14 # adding some contaminated points
fit <- lm(y~x1+x2)
#plot(y~x1+x2)
#summary(fit)
绘制残差与每个潜在x的关系
plot(resid(fit)~x1); abline (h = 0)
plot(resid(fit)~x2); abline (h = 0)
# plot(resid(fit)~x1+x2) # you can also use this, but then you wouldn't be able to use the abline on any plot but the last one
向qpplot中添加0-1行(英语中怎么称呼这行?!),以便查看qqline偏离了多少
plot(fit, which = 2); abline(0,1, col = "green")
使用外部学生化残差绘制qq图
# plot(fit, which = 2); abline(0,1, col = "green") # The next command is just like this one
qqnorm(rstandard(fit), ylim = c(-2.2,4.2)); qqline(rstudent(fit), lty = 2) ;abline(0,1, col = "green")
qqnorm(rstudent(fit), ylim = c(-2.2,4.2)); qqline(rstudent(fit), lty = 2) ;abline(0,1, col = "green")
# We can note how the "bad" points are more extreme when using the rstudent