Tidy each linear regression model
You've now performed a linear regression on each nested dataset and have a linear model stored in the list column model
. But you can't recombine the models until you've tidied each into a table of coefficients. To do that, you'll need to use map()
one more time and the tidy()
function from the broom
package.
Recall that you can simply give a function to map()
(e.g. map(models, tidy)
) in order to apply that function to each item of a list.
Cet exercice fait partie du cours
Case Study: Exploratory Data Analysis in R
Instructions
- Load the
broom
package. - Use the
map()
function to apply thetidy()
function to each linear model in themodel
column, creating a new column calledtidied
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Load the broom package
# Add another mutate that applies tidy() to each model
by_year_country %>%
nest(-country) %>%
mutate(model = map(data, ~ lm(percent_yes ~ year, data = .)))