Learn R Programming

faux (version 1.2.1)

contr_code_difference: Difference code a factor

Description

Difference coding sets the grand mean as the intercept. Each contrast compares one level with the previous level.

Usage

contr_code_difference(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(between = list(pet = c("cat", "dog", "ferret")), 
                 mu = c(2, 4, 9), empirical = TRUE, plot = FALSE)
                 
df$pet <- contr_code_difference(df$pet)
lm(y ~ pet, df) %>% broom::tidy()

Run the code above in your browser using DataLab