 Eric Green - 3 years ago 159
R Question

# how to extract upper/lower bounds on coefficients from quantile regression rq()

I'd like to extract coefficients and upper and lower bounds from a quantile regression using the

`quantreg`
package. Here's an example from the help file.

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

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

#tau:  0.05

#Coefficients:
#            coefficients lower bd  upper bd
#(Intercept) 124.88004     98.30212 130.51695
#income        0.34336      0.34333   0.38975
``````

I know I can use
`coefficients()`
to get the 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
``````

But I can't figure out how to get the upper/lower bounds that appear in
`summary()`
. I looked at
`str(sf)`
, but I did not see how to extract.

Ultimately, I'd like to put taus, coefficients, and upper/lower bounds in a dataframe for further processing. MrFlick

``````sapply(sf, function(x) c(tau=x\$tau, x\$coefficients[-1, ]))
That will iterate over the different levels of `tau` and extract the intervals for the coefficients
``````                  [,1]      [,2]      [,3]      [,4]      [,5]      [,6]