Sumit - 1 year ago 80
R Question

# Access p-value from quantile regression for multiple quantiles in R

I want to access p-values of quantile regression with multiple quantiles.

``````fit2 <- rq(speed ~ vsby_avg + snwd_avg, tau=c(.05, 0.95), data = test_data)
fit2_summ <- summary(fit2)
``````

The
`str(fit2_summ)`
gives the following result

``````List of 2
\$ :List of 6
..\$ call        : language rq(formula = speed ~ vsby_avg + snwd_avg, tau = c(0.05, 0.95), data = test_data)
..\$ terms       :Classes 'terms', 'formula'  language speed ~ vsby_avg + snwd_avg
.. .. ..- attr(*, "variables")= language list(speed, vsby_avg, snwd_avg)

..\$ coefficients: num [1:3, 1:4] 57.63195 0.13474 -0.00337 0.1919 0.01212 ...
``````

I am not able to access the p-values for the 50th and 95th quantile using
`fit2_summ\$coefficients[,4]`
because the summary model is present for 2 quantiles rather than a single quantile, in which case the above command would have worked.

You should specifiy a method for calculating se:

``````# using mtcars
library(quantreg)
fit <- rq(mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)

fit.smy <- summary(fit, se = 'boot')
# > fit.smy
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.05
#
# Coefficients:
#             Value    Std. Error t value  Pr(>|t|)
# (Intercept) 29.02978  1.85711   15.63170  0.00000
# cyl         -1.43979  0.55214   -2.60766  0.01426
# disp        -0.01546  0.00773   -1.99955  0.05499
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.95
#
# Coefficients:
#             Value    Std. Error t value  Pr(>|t|)
# (Intercept) 51.82250  6.18594    8.37747  0.00000
# cyl         -4.70281  1.84648   -2.54691  0.01644
# disp         0.01250  0.02616    0.47785  0.63634
``````

access P.values

``````# fit.smy is a list, its length is the same as tau;
lapply(fit.smy, function(x){
x\$coefficients[,4]
})
# [[1]]
#  (Intercept)          cyl         disp
# 3.996803e-14 2.205166e-02 5.699536e-02
#
# [[2]]
#  (Intercept)          cyl         disp
# 3.263261e-08 4.381427e-02 6.903882e-01
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download