我正在尝试获取线性和分位数回归的五种引导区间。我能够使用 Boot from 引导并找到线性回归的 5 个引导区间(分位数、正常、基本、学生化和 BCa)car和 boot.ci 来自boot。当我尝试使用 rq 对分位数回归执行相同操作时quantreg,它会抛出一个错误。这是示例代码
创建模型
library(car)
library(quantreg)
library(boot)
newdata = Prestige[,c(1:4)]
education.c = scale(newdata$education, center=TRUE, scale=FALSE)
prestige.c = scale(newdata$prestige, center=TRUE, scale=FALSE)
women.c = scale(newdata$women, center=TRUE, scale=FALSE)
new.c.vars = cbind(education.c, prestige.c, women.c)
newdata = cbind(newdata, new.c.vars)
names(newdata)[5:7] = c("education.c", "prestige.c", "women.c" )
mod1 = lm(income ~ education.c + prestige.c + women.c, data=newdata)
mod2 = rq(income ~ education.c + prestige.c + women.c, data=newdata)
启动线性和分位数回归
mod1.boot <- Boot(mod1, R=999)
boot.ci(mod1.boot, level = .95, type = "all")
dat2 <- newdata[5:7]
mod2.boot <- boot.rq(cbind(1,dat2),newdata$income,tau=0.5, R=10000)
boot.ci(mod2.boot, level = .95, type = "all")
Error in if (ncol(boot.out$t) < max(index)) { :
argument is of length zero
1) 为什么 boot.ci 不适用于分位数回归
2)使用我从 stackexchange 获得的这个解决方案,我能够找到分位数 CI。
rq 的分位数(百分位数 CI)的解决方案
t(apply(mod2.boot$B, 2, quantile, c(0.025,0.975)))
我如何获得引导程序的其他 CI(正常、基本、学生化、BCa)。
3)此外,我的线性回归 boot.ci 命令会产生此警告
Warning message:
In sqrt(tv[, 2L]) : NaNs produced
这意味着什么?