简体   繁体   中英

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?

# 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(object = x, parm = "scale(Sepal.Width)", level = 0.95)

#                        2.5 %     97.5 %
#scale(Sepal.Width) -0.3058138 0.01894847

Edit

confint uses method confint.lm when it is passed x because x is of class lm (as well as rlm ). Calling confint.default explicitly avoids this. These two functions only differ in one line of code, as shown below:

confint.lm

fac <- qt(a, object$df.residual)

confint.default

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.

Late to the party, but note that CIs from the normal distribution will have lower than expected coverage for small sample sizes.

The residual degrees of freedom for the rlm object can be gotten from,

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:

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(x)
                        2.5 %     97.5 %
(Intercept)        -0.2004593 0.12588715
scale(Sepal.Width) -0.3071526 0.02028719

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM