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!