What is the red solid line in the “residuals vs leverage” plot produced by `plot.lm()`?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 21:18:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!