contrasts
attribute of a factor variable.
contrasts(x) contrasts(x, how.many=<<see below>>) <- value
value
.
The default is to make one less contrast than the number of levels in
x
.
x
.
This is commonly the result of one of the standard contrast functions, such as
contr.sum
.
contrasts
attribute.
contrasts
attribute is changed when an assignment is made to it.
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.
# 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)