Learn R Programming

mixlm (version 1.4.0)

contr.weighted: Contrast matrix for weighted effect coding

Description

Weighted contrast coding for linear models.

Usage

contr.weighted(x, base)

Value

A matrix with n rows and n-1 values.

Arguments

x

factor for which a contrast matrix should be made.

base

factor level used as basis for contrast coding. Default is the (first) level with maximum frequency.

Author

Kristian Hovde Liland

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.

References

Nieuwenhuis, R.; Grotenhuis, M.; Pelzer, B. Weighted Effect Coding for Observational Data with wec. R. J. 2017, 9, 477-485.

See Also

Examples

Run this code
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")

Run the code above in your browser using DataLab