Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedR 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

Students also viewed these Databases questions

Question

who acts as a go - betwwen in the bond market?

Answered: 1 week ago

Question

1. Who will you assemble on the team?

Answered: 1 week ago

Question

4. Who would lead the group?

Answered: 1 week ago