View source: R/contr.helmert.weighted.R
contr.helmert.weighted | R Documentation |
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.
contr.helmert.weighted( x, reference.levels = levels(x)[-length(levels(x))], na.rm = FALSE )
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 |
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.
A matrix with n
rows and k
columns, where n
is
the number of levels and k=n-1
.
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.
center.numeric
for centering numeric variables and
contr.helmert.unweighted
for unweighted Helmert contrasts.
cuedata <- as.factor(c('ValidCue', 'ValidCue', 'InvalidCue', 'NoCue', 'InvalidCue', 'NoCue', 'InvalidCue')) contr.helmert.weighted(cuedata, reference.levels=c('ValidCue','InvalidCue'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.