contr.sum(n, contrasts=T) contr.poly(n, contrasts=T) contr.helmert(n, contrasts=T) contr.treatment(n, contrasts=T)
contr.poly
, this can be the numeric
values over which the contrasts should be orthogonal.
FALSE
, dummy variables will be returned instead.
contrasts
is
TRUE
, a matrix with
n
rows and
n-1
columns, and
an
n
by
n
matrix if
contrasts
is
FALSE
.
The interpretation of the matrix depends on the function:
contr.sum
produces coefficients satisfying the constraint
that their sum is zero (the traditional analysis of variance parametrization).
contr.poly
creates orthogonal polynomials of degree 1, 2, etc.,
either on equally spaced points if
n
was a single number,
or on the points specified by
x
.
Columns are scaled to have norm 1.
For
contr.helmert
, contrast
i
is the difference between level
i+1
and the
average of levels
1:i
.
In
contr.treatment
the contrasts are just levels
2
through
n
of the
category.
Note that
contr.poly
and
contr.helmert
produce orthogonal contrasts,
contr.sum
produces non-orthogonal contrasts, and
contr.treatment
produces a
coding that is not technically a set of contrasts at all.
These functions are usually not called directly, but supplied as the coding
for a category in a data frame.
To set the default contrast coding,
change the
contrasts
option.
# set contrasts to polynomial on x0 (a global dataset) contrasts(my.vble) <- function(n,contrasts=F)contr.poly(x0,contrasts) options(contrasts=c("contr.treatment", "contr.poly"))