图中的数字对应于标准化残差和原始数据的索引。默认情况下,R标记三个最极端的残差,即使它们与 QQ 线的偏差不大。因此,标记点的事实并不意味着拟合不好或其他任何事情。可以通过指定选项来更改此行为id.n。让我用你的例子来说明这一点
set.seed(1)
y <- rnorm(100)
x <- rnorm(100)
lm.mod <- lm(y ~ x) # linear regression model
plot(lm.mod, which=2) # QQ-Plot
lm.resid <- residuals(lm(y ~ x)) # save the residuals
sort(abs(lm.resid), decreasing=TRUE) # sort the absolute values of the residals
14 61 24
2.32415869 2.29316200 2.09837122
前三个最极端的残差是数字 14、61 和 24。这些是图中的数字。这些索引对应于原始数据的索引。因此,数据点 14、24 和 26 是导致最极端残差的数据点。我们还可以在散点图中标记它们(蓝点)。请注意,由于您是独立生成的y,x因此回归线只是y没有任何斜率的平均值:
# The original data points corresponding to the 3 most extreme residuals
cbind(x,y)[c(14, 24, 61), ]
x y
[1,] -0.6506964 -2.214700
[2,] -0.1795565 -1.989352
[3,] 0.4251004 2.401618
# Make a scatterplot of the original data and mark the three points
# and add the residuals
par(bg="white", cex=1.6)
plot(y~x, pch=16, las=1)
abline(lm.mod, lwd=2) # add regression line
pre <- predict(lm.mod)
# Add the residual lines
segments(x[c(14, 24, 61)], y[c(14, 24, 61)], x[c(14, 24, 61)],
pre[c(14, 24, 61)], col="red", lwd=2)
# Add the points
points(x[c(14, 24, 61)], y[c(14, 24, 61)], pch=16, cex=1.1, col="steelblue", las=1)
