我想使用 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
我知道我可以使用
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
但我不知道如何获得出现在
summary()
中的上限/下限.我看了str(sf)
,但我没有看到如何提取。最终,我想将 taus、系数和上限/下限放在数据框中以进行进一步处理。
最佳答案
我假设您只想要非截距项的系数。这个怎么样
sapply(sf, function(x) c(tau=x$tau, x$coefficients[-1, ]))
这将迭代
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
关于r - 如何从分位数回归 rq() 中提取系数的上限/下限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23926798/