library(knitr) opts_chunk$set(echo=FALSE, fig.align='center', fig.width=4, fig.height=3, cache=TRUE, autodep=TRUE, cache.comments=FALSE, message=FALSE, warning=FALSE) library(knitr) library(tidyverse) opts_chunk$set(echo=FALSE, fig.align='center', fig.width=8, fig.height=8, cache=TRUE, autodep=TRUE, cache.comments=FALSE, message=FALSE, warning=FALSE)
Your goal is to use this data to predict economic mobility. Note that there are generally more observations than predictors. You should definitely exclude some variables in the data (which ones?).
mob = read.csv('mobility.csv')
Using glmnet
, estimate 4 models: the linear model, ridge regression, the lasso, and the elastic net ($\alpha=.5$). Don't use the variables ID
, Name
, or State
(Why?)
Plot the CV curves for each of the three regularized models (easy).
Use lambda.min
to get a particular model for each of the regularized ones.
Plot the coefficients for each of the 4 models on one figure. What do you notice? Which features are most important?
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.