Question: Use the code below to select the first 40 predictors in the meatspec dataset. Use the glmnet package to perform Ridge and LASSO analyses on

Use the code below to select the first 40 predictors in the meatspec dataset. Use the glmnet package to perform Ridge and LASSO analyses on the 40 predictors. You do not need to build training and test data sets for this exercise.Use 10-fold Cross Validation to pick the optimal lambdas.

Submit your program, output, and any graphs that are generated, and a short paragraph summarizing your results.

library(faraway)

library(glmnet)

data(meatspec,package="faraway")#the dataset meatspec is found in the faraway package

# Getting the dependent variable

y_var <- meatspec$fat

y_var

# Getting the independent variables

x_var <- as.matrix(meatspec[,(1:40)]) #includes the 40 variables V1 - V40

head(x_var,1L)

#continue with program to perform Ridge and LASSO.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!