contr.weighted | R Documentation |
Weighted contrast coding for linear models.
contr.weighted(x, base)
x |
|
base |
|
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
.
A matrix
with n
rows and n-1
values.
contr.weighted
cannot be used directly as a replacement for other
contrasts by name, but must be used via contrasts matrix computations.
Kristian Hovde Liland
Nieuwenhuis, R.; Grotenhuis, M.; Pelzer, B. Weighted Effect Coding for Observational Data with wec. R. J. 2017, 9, 477-485.
lm
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.