model.matrix {base} | R Documentation |
Construct design matrices
Description
model.matrix
creates a design matrix.
model.weights
extracts the weights.
Usage
model.matrix (object, ...)
model.matrix.lm(object, ...)
model.matrix.default(formula, data, contrasts.arg = NULL, xlev = NULL)
model.weights(x)
Arguments
formula |
a model formula or terms object. |
data |
a data frame created with |
contrasts.arg |
A list, whose entries are contrasts suitable for
input to the |
xlev |
to be used as argument of |
x |
a modle frame. |
Value
The design matrix for a regression model with the specified formula and data.
References
Chambers and Hastie: "Statistical Models in S".
See Also
model.frame
,
terms
Examples
data(trees)
ff <- log(Volume) ~ log(Height) + log(Girth)
str(m <- model.frame(ff, trees))
mat <- model.matrix(ff, m)
dd <- data.frame(a = gl(3,4), b = gl(4,1,12))# balanced 2-way
options("contrasts")
model.matrix(~a+b,dd)
model.matrix(~a+b,dd,contrasts=list(a="contr.sum"))
model.matrix(~a+b,dd,contrasts=list(a="contr.sum",b="contr.poly"))
m.orth <- model.matrix(~a+b,dd, contrasts=list(a="contr.helmert"))
crossprod(m.orth)# m.orth is ALMOST orthogonal