contr_code_poly: Polynomial code a factor

View source: R/contrasts.R

contr_code_polyR 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()


faux documentation built on April 20, 2023, 9:13 a.m.