Learn R Programming

ic.infer (version 1.1-7)

contr.diff: Contrast function for factors with ordered values that yields increment coefficients

Description

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.

Usage

contr.diff(n, contrasts = TRUE)

Value

a matrix with a row for each level and a column for each dummy variable (when applied to a factor in a linear model).

Arguments

n

vector of levels or integer number of levels

contrasts

logical indicating whether contrasts should be computed

Author

Ulrike Groemping, BHT Berlin

Details

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.

See Also

See also ic.test, ic.est, orlm, contrasts for other contrast functions

Examples

Run this code
## 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)

Run the code above in your browser using DataLab