【问题标题】:What is the red solid line in the "residuals vs leverage" plot produced by `plot.lm()`?`plot.lm()` 生成的“残差 vs 杠杆”图中的红色实线是什么?
【发布时间】:2016-12-18 09:01:09
【问题描述】:
fit <- lm(dist ~ speed, cars)
plot(fit, which = 5)

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

我认为这与厨师的距离无关。

【问题讨论】:

    标签: r plot regression linear-regression lm


    【解决方案1】:

    它是 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 文档并没有解释一切。您最多可以从“参数”部分获得以下提示:

    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)
    

    【讨论】:

    • 非常感谢您的友好回答!
    • 很抱歉迟到了。我之前就做过。再次感谢您!。
    猜你喜欢
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2018-02-27
    • 2017-01-08
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多