contr_code_sum {faux} | R Documentation |
Sum code a factor
Description
Sum coding sets the grand mean as the intercept. Each contrast compares one level with the grand mean.
Usage
contr_code_sum(fct, levels = NULL, omit = length(levels))
Arguments
fct |
the factor to contrast code (or a vector) |
levels |
the levels of the factor in order |
omit |
the level to omit (defaults to the last level) |
Value
the factor with contrasts set
Examples
df <- sim_design(between = list(pet = c("cat", "dog", "bird", "ferret")),
mu = c(2, 4, 9, 13), empirical = TRUE, plot = FALSE)
df$pet <- contr_code_sum(df$pet)
lm(y ~ pet, df) %>% broom::tidy()
df$pet <- contr_code_sum(df$pet, omit = "cat")
lm(y ~ pet, df) %>% broom::tidy()
df$pet <- contr_code_sum(df$pet, omit = 1)
lm(y ~ pet, df) %>% broom::tidy()
[Package faux version 1.2.1 Index]