Overview
We will use the online spending application. First, create the variable yspend (10,000 observations with spending for each household) and the sparse matrix xweb, following the lecture notes (you can just copy the code from the lecture notes, and you don’t need to include this data preparation step when turning in the problem set).
We will run an out-of-sample experiment to see how well cross-validated lasso performs. First, draw a random sample of size n = 8, 000 from the original 10, 000 observations, without replacement. We will refer to these observations X1, . . . , Xn and Y1, . . . , Yn as the “estimation” sample. We will refer to the remaining m = 2, 000 observations Xn+1, . . . , Xn+m and Yn+1, . . . , Yn+m as the “holdout” sample. (a) (15 points) Run 5-fold cross-validated lasso of log(yspend) on xweb on the estimation sample of n = 8, 000 observations. Report a plot of the out-of-sample cross validation error as a function of λ (you can use the plot command on the cv.gamlr object as in the lecture notes).
Question:
Run 5-fold cross-validated lasso of log(yspend) on xweb on the estimation sample of n = 8, 000 observations. Report a plot of the out-of-sample cross validation error as a function of λ (you can use the plot command on the cv.gamlr object as in the lecture notes).
Using R software to solve the problem, the data code is in the lecture note page 59