为什么拟合值不在拟合线上

Why fitted values do not lie on the fitted line

我有一个关于理解线性回归模型的非常基本的问题。考虑 $y = a + bx + e$ 时的简单情况,其中 $e$ 是误差项。我使用 OLS 来估计系数 $a$ 和 $b$。那么拟合值为 $\hat y = \hat a + \hat b x$。既然是线性关系,难道不应该在同一条线上吗?我问是因为我在 R 中进行了简单的操作并得到了违反直觉的结果

x <- rnorm(20, 3, 1)
y <- 12 + 4*x + rnorm(20, 0, 0.5)
m <- lm(y ~ x)
a <- coef(m)[1]
b = coef(m)[2]
plot(x, y) #plot initial data
abline(a = a, b = b, lwd = 2, col = 2) #plot fitted line
points(x = m$fitted.values, col = 4, pch = 4) #plot fitted values
legend('topleft', c("Actual", "Fitted line", "Fitted values"), col = c(1, 2, 4), pch = c(1, 1, 4), lty = c(0, 1, 0))

为什么拟合值不在拟合线上?

将最后一行替换为

points(x = x, y = m$fitted.values, col = 4, pch = 4) #plot fitted values

拟合值适用于 y,不适用于 x