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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started