C
Assign Contrasts to a Factor
Description
Assign contrasts to a factor in a model formula or create a new factor for use in statistical modelling functions.
Usage
C(object, contr, how.many)
Arguments
object |
a factor or an ordered factor.
|
contr |
a function, a matrix, or character string that specifies the contrasts
to use. If a matrix, the matrix must have as many rows as there are
levels in the factor. If you specify a character string, you can
submit one of the following five standard names: (helmert,
poly, treatment, sum), or SAS. The default
is the first element of the contrasts option for factors and
the second element of the option for ordered factors.
|
how.many |
an integer that specifies the number of contrasts to be assigned to
the factor. The default is nlevels(object)-1.
|
Details
If you set how.many to less than nlevels(object)-1 in a
model formula you are asserting that the coefficients for the
remaining factors are either known to be negligible or else should be
aliased with other coefficients.
Value
returns the input factor with an added contrasts attribute.
See Also
Examples
data(warpbreaks)
# treat 2nd level of tension as baseline for just the next analysis
lm(breaks ~ wool + C(tension, treatment, base=2), data=warpbreaks)
# treat last level as baseline for all future analyses
contrasts(warpbreaks$tension) <- "contr.SAS"
lm(breaks ~ wool + tension, data=warpbreaks)
contrasts(warpbreaks$tension) <- NULL