Learning Objectives

Motivation

Nest

Fit a model

Get model summaries

Unnest

mtcars exercise

Recall how we used the split() function in the iterators worksheet on the mtcars dataset to get the regression coefficient estimates of a regression of mpg on wt.

data("mtcars")
mtcars %>% 
  split(.$cyl) %>% 
  map(~lm(mpg ~ wt, data = .)) %>%
  map(~tidy(.)) %>%
  map_dbl(~.$estimate[2])
##      4      6      8 
## -5.647 -2.780 -2.192

Redo this exercise using the nest()-map()-unnest() workflow we just went through.