contr.helmert.unweighted: Unweighted Helmert Contrast Matrices

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

contr.helmert.unweightedR Documentation

Unweighted Helmert Contrast Matrices

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. The contrasts may be computed either based on a numerical number of levels or a vector of data.

Usage

contr.helmert.unweighted(
  x,
  reference.levels = my.levels[-length(my.levels)],
  n = NULL
)

Arguments

x

a factor variable (or variable that can be coerced to a factor) for which 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.

n

a vector of levels for a factor, or the number of levels, which can be provided instead of x.

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, unweighted coding is appropriate if the differences in frequency in the sample are merely incidental (e.g., both conditions were intended to be presented equally frequently, but by chance there are more observations from one condition than another). (If the differences in frequency instead represent genuine differences in the population, weighted coding may be more appropriate.)

If all of the factor levels are equally common, there is no difference between unweighted and weighted 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

contr.helmert.weighted for weighted Helmert contrasts, and contrasts and contr.helmert.

Examples

contr.helmert.unweighted(n=4)

contr.helmert.unweighted(n=c('Active','Passive'), reference.levels=1)

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

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