Question: R language **code for part 1 and 2 has been provided, can someone help me to fill question 3 and 4 with the code i

R language **code for part 1 and 2 has been provided, canR language

**code for part 1 and 2 has been provided, can someone help me to fill question 3 and 4 with the code i provided? There is non way for me to upload the oj dataset

oj.csv dataset can be found right here https://github.com/TaddyLab/BDS/tree/master/examples

# Q3 LASSO

rm(list=ls())

## Q3.1

# Apply the LASSO for different values of $\lambda$. Draw a figure similar to the left of Figure 3.9 (p.92).

# load packages library(gamlr)

# read data oj = read.csv("oj.csv")

# create design matrix as data frame P = 15 X = data.frame(cbind(poly(oj$price, P)))

# Run cross validation for 100 values of lambda. # Note no sparse matrix because no factor variables. cv.sales = cv.gamlr(X, oj$sales, nlambda=100, lambda.start = Inf, lambda.min.ratio = 0.001)

# path plot plot(cv.sales$gamlr)

# MSE plot plot(cv.sales)

## Q3.2

# What is the value of $\lambda$ which has 25 non-zero coefficients (excluding the constant term)?

_____

## Q3.3

# CV-min cvmin = cv.sales$seg.min cvmin cv.sales$gamlr$lambda[cvmin] # 1se onese = cv.sales$seg.1se onese cv.sales$gamlr$lambda[onese] # AI aic = cv.sales$ aic

# BIC bic = _____ bic

## Q3.4

# which coefs for 1se rule? coef(cv.sales, select = "_____")

# post-lasso with glm postLasso = glm(_____) summary(postLasso)$coefficients

3 Lasso Again, suppose we want to predict sales using price for the oj dataset. We focus on the polynomial regression: sales = Be + Biprice + B2price? + ... + B15price15 + . 1. Apply the LASSO for different values of . Draw a figure similar to the left of Figure 3.9 (p.92). 2. What is the value of which has 5 non-zero coefficients (excluding the constant term)? 3. What is the best in terms of the min-CV rule? 4. Collect all the regressors which has non-zero coefficients according to the min-CV rule. Regress sales on these regressors using the glm function. (It is called the post-Lasso regression.) 3 Lasso Again, suppose we want to predict sales using price for the oj dataset. We focus on the polynomial regression: sales = Be + Biprice + B2price? + ... + B15price15 + . 1. Apply the LASSO for different values of . Draw a figure similar to the left of Figure 3.9 (p.92). 2. What is the value of which has 5 non-zero coefficients (excluding the constant term)? 3. What is the best in terms of the min-CV rule? 4. Collect all the regressors which has non-zero coefficients according to the min-CV rule. Regress sales on these regressors using the glm function. (It is called the post-Lasso regression.)

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!