contr.mean: Contrast Matrix for Constraints about the Mean

View source: R/util.r View source: R/contrast.r

contrastR Documentation

Contrast Matrix for Constraints about the Mean

Description

Return a matrix of contrasts for constraints about the mean.

Usage

contr.mean(n, contrasts = TRUE)

Arguments

n

A vector of levels for a factor or the number of levels.

contrasts

A logical value indicating whether or not contrasts should be computed.

Details

This function corrects contr.sum to display labels properly.

Value

A matrix of computed contrasts with n rows and k columns, with k=n-1 if contrasts is TRUE and k=n if contrasts is FALSE. The columns of the resulting matrices contain contrasts which can be used for coding a factor with n levels.

See Also

contrasts, C, and contr.sum.

Examples

oldop <- options(contrasts=c("contr.sum","contra.poly"))
y <- rnorm(30)
x <- gl(3,10,labels=c("First","Second","Third"))
glm(y~x)
options(contrasts=c("contr.mean","contra.poly"))
x <- gl(3,10,labels=c("First","Second","Third"))
glm(y~x)
options(oldop)

swihart/rmutil documentation built on Oct. 30, 2022, 9:33 a.m.