Skip to content

feature request: add way to remove intercept in linear_reg() lm #975

@jospueyo

Description

@jospueyo

Feature: step_rm_intercept()

In situations when a linear model without intercept is needed, recipes does not provide a straightforward method. If you try the conventional way:

library(tidymodels)

rec <- recipe(mpg ~ cyl -1, data = mtcars)
#> Error in `recipe()`:
#> ! `-` is not allowed in a recipe formula. Use `step_rm()` instead.
#> Backtrace:
#>     ▆
#>  1. ├─recipes::recipe(mpg ~ cyl - 1, data = mtcars)
#>  2. └─recipes:::recipe.formula(mpg ~ cyl - 1, data = mtcars)
#>  3.   └─rlang::abort("`-` is not allowed in a recipe formula. Use `step_rm()` instead.")

I found a workaround in stackoverflow, where, by the way, @juliasilge already suggested to include this feature.

However, I do not know how to integrate this workaround when multiple models are set using workflow_set because the add_model step, suggested in the above answer, is not used:

library(tidymodels)

rec1 <- recipe(mpg ~ cyl + hp, data = mtcars)
rec2 <- rec1 |>
  step_rm(hp)

workflow_set(list(rec1, rec2), list(lm = linear_reg()))
#> # A workflow set/tibble: 2 × 4
#>   wflow_id    info             option    result    
#>   <chr>       <list>           <list>    <list>    
#> 1 recipe_1_lm <tibble [1 × 4]> <opts[0]> <list [0]>
#> 2 recipe_2_lm <tibble [1 × 4]> <opts[0]> <list [0]>

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

Thanks for the package!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorfeaturea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions