factor_col: The factor column to use, eg data$gender
code_by: Either a matrix or a function
reference_level: The level to use as the reference level, default NA
set_intercept: The intercept to use, default NA
drop_trends: Whether to drop trends, default NA
labels: Labels to use in the contrast matrix, must equal number of contrasts
as_is: Logical, default FALSE, whether to suppress auto switching of the reference level to the first level if not specified
...: Additional arguments to be passed to use_contrast_function, specifically, which level you want the reference level to be
Returns
A contrast coding matrix with labels and proper reference level
Examples
# Create a contrast matrix given some factor vector with the specified# reference leveluse_contrasts(gl(5,2), sum_code, reference_level =3)# Set column labels; order for labels is the same as the column indicesuse_contrasts(gl(3,2), scaled_sum_code, labels = c("2-1","3-1"))my_data <- mtcars
my_data$gear <- factor(mtcars$gear)MASS::fractions(use_contrasts(my_data$gear, helmert_code))