reverse_helmert: Reverse Helmert Contrasts

View source: R/reverse_helmert.R

reverse_helmertR Documentation

Reverse Helmert Contrasts

Description

Creates a Reverse Helmert contrast matrix by reversing both the rows and columns of a standard Helmert contrast matrix.

Usage

reverse_helmert(n, contrasts = TRUE)

Arguments

n

A factor, whose levels are used; a vector of level names; or a whole number specifying the number of factor levels (at least 2).

contrasts

Logical indicating whether to return contrasts (default TRUE).

Details

Reverse Helmert contrasts compare each factor level, except the last, with the mean of the subsequent levels.

The contrast matrix is constructed from stats::contr.helmert() by reversing the row order and subsequently the column order. This preserves the Helmert coding structure while reversing the direction in which the sequential comparisons are defined.

Value

A numeric matrix with n rows and n - 1 columns containing Reverse Helmert contrasts.

See Also

stats::contr.helmert()

Examples

reverse_helmert(3)
reverse_helmert(c("Control", "Trt1", "Trt2"))
reverse_helmert(factor(c("b", "a", "b", "c")))

dat <- data.frame(
  group = factor(rep(c("A", "B", "C"), each = 10)),
  y = rnorm(30)
)

contrasts(dat$group) <- reverse_helmert(3)
model <- lm(y ~ group, data = dat)


MoPlot documentation built on Nov. 25, 2026, 5:10 p.m.