Learn R Programming

rmutil (version 1.1.10)

contrast: Contrast Matrix for Constraints about the Mean

Description

Return a matrix of contrasts for constraints about the mean.

Usage

contr.mean(n, contrasts = TRUE)

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.

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.

See Also

Examples

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

Run the code above in your browser using DataLab