contr.helmert.weighted: Weighted Helmert Contrasts for Factor Variables

View source: R/contr.helmert.weighted.R

contr.helmert.weightedR Documentation

Weighted Helmert Contrasts for Factor Variables

Description

Returns a matrix of Helmert contrasts, scaled so that the resulting contrast estimates (in an ANOVA or regression model) correspond to the difference between the levels (categories) being compared, and weighted so that the mean of each contrast is zero.

Usage

contr.helmert.weighted(
  x,
  reference.levels = levels(x)[-length(levels(x))],
  na.rm = FALSE
)

Arguments

x

a factor variable (or variable that can be coerced to a factor) for which mean-centered Helmert contrasts should be calculated.

reference.levels

vector specifying, in order, the category treated as the reference level (i.e., assigned the next negative value) in each successive contrast.

na.rm

logical indicating whether NA values should be ignored when computing the contrasts.

Details

Helmert contrasts compare the second level with the first, the third with the average of the first two, and so on. As with other contrasts, they are orthogonal to each other and to the intercept.

When the levels differ in frequency, weighted coding is appropriate if the differences in frequency in the sample correspond to actual differences in the population (e.g., some college majors are more common than others). (If the differences in frequency instead represent incidental differences in the sample, unweighted coding may be more appropriate.)

If all of the factor levels are equally common, there is no difference between weighted and unweighted coding.

Value

A matrix with n rows and k columns, where n is the number of levels and k=n-1.

References

Cohen, J., Cohen, P., West, S.G., & Aiken, L.S. (2002). Categorical or nominal independent variables. In Applied multiple regression/ correlation analysis for the behavioral sciences (3rd ed., pp. 302-353). Mahwah, NJ: Lawrence Erlbaum Associates.

See Also

center.numeric for centering numeric variables and contr.helmert.unweighted for unweighted Helmert contrasts.

Examples

cuedata <- as.factor(c('ValidCue', 'ValidCue',
   'InvalidCue', 'NoCue', 'InvalidCue', 'NoCue', 'InvalidCue'))
contr.helmert.weighted(cuedata, reference.levels=c('ValidCue','InvalidCue'))

sfraundorf/psycholing documentation built on April 23, 2022, 2:50 a.m.