# 1. Effects coding for a 4-level factor:
effects_coding(c("low", "med", "high", "very_high"))
# 2. With "low" as the reference category:
effects_coding(c("low", "med", "high", "very_high"),
reference = "low")
# 3. Assign to a factor for modeling:
f <- factor(c("a", "b", "c", "a", "b", "c"))
contrasts(f) <- effects_coding(levels(f))
model.matrix(~ f)
Run the code above in your browser using DataLab