Get the earth basis matrix
Get the basis matrix of an earth model.
## S3 method for class 'earth'
model.matrix(object = stop("no 'object' argument"),
x = NULL, subset = NULL, which.terms = NULL,
trace = 0,
...,
Env = parent.frame(),
Callers.name = "model.matrix.earth")object |
An |
x |
Default is NULL, meaning use the original data
used to build the Else |
subset |
Which rows to use in |
which.terms |
Which terms to use.
Default is NULL, meaning all terms in the earth model
(i.e. the terms in |
trace |
Default 0. Set to non-zero to see which data |
... |
Unused, but provided for generic/method consistency. |
Env |
For internal use. |
Callers.name |
For internal use (used by earth in trace messages). |
A basis matrix bx of the same form returned by earth.
The format of bx is described in earth.object.
If x, subset, and which.terms are all NULL (the
default), this function returns the model's bx. In this case,
it is perhaps easier to simply use object$bx.
# Example 1
data(trees)
earth.mod <- earth(Volume ~ ., data = trees) # standard earth model
summary(earth.mod, decomp = "none") # "none" to print terms in same order as lm.mod below
bx <- model.matrix(earth.mod) # earth model's basis mat (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
# Example 2
earth.mod <- earth(Volume~., data=trees) # standard earth model
summary(earth.mod, decomp = "none") # "none" to print terms in same order as lm.mod below
bx <- model.matrix(earth.mod) # earth model's basis mat (equivalent to bx <- earth.mod$bx)
bx <- bx[, -1] # drop intercept column
bx <- as.data.frame(bx) # lm requires a data frame
bx$Volume <- trees$Volume # add Volume to data
lm.mod <- lm(Volume~., data=bx) # standard linear regression on earth's basis mat
summary(lm.mod) # yields same coeffs as above summary
# displayed t values are not meaningfulPlease choose more modern alternatives, such as Google Chrome or Mozilla Firefox.