contr.weighted {mixlm} | R Documentation |
Contrast matrix for weighted effect coding
Description
Weighted contrast coding for linear models.
Usage
contr.weighted(x, base)
Arguments
x |
|
base |
|
Details
Different from the contrasts made throught the stats
package functions
this contrast requires a full factor
vector as input rather than its
respective levels
as weights are computed from the frequencies of the
factor
levels
.
Value
A matrix
with n
rows and n-1
values.
Note
contr.weighted
cannot be used directly as a replacement for other
contrasts by name, but must be used via contrasts matrix computations.
Author(s)
Kristian Hovde Liland
References
Nieuwenhuis, R.; Grotenhuis, M.; Pelzer, B. Weighted Effect Coding for Observational Data with wec. R. J. 2017, 9, 477–485.
See Also
Examples
balanced <- factor(c(rep("A", 3), rep("B", 3), rep("C", 3)))
unbalanced <- factor(c(rep("A", 3), rep("B", 3), rep("C", 2)))
# Weighted coding when applied to balanced data
contr.weighted(balanced)
# Weighted coding when applied to unbalanced data (default base level)
contr.weighted(unbalanced)
# Weighted coding when applied to unbalanced data (base level = "C")
contr.weighted(unbalanced, "C")
[Package mixlm version 1.3.0 Index]