r - Why fitted values do not lie on the fitted line -
i have basic question regarding understanding linear regression model. consider simple case when $y = + bx + e$, $e$ error term. use ols estimate coefficients $a$ , $b$. fitted values $\hat y = \hat + \hat b x$. should not lie on same line, since linear relationship? ask because simple manipulations in r , have counterintuitive results
x <- rnorm(20, 3, 1) y <- 12 + 4*x + rnorm(20, 0, 0.5) m <- lm(y ~ x) <- 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))
why fitted values not lie on fitted line?
replace last line with
points(x = x, y = m$fitted.values, col = 4, pch = 4) #plot fitted values
the fitted values y
, not x
.
Comments
Post a Comment