Sumit - 8 months ago 55

R Question

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)`

`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]`

Answer Source

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
```