1

I am trying to run LASSO (least absolute shrinkage and selection operator) using the lars package in R. Here is the dimension of my data:

dim(y) : 235 50

dim(x) : 235 15

When running the following:

 library(lars)
 return = as.matrix(ret.ff.zoo)   ### this is my "y"
 data = as.matrix(df)   ### this is my "x"
 lasso <- lars(data, return, type = c("lasso")) 

I get the following error:

 > lasso <- lars(data, return, type = c("lasso")) 
 Error in Cvec - gamhat * Gram[, active, drop = FALSE] %*% w : 
   non-conformable arrays

When I make the response variable "y" a vector, as follows:

 lasso <- lars(data, return[,1], type = c("lasso")) 

It works! However, doing this means that the LASSO is performed on 1 security out of 3000 from the panel. How can this formula be extended to analyze a panel of data?? Doing LASSO separately on each of the 3000 securities doesn't make much sense as it excludes any cross-sectional dynamic.

I could use any help I can get! Thanks!

Mayou
  • 8,498
  • 16
  • 59
  • 98
  • The help page for lars() says the y argument is "response" but unlike the description of the x argument it does _not_ say it should be a matrix. Furthermore if you are not naming your argument then the y-argument should come second. – IRTFM Aug 23 '13 at 19:44
  • Well, the reason why my "y" is a matrix is because it is panel dataset (in other words, have a cross-sectional and time-series component). How can I implement the function with panel data? – Mayou Aug 23 '13 at 19:50
  • This appears to be further attempt to post a similar question that you asked and deleted earlier today, and I advised you at that time to request assistance at CV asking for advice on available methods. This does not appear to do so. You should have asked for statistical advice and instead posted failed code. Now you are again asking for statistical advice at THE WRONG FORUM. You should post a CV question that does not try to apply functions that do not accomplish what you want, and instead ask about what methods might have been developed for the sort of problem you are trying to solve. – IRTFM Aug 23 '13 at 20:19
  • 1
    @DWin, note that this was migrated *from* CV. Since this question is purely about using the R function and data formatting, it's definitely not suitable for CV. – ely Aug 23 '13 at 20:23
  • @EMS Thank you very much for clarifying this to DWin. My post was indeed migrated DWin. – Mayou Aug 23 '13 at 20:25
  • 1
    Also, on CV, I was the one who [advised the OP to use LASSO](http://stats.stackexchange.com/questions/68181/performing-all-possible-regressions-in-r/68192#68192), so if you don't enjoy LASSO's use for panel data (I use it all the time for panel data for my job), that's OK, but it's surely not the OP's fault. The method is being misused above (you'd want to perform LASSO as the cross-sectional regression, then something like Fama-MacBeth across time), but still, LASSO is a perfectly fine tool for the OP's problem. – ely Aug 23 '13 at 20:25
  • @EMS Thanks for clarifying the methodology. Could we discuss more this hybrid of LASSO and Fama-MacBeth? I am still new to this model selection world.. I am very familiar with Fama-MacBeth, not so much with LASSO. – Mayou Aug 23 '13 at 20:27
  • @EMS: But lars::lars may not be the correct tool to implement LASSO on panel data, right? – IRTFM Aug 23 '13 at 20:33
  • @EMS Thanks for clarifying the methodology. Could we discuss more this hybrid of LASSO and Fama-MacBeth? I am still new to this model selection world.. I am very familiar with Fama-MacBeth, not so much with LASSO. I am not sure how to run LASSO on the cross-section when my predictors are "Economic variables", because each predictor, e.g. Inflation, would have the same value for all securities at a point in time t. – Mayou Aug 23 '13 at 20:34
  • @EMS Could you please explain more in detail how you run LASS and Fama-MacBeth in tandem? I think that is exactly the method I was looking for. – Mayou Aug 26 '13 at 12:18

0 Answers0