[英]Getting confidence intervals for robust regression coefficient (MASS::rlm)
Is there any possible way to get 95% CI for regression coefficients from the robust regression, as implemented in MASS::rlm?是否有任何可能的方法可以从稳健回归中获得 95% CI 的回归系数,如在 MASS::rlm 中实现的那样?
# libraries needed
library(MASS)
library(stats)
library(datasets)
# running robust regression
(x <-
MASS::rlm(formula = scale(Sepal.Length) ~ scale(Sepal.Width),
data = iris))
#> Call:
#> rlm(formula = scale(Sepal.Length) ~ scale(Sepal.Width), data = iris)
#> Converged in 5 iterations
#>
#> Coefficients:
#> (Intercept) scale(Sepal.Width)
#> -0.03728607 -0.14343268
#>
#> Degrees of freedom: 150 total; 148 residual
#> Scale estimate: 1.06
# getting confidence interval for the regression coefficient
stats::confint(object = x,
parm = "scale(Sepal.Width)",
level = 0.95)
#> 2.5 % 97.5 %
#> scale(Sepal.Width) NA NA
Explicitly calling confint.default
seems to provide good results, like this: 显式调用confint.default
似乎可以提供良好的结果,如下所示:
confint.default(object = x, parm = "scale(Sepal.Width)", level = 0.95)
# 2.5 % 97.5 %
#scale(Sepal.Width) -0.3058138 0.01894847
confint
uses method confint.lm
when it is passed x
because x
is of class lm
(as well as rlm
). confint
使用方法confint.lm
当它传递x
因为x
是类的lm
(以及rlm
)。 Calling confint.default
explicitly avoids this. 调用confint.default
明确避免这种情况。 These two functions only differ in one line of code, as shown below: 这两个函数仅在一行代码中有所不同,如下所示:
fac <- qt(a, object$df.residual)
fac <- qnorm(a)
The issue is that x$df.residual
is NA
and, consequently, qt(a, object$df.residual)
produces an NA
whereas qnorm(a)
doesn't have this problem. 问题是x$df.residual
是NA
,因此qt(a, object$df.residual)
产生NA
而qnorm(a)
没有这个问题。
Late to the party, but note that CIs from the normal distribution will have lower than expected coverage for small sample sizes.迟到了,但请注意,对于小样本量,正态分布的 CI 的覆盖率将低于预期。
The residual degrees of freedom for the rlm object can be gotten from, rlm 对象的剩余自由度可以从,
summary(x)$df[2] # see code for MASS:::summary.rlm
To write your own confint method for rlm results, assign the df to the df.residual slot, and then call confint.lm:要为 rlm 结果编写自己的 confint 方法,请将 df 分配给 df.residual 槽,然后调用 confint.lm:
confint.rlm <- function(object, ...){
object$df.residual <- MASS:::summary.rlm(object)$df[2]
confint.lm(object, ...)
}
Now confint behaves as expected, and is also based on Student's t:现在 confint 的行为符合预期,并且还基于学生的 t:
confint(x)
2.5 % 97.5 %
(Intercept) -0.2004593 0.12588715
scale(Sepal.Width) -0.3071526 0.02028719
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.