Skip to content

No formula and adding a step causes all variables to have role predictor role #296

@olangfor

Description

@olangfor

Hi,

Firstly, thank you for this wonderful package.

I have query regarding the behaviour of adding a step (example below uses step_dummy). When I don't add a formula and perform juice(prepped object, all_predictors()), this returns all variables. It seems by not having a role, then adding step it makes all variables have a role of predictor.

Please see the examples below. I've tried to illustrate the issue in the first one, with expected behaviour in the next two examples.

Please excuse me if I've misused the package.

Best wishes,

Oli

library(recipes); 
library(nlme) # for data

# Add individual steps
obj_rec <- recipe(x = as.data.frame(Orthodont)) %>% 
  add_role(distance, new_role = 'outcome') %>%
  add_role(age, new_role = 'predictor') %>%
  add_role(Sex, new_role = 'predictor')  %>%
  step_dummy(Sex) 
obj_prep <- prep(obj_rec, training = Orthodont, retain = TRUE)
X <- juice(obj_prep, all_predictors()) 
head(X) # Expected?
y <- juice(obj_prep, all_outcomes()) 
head(y)

# No step_dummy
obj_rec <- recipe(x = as.data.frame(Orthodont)) %>% 
  add_role(distance, new_role = 'outcome') %>%
  add_role(age, new_role = 'predictor') %>%
  add_role(Sex, new_role = 'predictor') 
obj_prep <- prep(obj_rec, training = Orthodont, retain = TRUE)
X <- juice(obj_prep, all_predictors()) 
head(X)
y <- juice(obj_prep, all_outcomes()) 
head(y)


# Formula method works fine
obj_rec <- recipe(distance ~ age + Sex, data = as.data.frame(Orthodont)) %>% 
  step_dummy(Sex) 
obj_prep <- prep(obj_rec, training = Orthodont, retain = TRUE)
X <- juice(obj_prep, all_predictors()) 
head(X)
y <- juice(obj_prep, all_outcomes()) 
head(y)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions