Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(dplyr)
- library(tidyr)
- library(purrr)
- library(broom)
- library(ggplot2)
- f1 = hwy ~ cyl
- f2 = hwy ~ displ
- f3 = hwy ~ cyl + displ
- lin_mod = function(formula) {
- function(data) {
- lm(formula, data = data)
- }
- }
- mpg %>%
- group_by(manufacturer) %>%
- nest() %>%
- mutate(model = map(data, lin_mod(f1)),
- aug = map(model, augment),
- res = map(aug, ".resid"))
- mpg %>%
- group_by(manufacturer) %>%
- nest() %>%
- mutate(model1 = map(data, lin_mod(f1)),
- aug1 = map(model1, augment),
- res1 = map(aug1, ".resid"),
- model2 = map(data, lin_mod(f2)),
- aug2 = map(model2, augment),
- res2 = map(aug2, ".resid"),
- model3 = map(data, lin_mod(f3)),
- aug3 = map(model3, augment),
- res3 = map(aug3, ".resid"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement