5

I am building a quantile regression model + LASSO penalization for the boston housing data in R. I found 2 packages that can build this kind of models: rqPen and quantreg. rqPen implements a cross validation process to tune the LASSO parameter lambda, so I decided to use this one. I considered 100 different lambda values automatically chosen by the algorithm and 10 folds:

library(rqPen)
library(mlbench)
data("BostonHousing")
help(BostonHousing)
x_boston <- data.matrix(BostonHousing[,-14])
y_boston <- BostonHousing[,14]
cv_m1_boston <- cv.rq.pen(x_boston,y_boston, penalty="LASSO", nlambda=100, nfolds=10, tau=.5, cvFunc="AE")

The results from the CV are that the smallest absolute error is 4.2 achieved with a lambda value of 0.46. This model considers only the predictors "zn, "tax", "b" and "lstat" and sends to zero the coefficients associated to the rest of the predictors.

m1_boston <- rq.lasso.fit(x_boston[i_train,], y_boston[i_train], tau=0.5, lambda=0.46)

Coefficients:
intercept         crim           zn        indus         chas          nox           rm          age          dis          rad 
27.175724364  0.000000000  0.025560221  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000  0.000000000 
        tax      ptratio            b        lstat 
-0.008151729  0.000000000  0.007577458 -0.495927958 

I decided to build the same model using the other package, the quantreg package, but maintaining the lambda value. I expected the models form the two packages to be not exactly equal but similar in terms of the predictors included in the models.

library(quantreg)
m2_boston <- rq(medv~., data=BostonHousing[i_train,], tau=0.5,method = "lasso", lambda=0.46)

And I found that in this model all the predictors were being used, so it was completly different to the first one.

Coefficients:
(Intercept)         crim           zn        indus        chas1          nox           rm          age          dis          rad 
15.528274036 -0.128622834  0.038896192  0.007109711  1.385725245 -7.221209356  5.144134214 -0.035033485 -1.075032872  0.165388801 
        tax      ptratio            b        lstat 
-0.010579964 -0.765578313  0.012533729 -0.283032080 

Am I doing something wrong? is the rqPen package failing on the computations?

0 Answers0