问题
fit <- lm(dist ~ speed, cars)
plot(fit, which = 5)
What does the solid red line in the middle of plot mean?
I think it is not about cook's distance.
回答1:
It is the LOESS regression line (with span = 2/3 and degree = 2), by smoothing standardised residuals against leverage.
Internally in plot.lm(), variable xx is leverage, while rsp is Pearson residuals (i.e., standardised residuals). Then, the scattered plot as well as the red solid line is drawn via:
graphics::panel.smooth(xx, rsp)
Here is what this function does:
> panel.smooth
function (x, y, col = par("col"), bg = NA, pch = par("pch"),
cex = 1, col.smooth = "red", span = 2/3, iter = 3, ...)
{
points(x, y, pch = pch, col = col, bg = bg, cex = cex)
ok <- is.finite(x) & is.finite(y)
if (any(ok))
lines(stats::lowess(x[ok], y[ok], f = span, iter = iter),
col = col.smooth, ...)
}
<bytecode: 0xabc0004>
<environment: namespace:graphics>
R documentation for ?plot.lm does not explain everything. You can at most get the following hint from the "Arguments" section:
panel
panel function. The useful alternative to `points`, `panel.smooth` can be
chosen by `add.smooth = TRUE`.
add.smooth
logical indicating if a smoother should be added to most plots; see also
panel above.
Normally add.smooth = TRUE is the default, hence you see that solid red line. But you can use add = FALSE to suppress it:
plot(fit, which = 5, add.smooth = FALSE)
来源:https://stackoverflow.com/questions/38899463/what-is-the-red-solid-line-in-the-residuals-vs-leverage-plot-produced-by-plot