View source: R/reverse_helmert.R
| reverse_helmert | R Documentation |
Creates a Reverse Helmert contrast matrix by reversing both the rows and columns of a standard Helmert contrast matrix.
reverse_helmert(n, contrasts = TRUE)
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 |
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.
A numeric matrix with n rows and n - 1 columns containing
Reverse Helmert contrasts.
stats::contr.helmert()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.