Contrasts Attribute

DESCRIPTION:

Returns the matrix that is the contrasts attribute of a factor variable.

USAGE:

contrasts(x) 
contrasts(x, how.many=<<see below>>) <- value 

REQUIRED ARGUMENTS:

x
a factor or ordered factor.

OPTIONAL ARGUMENTS:

how.many
the number of contrasts to make. This value can be larger, smaller or the same as the number of columns in value. The default is to make one less contrast than the number of levels in x.
value
a matrix containing the same number of rows as there are levels in x. This is commonly the result of one of the standard contrast functions, such as contr.sum.

VALUE:

the value of the contrasts attribute.

SIDE EFFECTS:

the contrasts attribute is changed when an assignment is made to it.

DETAILS:

There are three functions that specify contrasts for factor variables in S-PLUS: C, contrasts, and options. Use the C function to specify a contrast as you type a model formula. The contrasts function is used to specify a contrast attribute for a factor variable. The options function specifies the default choice of contrasts for all factors.

SEE ALSO:

, , .

EXAMPLES:

# assign polynomial contrasts to temp.
contrasts(temp) <- contr.poly(3) 
# the contrast attribute from this command has 4 columns, 
# which is probably not what was intended. 
contrasts(treatment) <- contr.sum(5)[, 1:3] 
# the contrast attribute from this command has 3 columns instead. 
contrasts(treatment, how.many=3) <- contr.sum(5)[, 1:3] 
# assign and extract contrasts from quality.
quality <- factor(c(rep("tested-low",10), rep("low",10), 
     rep("high",10), rep("tested-high",10)), 
     levels = c("tested-low", "low", "high", "tested-high"))
contrast.mat <- contr.helmert(4)
contrasts(quality) <- contrast.mat
contrasts(quality)