R's stats::contr.helmert() function is unscaled, meaning that you need to scale the coefficients of a model fit to get the actual comparisons of interest. This version will automatically scale the contrast matrix such that the coefficients are the expected scaled values.
helmert_code(n)
Arguments
n: Integer umber of factor levels to compute contrasts for.
Returns
A contrast matrix with dimensions n rows and (n-1) columns.
Details
Helmert coding compares each level to the total mean of all levels that have come before it. Differs from backward difference coding, which compares only pairs of levels (not a level to a cumulative mean of levels)
Example interpretation for a 4 level factor:
Intercept = Grand mean (mean of the means of each level)