Jia
Jia

Reputation: 15

Avoiding singularity matrix in regression

I want to run quantile regression on the following high dimensional code(n=123, p =945) .. but I get an error saying the design matrix is singular and cannot compute. Below is how i extracted the data using the PRIMsrc package.

library(PRIMsrc)
data(Real.2)
df<-Real.2
y<-df$y
X<-data.matrix(df[2:946])
library(quantreg)
rq1 = rq(y ~X,tau=1)

This seems to be an issue with the data itself so i tried to add some noise to the response using jitter() with the base package, but this didn't solve the issue. Any idea?

Upvotes: 0

Views: 1267

Answers (1)

StupidWolf
StupidWolf

Reputation: 47008

You have too many variables to fit with too little observations. It's not quite possible to get an estimate for all of them. In your case, I suggest you try a lasso:

library(PRIMsrc)
data(Real.2)
df<-Real.2
y<-df$y
X<-data.matrix(df[2:946])
library(quantreg)
rq1 = rq.fit.lasso(y=y,x=X,tau=0.5)

The coefficients can be found under:

rq1$coefficients

For predictions etc, this should work ok. For inferences based on the coefficients etc, you might need to give it more thought

Upvotes: 1

Related Questions