Run a linear model
You can use map()
to do more than just take the square root of a number or simulate data. You can also use map()
to loop over different inputs to run several models, each using the unique values of a given list element. You can also then iterate over the models you've run to create the model summaries and look at the results.
The lists sites
and list_of_df
are preloaded.
Diese Übung ist Teil des Kurses
Foundations of Functional Programming with purrr
Anleitung zur Übung
- Pipe
list_of_df
intomap()
along with thelm()
linear model function, to comparea
as the response andb
as the predictor variable.- Use the syntax:
lm(response ~ predictor, data = )
- Use the syntax:
- Then pipe the linear model output into
map()
and generate thesummary()
of each model.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Map over the models to look at the relationship of a vs. b
___ %>%
map(~ ___(___ ~ ___, data = .)) %>%
map(___)