Update to latest modelr

This commit is contained in:
hadley
2016-06-15 14:10:48 -05:00
parent 9267d69365
commit 820405f66d
4 changed files with 104 additions and 81 deletions

View File

@@ -76,7 +76,7 @@ mod <- my_model(df)
rmse(mod, df)
grid <- df %>% expand(x = seq_range(x, 50))
preds <- grid %>% add_predictions(y = mod)
preds <- grid %>% add_predictions(mod, var = "y")
df %>%
ggplot(aes(x, y)) +
@@ -98,25 +98,25 @@ Obviously it does much worse. But in real-life you can't easily go out and reco
```{r}
boots <- rerun(100, df %>% mutate(y = true_model(x)))
mods <- map(boots, my_model)
preds <- map2_df(list(grid), mods, ~ add_predictions(.x, y = .y), .id = "id")
preds <- map2_df(list(grid), mods, add_predictions, .id = "id")
preds %>%
ggplot(aes(x, y, group = id)) +
ggplot(aes(x, pred, group = id)) +
geom_line(alpha = 1/3)
```
```{r}
boot <- bootstrap(df, 100)
boot <- modelr::bootstrap(df, 100)
mods <- boot$strap %>% map(safely(my_model)) %>% transpose()
ok <- mods$error %>% map_lgl(is.null)
```
```{r}
preds <- map2_df(list(grid), mods$result[ok], ~ add_predictions(.x, y = .y), .id = "id")
preds <- map2_df(list(grid), mods$result[ok], add_predictions, .id = "id")
preds %>%
ggplot(aes(x, y, group = id)) +
ggplot(aes(x, pred, group = id)) +
geom_line(alpha = 1/3)
```