Building models based on the same predictors but differnet outcomes

Hello, I need to build models based on the same "predictor" variables but different "outcome" variables. I noticed that recipes could have multiple "outcome" variables, such as :

library(tidymodels)

recipe(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width, data = iris) %>% 
  step_naomit(has_role("outcome"), skip = FALSE) %>% 
  summary()
#> # A tibble: 4 × 4
#>   variable     type    role      source  
#>   <chr>        <chr>   <chr>     <chr>   
#> 1 Petal.Length numeric predictor original
#> 2 Petal.Width  numeric predictor original
#> 3 Sepal.Length numeric outcome   original
#> 4 Sepal.Width  numeric outcome   original

Created on 2022-10-28 with reprex v2.0.2

Just for confirmation, does it mean the different outcome variables will be handled respectively in the following data preprocessing and modelling? For example:

library(tidymodels)

linear_reg() %>% 
  set_engine("lm") -> model

# outcome: Sepal.Length
recipe(Sepal.Length ~ Petal.Length + Petal.Width, data = iris) %>% 
  step_naomit(has_role("outcome"), skip = FALSE) -> rec_1

workflow() %>% 
  add_recipe(rec_1) %>% 
  add_model(model) %>% 
  fit(data = iris)
#> ══ Workflow [trained] ══════════════════════════════════════════════════════════
#> Preprocessor: Recipe
#> Model: linear_reg()
#> 
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> 1 Recipe Step
#> 
#> • step_naomit()
#> 
#> ── Model ───────────────────────────────────────────────────────────────────────
#> 
#> Call:
#> stats::lm(formula = ..y ~ ., data = data)
#> 
#> Coefficients:
#>  (Intercept)  Petal.Length   Petal.Width  
#>       4.1906        0.5418       -0.3196

# outcome: Sepal.Width
recipe(Sepal.Width ~ Petal.Length + Petal.Width, data = iris) %>% 
  step_naomit(has_role("outcome"), skip = FALSE) -> rec_2

workflow() %>% 
  add_recipe(rec_2) %>% 
  add_model(model) %>% 
  fit(data = iris)
#> ══ Workflow [trained] ══════════════════════════════════════════════════════════
#> Preprocessor: Recipe
#> Model: linear_reg()
#> 
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> 1 Recipe Step
#> 
#> • step_naomit()
#> 
#> ── Model ───────────────────────────────────────────────────────────────────────
#> 
#> Call:
#> stats::lm(formula = ..y ~ ., data = data)
#> 
#> Coefficients:
#>  (Intercept)  Petal.Length   Petal.Width  
#>       3.5870       -0.2571        0.3640

# outcomes: Sepal.Length & Sepal.Width
recipe(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width, data = iris) %>% 
  step_naomit(has_role("outcome"), skip = FALSE) -> rec_12

workflow() %>% 
  add_recipe(rec_12) %>% 
  add_model(model) %>% 
  fit(data = iris)
#> ══ Workflow [trained] ══════════════════════════════════════════════════════════
#> Preprocessor: Recipe
#> Model: linear_reg()
#> 
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> 1 Recipe Step
#> 
#> • step_naomit()
#> 
#> ── Model ───────────────────────────────────────────────────────────────────────
#> 
#> Call:
#> stats::lm(formula = cbind(Sepal.Length, Sepal.Width) ~ ., data = data)
#> 
#> Coefficients:
#>               Sepal.Length  Sepal.Width
#> (Intercept)    4.1906        3.5870    
#> Petal.Length   0.5418       -0.2571    
#> Petal.Width   -0.3196        0.3640

Created on 2022-10-28 with reprex v2.0.2

The results seem that different outcome variables are handled respectively.

And I was wondering, is there a vignette/document to demonstrate this multi-outcome situation? Thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.