contr_code_poly: Polynomial code a factor

Description Usage Arguments Value Examples

View source: R/contrasts.R

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

1

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

1
2
3
4
5
6
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()

faux documentation built on Sept. 14, 2021, 1:08 a.m.