2
votes

I'm interested in doing a multivariate regression in R, looking at the effects of a grouping variable (2 levels) on several dependent variables. However, due to my data being non-normal and the 2 groups not having homogenous variances, I'm looking to use a quantile regression instead. I'm using the rq function from the quantreg toolbox to do this.

My code is as follows

 # Generate some fake data
   DV = matrix(rnorm(40*5),ncol=5) #construct matrix for dependent variables

   IV =  matrix(rep(1:2,20)) #matrix for grouping factor

   library(quantreg)

   model.q = rq(DV~IV,
             tau = 0.5)

I get the following error message when this is run:

Error in y - x %*% z$coef : non-conformable arrays
In addition: Warning message:
In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique

I believe this is due to my having several DVs, as the model works fine when I try using a DV of one column. Is there a specific way I should be formatting my data? Or perhaps there is another function I may be able to use?

Thank you!

2

2 Answers

2
votes

If you just want to run several regressions, each with the same set of independent variables, but with a different dependent variable, you could write a function and then apply it to all columns of your DV matrix and save the models in a list:

reg <- function(col_number) {
  model.q <- rq(DV[, col_number] ~ IV, tau = 0.5)
}
model_list <- lapply(1:ncol(DV), reg)

However, as pointed out in the comments, it might be that you want a multivariate model accounting for the correlation of the outcome - but then I do not think the rq method would be appropriate

2
votes

If you have multiple responses, what you most likely need is:

DV = matrix(rnorm(40*5),ncol=5) #construct matrix for dependent variables
IV =  matrix(rep(1:2,20)) #matrix for grouping factor
library(quantreg)
rqs.fit(x=IV, y=DV, tau=0.5, tol = 0.0001)

Unfortunately, there's really not a lot of documentation about how this works.. I can update if i do find it