Questions

  1. Now fit a lasso model to the simulated data from the previous exercise, again using \(X,X^2,\cdots,X^{10}\) as predictors. Don’t forget to load the necessary package(s) and make use of the model.matrix function. Use cross-validation to select the optimal value of \(\lambda\), store this value in bestlam. Now build the model with the optimal lambda value and store the coefficient estimates in coef.lasso.


Assume that: