Conversation
Member
|
I think that {embed} is the right place for this. i'll try to look at this later this week! |
Author
|
This step can also be used for causal inference - and since it can be used with any other previous steps, it can also adjust non-linear terms. Here's a very simple example: library(embed)
#> Loading required package: recipes
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#>
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#>
#> step
n <- 500
set.seed(333)
dat <- tibble(
Z = rnorm(n),
X = 3^Z + 1.3 * Z^2 - rnorm(n),
Y = 30 * Z - 4 * X + 100 * rnorm(n)
)
plot(dat)rec <- recipe(Y ~ ., data = dat) |>
step_spline_b(Z, deg_free = 5) |>
step_adjust_linear(X, remove_vars = vars(starts_with("Z")))
baked <- prep(rec) |> bake(new_data = dat, stop_at = 2)
lm(Y ~ X, data = dat) # confounded
#>
#> Call:
#> lm(formula = Y ~ X, data = dat)
#>
#> Coefficients:
#> (Intercept) X
#> -6.202 -0.587
lm(Y ~ X, data = baked) # should be about ~4
#>
#> Call:
#> lm(formula = Y ~ X, data = baked)
#>
#> Coefficients:
#> (Intercept) X
#> 2.070 -3.199Created on 2026-09-23 with reprex v2.1.1 |
1 task
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR addresses the feature request in #275.
I have named the step
step_adjust_linear()- its functionality can be seen in the original issue.Here is the example from the docs:
Created on 2026-09-23 with reprex v2.1.1
Since the step does not depend on any package other than
statsI'm not sure if{embed}or{recipes}are the right place for it.