contr.diff | R Documentation |
Function contr.diff
is a contrast function for factors with ordered values.
Coefficients for factors formatted with contr.diff
are the increments
from the current level to the neighbouring lower level.
contr.diff(n, contrasts = TRUE)
n |
vector of levels or integer number of levels |
contrasts |
logical indicating whether contrasts should be computed |
The design matrix for an ordered factor formatted with contr.diff
consists of ones
for the current level itself and all lower levels. Thus, the estimated coefficients
for each level are the estimated differences to the next lower level.
With this coding, the matrix ui
in functions of package ic.infer
can be chosen as the identity matrix for monotonicity constraints on the factor.
a matrix with a row for each level and a column for each dummy variable (when applied to a factor in a linear model).
Ulrike Groemping, BHT Berlin
See also ic.test
, ic.est
,
orlm
, contrasts
for other contrast
functions
## mu, Sigma and covariance matrix
means <- c(3,5,2,7)
## contrast matrix
contr.diff(4)
## design matrix
X <- cbind(rep(1,4),contr.diff(4))
## estimated coefficients
solve(t(X)%*%X,t(X)%*%means)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.