contr.deviation: Sets up deviation contrasts

View source: R/utility.r

contr.deviationR Documentation

Sets up deviation contrasts

Description

Deviation-coding is a contrast-coding scheme that compares each level to the average of the other levels. It is often confused with sum-coding, which compares each level to the average of all levels. In the binary case, deviation coding works out to \( (+0.5,-0.5) \); in the ternary case and beyond, the coding is a little bit more involved.

Usage

contr.deviation(n, contrasts = TRUE, sparse = FALSE)

Arguments

n

See contr.sum.

contrasts

See contr.sum.

sparse

See contr.sum.

Details

contr.deviation starts by calling contr.sum and hence accepts the same arguments as it does.

Value

A matrix of deviation-coded contrasts.

See Also

contr.sum

Examples

iris$Species <- contr.deviation(iris$Species)

buildmer documentation built on June 27, 2026, 1:06 a.m.