Question

I have a quantile regression model with 1 regressor and 1 regressand. I want to hypothesis test that the regressor is equal over every quantile. One approach I've thought of is to test over all tau over {0.01,0.02,....,0.99}. However, I would then have to write:

anova(model1,model2,model3,.......,model99), where each model corresponds to a different tau. Question: How do I get anova() to accept large amount of models of type rq without manually typing them out?


My attempt at a solution has been to do this:

y = rnorm(100)
x = rnorm(100)

rqs_object <- rq(y~x,tau=1:99/100)
anova(rqs_object)

However, anova clearly doesn't take object type rqs, only type rq, unfortunately.


Cross posted here until I decided that it had a large programming/specialist element to the problem .

Was it helpful?

Solution

I concentrate on question 1 and only on the programming part.

some data:

set.seed(65465)
y = rnorm(100)
x = rnorm(100)

Now I define a function, that takes tau as input and does the fit:

rqfits <- function(tau) {
  require(quantreg)
  rq(y~x,tau=tau)
}

I can then apply this function on a vector of taus:

taus <- 1:5/10
fits <- lapply(taus,rqfits)

The result is a list of models. We can now use do.call to pass our models to anova:

do.call(anova,fits)

Quantile Regression Analysis of Deviance Table

Model: y ~ x
Joint Test of Equality of Slopes: tau in {  0.1 0.2 0.3 0.4 0.5  }

  Df Resid Df F value Pr(>F)
1  4      496  1.0388 0.3866
Warning:
In summary.rq(x, se = se, covariance = TRUE) : 2 non-positive fis
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top