helmert_coding: Helmert-Coding Contrast Matrix for a Factor
Description
Builds the Helmert-coding contrast matrix for a factor with \(a\)
levels. The \(k\)-th column contrasts the \((k + 1)\)-th level
against the average of all preceding levels, giving a fully
orthogonal set under equal sample sizes. The returned matrix has columns named after the
contrasted level rather than the numeric column names produced by
stats::contr.helmert().
Usage
helmert_coding(levels)
Value
A numeric \(a \times (a - 1)\) matrix with row names =
the factor levels and column names of the form
"L2_vs_prior", "L3_vs_prior", ...
Arguments
levels
Either an integer giving the number of levels or a
character / factor vector giving the level labels. If integer,
the labels default to "L1", "L2", ...
Why Helmert. Helmert contrasts are the canonical
"sequential" orthogonal contrast set: under equal-\(n\), every
column is orthogonal to every other column and to the intercept.
They are useful when the factor has a natural ordering and the
research questions are "does the \(k\)-th level differ from the
average of the preceding levels?"
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003).
Applied multiple regression/correlation analysis for the
behavioral sciences (3rd ed.). Lawrence Erlbaum.