cumulative_split_code function

Cumulative split contrasts

Cumulative split contrasts

Contrast coding scheme that repeatedly dichotomizes the factor levels.

cumulative_split_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

This scheme is similar to Helmert contrasts, but instead of comparing one level to the accumulated mean of all previous levels, each comparison with this scheme splits the levels into two groups: those below and including the current level, and those above the current level. Conceptually this is similar to continuation ratio logits used in ordinal models. For example, with a four level factor with levels A, B, C, and D, the comparisons would be:

  • A vs. BCD
  • AB vs. CD
  • ABC vs. D

In other words, each comparison splits the levels into two groups. Each of these comparisons uses the cumulative mean of all the levels in each group. The intercept is the grand mean.

Examples

set.seed(111) mydf <- data.frame( grp = rep(c("a", "b", "c", "d"), each = 2000), val = c( rnorm(200, 2, 1), rnorm(200, 5, 1), rnorm(200, 7.5, 1), rnorm(200, 15, 1) ) ) |> set_contrasts(grp ~ cumulative_split_code | c("a-rest", "ab-rest", "abc-rest")) lm(val ~ grp, data = mydf)
  • Maintainer: Thomas Sostarics
  • License: MIT + file LICENSE
  • Last published: 2024-10-01