I am trying to run a LASSO Regression via the enet function (from the elasticnet library) in R on each and every one of a large number of individual csv file formatted datasets all within the same file folder for a research project where each dataset has 1 column with observations on the dependent variable called Y, and 30 columns with obs on the independent variables, called X1:X30 respectively.
I have absolutely no idea how to do this or even what search terms to use to look it up, I have already tried in both Google and Bing several times. I believe that the only packages my code as it stands requires are: leaps lars stats plyr dplyr readr elasticnet This is my code to run the LASSO Regression itself once on of you nice people help me either load the data beforehand or adjust this function in order to do that part in the function itself (obviously, I made up the dataframe names for the x & y arguments in the enet() function for this post/question):
## Attempt 2: Run a LASSO regression using
## the enet function from the elasticnet library
set.seed(11)
library(elasticnet)
enet_LASSO <- enet(x = as.matrix(df_all_obs_on_all_of_the_IVs),
y = df_all_obs_on_the_DV,
lambda = 0, normalize = FALSE)
print(enet_LASSO)
# In order to ascertain which predictors/regressors are still
# included in the version of the model after running a
# LASSO regression on it for the purpose of variable selection,
# I am going to use the 'predict' method from the stats package.
LASSO_coeffs <- predict(enet_LASSO,
x = as.matrix(df_all_obs_on_all_of_the_IVs),
s = 0.1, mode = "fraction", type = "coefficients")
print(LASSO_coeffs)
Again, I am still a newbie/novice at coding in general. My background is much stronger on the statistics, probability, and econometrics end of data science than the coding side to be honest. But I am trying to learn.