## S3 method for class 'earth'
model.matrix(object = stop("no 'object' argument"),
x = NULL, subset = NULL, which.terms = NULL,
...,
env = parent.frame(),
trace = 0,
Callers.name = "model.matrix.earth")
Arguments
object
An earth object.
This is the only required argument.
x
An input matrix with the same number of columns as the x matrix
used to construct the original earth object.
Default is NULL, meaning use the original x matrix after
taking the original subset, if any.
subset
Which rows to use in x.
Default is NULL, meaning use all of x.
which.terms
Which terms to use.
Default is NULL, meaning use object$selected.terms.
...
Unused, but provided for generic/method consistency.
env
For internal use.
trace
Default 0. Set to non-zero to see which data model.matrix.earth is using.
Callers.name
For internal use (used by earth in trace messages).
Value
A basis matrix bx of the same form returned by earth.
If x, subset, and which.terms are all NULL, this
function returns the object's bx. In this case, it is perhaps easier
to simply use object$bx.
The format of bx is described in earth.
The matrix bx can be used
as the input matrix to lm or glm,
as shown below in the example.
In fact, that is what earth does internally after the pruning pass —
it calls lm.fit,
and additionally glm if earth's glm argument is used.
See Also
earth
Examples
data(trees)
earth.mod <- earth(Volume ~ ., data = trees)
summary(earth.mod, decomp = "none") # "none" to print terms in same seq as lm.mod below
bx <- model.matrix(earth.mod) # equivalent to bx <- earth.mod$bx
lm.mod <- lm(trees$Volume ~ bx[,-1]) # -1 to drop intercept
summary(lm.mod) # yields same coeffs as above summary
# displayed t values are not meaningful