Question: This is a R programming question I have completed most of the solution I would just like a Chegg expert to make sure what I

This is a R programming question I have completed most of the solution I would just like a Chegg expert to make sure what I have done is corrected and also to explain the part 1cii and 1ciii and 1civ I do not know how to do these parts I will provide the commented code that I currently have the questions please show clear explanation screen shots of R and correct solution thanks

This is a R programming question I have completed most of the

#install.packages("faraway") library(faraway) head(prostate) #1a fit

summary(fit) #1b #install.packages("MASS") library(MASS) lambda_all

plot(ridge_fit) abline(v=lambda_all[which.min(ridge_fit$GCV)])

plot(ridge_fit$lambda,ridge_fit$GCV) abline(v=lambda_all[which.min(ridge_fit$GCV)])

j

#Computing the Ridge estimate which has the lowest GCV v

#1c

install.packages("glmnet") library(glmnet)

#i y = prostate[,5] X = as.matrix(prostate[,-5]) lasso_fit

#ii

# In order to choose the best lamba we will have to use the cv.glmnet function # Fitting the model using cv.glmnet function cv_fit

#iii

Consider the prostate dataset in the faraway package. Let lpsa be the outcome and treat all other variables as predictors. (a) Fit the full model (as with the previous assignment). You do not need to comment on the fit or parameters. (b) Compute the Ridge estimate which has the lowest GCV. Use 100 equally spaced lambdas between 0 and 10. Comment on any differences between the resulting estimate and the one form (a) (c) Compute the LASSO estimate using the following steps i. Fit the model using glmnet and plot the coefficients as a function of the penalty, comment on any patterns you see ii. Fit the model using cv.glmnet and plot the standard errors as a function of the penalty. Create a second "zoomed in" plot using ylim, so that one can clearly see where the minimum is reached. iii. Fit the model using glmnet but take A to be lambda min from cv.glmnet. Do the same thing, but now using lambda.1se. Compare the estimates with each other as well as with (a) and (b). iv. Take the predictors selected by lasso with "lambda. 1se" as the tuning param- eter and refit the model using lm. Comment on any differences with (a Consider the prostate dataset in the faraway package. Let lpsa be the outcome and treat all other variables as predictors. (a) Fit the full model (as with the previous assignment). You do not need to comment on the fit or parameters. (b) Compute the Ridge estimate which has the lowest GCV. Use 100 equally spaced lambdas between 0 and 10. Comment on any differences between the resulting estimate and the one form (a) (c) Compute the LASSO estimate using the following steps i. Fit the model using glmnet and plot the coefficients as a function of the penalty, comment on any patterns you see ii. Fit the model using cv.glmnet and plot the standard errors as a function of the penalty. Create a second "zoomed in" plot using ylim, so that one can clearly see where the minimum is reached. iii. Fit the model using glmnet but take A to be lambda min from cv.glmnet. Do the same thing, but now using lambda.1se. Compare the estimates with each other as well as with (a) and (b). iv. Take the predictors selected by lasso with "lambda. 1se" as the tuning param- eter and refit the model using lm. Comment on any differences with (a

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 Databases Questions!