contr_code_poly {faux} | R Documentation |
Polynomial code a factor
Description
Polynomial coding sets the grand mean as the intercept. Each contrast tests a trend (linear, quadratic, cubic, etc.). This is only suitable for ordered factors.
Usage
contr_code_poly(fct, levels = NULL)
Arguments
fct |
the factor to contrast code (or a vector) |
levels |
the levels of the factor in order |
Value
the factor with contrasts set
Examples
df <- sim_design(within = list(time = 1:6),
mu = 1:6 + (1:6-3.5)^2,
long = TRUE, plot = FALSE)
df$time <- contr_code_poly(df$time)
lm(y ~ time, df) %>% broom::tidy()
[Package faux version 1.2.1 Index]