获得稳健回归系数的置信区间(MASS :: rlm)

时间:2018-03-07 16:34:14

标签: r statistics mass

有没有办法从稳健回归中获得回归系数的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

1 个答案:

答案 0 :(得分:1)

明确调用ERROR: syntax error at or near "character" LINE 1: ...LTER TABLE user_template ALTER COLUMN "type" character ... ^ 似乎可以提供良好的结果,如下所示:

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时使用方法confint.lm,因为x属于类x(以及lm)。明确地调用rlm可以避免这种情况。这两个函数仅在一行代码中有所不同,如下所示:

confint.lm

confint.default

confint.default

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

问题是fac <- qnorm(a) x$df.residual,因此NA会产生qt(a, object$df.residual),而NA不会产生此问题。< / p>