library(dplyr)
library(tibble)
library(recipes)
library(car)
param <- getOption("contrasts")
go_deviance <- param
# traditional `contr.sum` does not name levels, so use function from `car` package
go_deviance["unordered"] <- "contr.Sum"
options(contrasts = go_deviance)
tib_example <- tibble(fct_example = factor(c("a", "b", "c", "d")),
chr_example = c("al", "ben", "cam", "cam"),
target_example = rnorm(4))
recipe(target_example ~fct_example + chr_example, data = tib_example) %>%
step_dummy(all_nominal()) %>%
# step_interact(~ contains("fct"):contains("chr")) %>% # how to set-up an interaction
prep(retain = TRUE) %>%
juice() %>%
glimpse()
#> Observations: 4
#> Variables: 6
#> $ target_example <dbl> 0.3598693, 0.1322287, 1.7492702, -0.4346045
#> $ fct_example_X.S.a. <dbl> 1, 0, 0, -1
#> $ fct_example_X.S.b. <dbl> 0, 1, 0, -1
#> $ fct_example_X.S.c. <dbl> 0, 0, 1, -1
#> $ chr_example_X.S.al. <dbl> 1, 0, -1, -1
#> $ chr_example_X.S.ben. <dbl> 0, 1, -1, -1
# Looks like it is working correctly... had thought it wasn't handling
# "contr.Sum" correctly, and was doing dummy encoding, but looks to be workingCreated on 2019-02-27 by the reprex package (v0.2.1)