如何从分位数回归中提取系数的上/下界 rq()

Eri*_*een 5 regression r quantile quantreg

我想使用该quantreg包从分位数回归中提取系数以及上限和下限。这是帮助文件中的示例。

data(engel)
attach(engel)
taus <- c(.05,.1,.25,.75,.9,.95)
f <- rq((foodexp)~(income),tau=taus)
sf <- summary(f)
sf[1]
#[[1]]

#Call: rq(formula = (foodexp) ~ (income), tau = taus)

#tau: [1] 0.05

#Coefficients:
#            coefficients lower bd  upper bd 
#(Intercept) 124.88004     98.30212 130.51695
#income        0.34336      0.34333   0.38975
Run Code Online (Sandbox Code Playgroud)

我知道我可以用来coefficients()获取系数。

cf <- t(data.frame(coefficients(f)))    # transpose for better arrangement
cf
#              (Intercept)    income
#tau..0.05   124.88004 0.3433611
#tau..0.10   110.14157 0.4017658
#tau..0.25    95.48354 0.4741032
#tau..0.75    62.39659 0.6440141
#tau..0.90    67.35087 0.6862995
#tau..0.95    64.10396 0.7090685
Run Code Online (Sandbox Code Playgroud)

但我不知道如何获得出现在summary(). 我看了str(sf),但没看到如何提取。

最终,我想将 taus、系数和上/下界放入数据框中以进行进一步处理。

MrF*_*ick 3

我假设您只想要非截距项的系数。这个怎么样

sapply(sf, function(x) c(tau=x$tau, x$coefficients[-1, ]))
Run Code Online (Sandbox Code Playgroud)

这将迭代不同级别tau并提取系数的区间

                  [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
tau          0.0500000 0.1000000 0.2500000 0.7500000 0.9000000 0.9500000
coefficients 0.3433611 0.4017658 0.4741032 0.6440141 0.6862995 0.7090685
lower bd     0.3433270 0.3420992 0.4203298 0.5801552 0.6493680 0.6739000
upper bd     0.3897500 0.4507941 0.4943288 0.6904127 0.7422294 0.7344405
Run Code Online (Sandbox Code Playgroud)