Learn R Programming

faux (version 1.2.1)

contr_code_poly: 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)

Value

the factor with contrasts set

Arguments

fct

the factor to contrast code (or a vector)

levels

the levels of the factor in order

Examples

Run this code
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()

Run the code above in your browser using DataLab