Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #896 #897

Merged
merged 2 commits into from Jul 13, 2020
Merged

Fix issue #896 #897

merged 2 commits into from Jul 13, 2020

Conversation

rudeboybert
Copy link
Contributor

Attempt at fixing #896. Here is the proposed behavior of augment.lm()

library(tidyverse)
library(broom)
 
# Prep mtcars
mtcars <- mtcars %>%
  rownames_to_column(var = "automobile") %>%
  mutate(cyl = as.factor(cyl)) %>% 
  select(mpg, hp, cyl)

# Fit lm model with y = mpg
mpg_model <- lm(mpg ~ hp + cyl, data = mtcars)

# Use newdata. Output has .resid variable
mtcars %>% 
  augment(mpg_model, newdata = .)
#> # A tibble: 32 x 5
#>      mpg    hp cyl   .fitted  .resid
#>    <dbl> <dbl> <fct>   <dbl>   <dbl>
#>  1  21     110 6        20.0  0.962 
#>  2  21     110 6        20.0  0.962 
#>  3  22.8    93 4        26.4 -3.61  
#>  4  21.4   110 6        20.0  1.36  
#>  5  18.7   175 8        15.9  2.78  
#>  6  18.1   105 6        20.2 -2.06  
#>  7  14.3   245 8        14.2  0.0602
#>  8  24.4    62 4        27.2 -2.76  
#>  9  22.8    95 4        26.4 -3.57  
#> 10  19.2   123 6        19.7 -0.526 
#> # … with 22 more rows

# Use newdata without y. Output does not have .resid variable as expected, and
# no longer has warning message from v0.7.0
mtcars %>% 
  select(-mpg) %>% 
  augment(mpg_model, newdata = .)
#> # A tibble: 32 x 3
#>       hp cyl   .fitted
#>    <dbl> <fct>   <dbl>
#>  1   110 6        20.0
#>  2   110 6        20.0
#>  3    93 4        26.4
#>  4   110 6        20.0
#>  5   175 8        15.9
#>  6   105 6        20.2
#>  7   245 8        14.2
#>  8    62 4        27.2
#>  9    95 4        26.4
#> 10   123 6        19.7
#> # … with 22 more rows

Created on 2020-07-13 by the reprex package (v0.3.0)

@simonpcouch
Copy link
Collaborator

Looks great, thanks!

@simonpcouch simonpcouch merged commit ce91d5b into tidymodels:master Jul 13, 2020
simonpcouch added a commit that referenced this pull request Jul 13, 2020
@alexpghayes
Copy link
Collaborator

alexpghayes commented Jul 13, 2020 via email

@rudeboybert
Copy link
Contributor Author

I figured. Please do keep me in the loop. I'm curious to see how the pros do it!

@github-actions
Copy link

github-actions bot commented Mar 7, 2021

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants