gpt4 book ai didi

r - plot.lm() 如何确定残差与拟合图的异常值?

转载 作者:行者123 更新时间:2023-12-03 16:53:50 27 4
gpt4 key购买 nike

plot.lm() 如何确定残差与拟合图的哪些点是异常值(即要标记哪些点)?我在 documentation 中找到的唯一东西这是:

Details

sub.caption—by default the function call—is shown as a subtitle (under the x-axis title) on each plot when plots are on separate pages, or as a subtitle in the outer margin (if any) when there are multiple plots per page.

The ‘Scale-Location’ plot, also called ‘Spread-Location’ or ‘S-L’ plot, takes the square root of the absolute residuals in order to diminish skewness (sqrt(|E|)) is much less skewed than | E | for Gaussian zero-mean E).

The ‘S-L’, the Q-Q, and the Residual-Leverage plot, use standardized residuals which have identical variance (under the hypothesis). They are given as R[i] / (s * sqrt(1 - h.ii)) where h.ii are the diagonal entries of the hat matrix, influence()$hat (see also hat), and where the Residual-Leverage plot uses standardized Pearson residuals (residuals.glm(type = "pearson")) for R[i].

The Residual-Leverage plot shows contours of equal Cook's distance, for values of cook.levels (by default 0.5 and 1) and omits cases with leverage one with a warning. If the leverages are constant (as is typically the case in a balanced aov situation) the plot uses factor level combinations instead of the leverages for the x-axis. (The factor levels are ordered by mean fitted value.)

In the Cook's distance vs leverage/(1-leverage) plot, contours of standardized residuals that are equal in magnitude are lines through the origin. The contour lines are labelled with the magnitudes.


但它没有说明残差与拟合图的生成方式以及它如何选择要标记的点。
更新 :Zheyuan Li 的回答表明残差与拟合图标记点的方式实际上只是通过查看残差最大的 3 个点。情况确实如此。可以通过以下“极端”示例来证明。
x = c(1,2,3,4,5,6)
y = c(2,4,6,8,10,12)
foo = data.frame(x,y)
model = lm(y ~ x, data = foo)
enter image description here

最佳答案

他们找到最大的 3 个绝对标准化残差。考虑这个例子:

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

enter image description here
r <- rstandard(fit)  ## get standardised residuals
order(abs(r), decreasing = TRUE)[1:3]
# [1] 49 23 35

关于r - plot.lm() 如何确定残差与拟合图的异常值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39259252/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com