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

add residuals when outcome is available in augment.workflow() #201

Merged
merged 1 commit into from Jul 25, 2023

Conversation

simonpcouch
Copy link
Contributor

Closes #131. Companion PR with tidymodels/parsnip#961.

library(workflows)
library(parsnip)

wf_fit <- workflow(mpg ~ ., linear_reg()) %>% fit(mtcars)
spec_fit <- fit(linear_reg(), mpg ~ ., mtcars)

extract_fit_parsnip(wf_fit)$preproc$y_var
#> [1] "mpg"
spec_fit$preproc$y_var
#> [1] "mpg"

augment(wf_fit, mtcars)
#> # A tibble: 32 × 13
#>    .pred  .resid   mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear
#>  * <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  22.6 -1.60    21       6  160    110  3.9   2.62  16.5     0     1     4
#>  2  22.1 -1.11    21       6  160    110  3.9   2.88  17.0     0     1     4
#>  3  26.3 -3.45    22.8     4  108     93  3.85  2.32  18.6     1     1     4
#>  4  21.2  0.163   21.4     6  258    110  3.08  3.22  19.4     1     0     3
#>  5  17.7  1.01    18.7     8  360    175  3.15  3.44  17.0     0     0     3
#>  6  20.4 -2.28    18.1     6  225    105  2.76  3.46  20.2     1     0     3
#>  7  14.4 -0.0863  14.3     8  360    245  3.21  3.57  15.8     0     0     3
#>  8  22.5  1.90    24.4     4  147.    62  3.69  3.19  20       1     0     4
#>  9  24.4 -1.62    22.8     4  141.    95  3.92  3.15  22.9     1     0     4
#> 10  18.7  0.501   19.2     6  168.   123  3.92  3.44  18.3     1     0     4
#> # ℹ 22 more rows
#> # ℹ 1 more variable: carb <dbl>
augment(spec_fit, mtcars)
#> # A tibble: 32 × 13
#>    .pred  .resid   mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear
#>    <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  22.6 -1.60    21       6  160    110  3.9   2.62  16.5     0     1     4
#>  2  22.1 -1.11    21       6  160    110  3.9   2.88  17.0     0     1     4
#>  3  26.3 -3.45    22.8     4  108     93  3.85  2.32  18.6     1     1     4
#>  4  21.2  0.163   21.4     6  258    110  3.08  3.22  19.4     1     0     3
#>  5  17.7  1.01    18.7     8  360    175  3.15  3.44  17.0     0     0     3
#>  6  20.4 -2.28    18.1     6  225    105  2.76  3.46  20.2     1     0     3
#>  7  14.4 -0.0863  14.3     8  360    245  3.21  3.57  15.8     0     0     3
#>  8  22.5  1.90    24.4     4  147.    62  3.69  3.19  20       1     0     4
#>  9  24.4 -1.62    22.8     4  141.    95  3.92  3.15  22.9     1     0     4
#> 10  18.7  0.501   19.2     6  168.   123  3.92  3.44  18.3     1     0     4
#> # ℹ 22 more rows
#> # ℹ 1 more variable: carb <dbl>

Created on 2023-05-05 with reprex v2.0.2

@simonpcouch simonpcouch requested a review from hfrick May 5, 2023 22:09
Copy link
Member

@hfrick hfrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice new feature! 🌲

@simonpcouch simonpcouch merged commit e6e7150 into main Jul 25, 2023
10 checks passed
@simonpcouch simonpcouch deleted the resid-131 branch July 25, 2023 14:41
@github-actions
Copy link

github-actions bot commented Aug 9, 2023

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 Aug 9, 2023
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.

augmenting regression models should add the residual if the outcome is available
2 participants