Deviation Coding

Deviation coding represents a treatment factor using a sum-to-zero constraint, so coefficients describe how treatment means differ from the grand mean.

Under deviation coding,

$$ \tau_1 + \tau_2 + \cdots + \tau_k = 0. $$

This coding is convenient when the grand mean is the natural baseline rather than a reference treatment.

R

contrasts(dat$treatment) <- contr.sum
fit <- lm(y ~ treatment, data = dat)
model.matrix(fit)