Wrapper around stats::contr.treatment(). Returns a contrast
matrix where comparisons give differences between each comparison level and a
baseline reference level, while the intercept equals the first level of the
factor. See scaled_sum_code() for a function that centers
the intercept on the grand mean while retaining pairwise comparisons from a
reference level.
Usage
treatment_code(n)
Value
A contrast matrix with dimensions n rows and (n-1) columns.
Arguments
n
Integer umber of factor levels to compute contrasts for.
Details
For n levels of factors, generate a matrix with n-1 comparisons
where:
Reference level = 0
Comparison level = 1
All others = 0
Note that this function sets the first level (alphabetically) as the
reference level while stats::contr.SAS() sets the LAST level as the
reference level. However, in functions like
set_contrasts(), and enlist_contrasts(), the reference level is
automatically set to be the first level alphabetically.