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.
Diese Übung ist Teil des Kurses
Case Study: Exploratory Data Analysis in R
Anleitung zur Übung
- Load the
broompackage. - Use the
map()function to apply thetidy()function to each linear model in themodelcolumn, creating a new column calledtidied.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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 = .)))