"残差与杠杆"中的红色实线是什么?由plot.lm()生成的情节?

时间:2016-08-11 14:40:31

标签: r plot regression linear-regression lm

fit <- lm(dist ~ speed, cars)
plot(fit, which = 5)

情节中间的红线是什么意思?

我认为这不是关于厨师的距离。

1 个答案:

答案 0 :(得分:4)

这是LOESS回归线(span = 2/3degree = 2),通过平滑标准化残差与杠杆作用。

plot.lm()内部,变量xx是杠杆,而rsp是Pearson残差(即标准化残差)。然后,通过以下方式绘制散射图和红色实线:

graphics::panel.smooth(xx, rsp)

以下是此功能的作用:

> 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>

?plot.lm的R文档并未解释所有内容。您最多可以从&#34; Arguments&#34;获得以下提示:部分:

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.

通常add.smooth = TRUE是默认值,因此您会看到红色实线。但您可以使用add = FALSE来抑制它:

plot(fit, which = 5, add.smooth = FALSE)

enter image description here