Predict with an earth model
Predict with an
## S3 method for class 'earth': predict(object = stop("no 'object' argument"), newdata = NULL, type = c("link", "response", "earth", "class", "terms"), interval = "none", level = .95, thresh = .5, trace = FALSE, ...)
earthobject. This is the only required argument.
- Make predictions using
newdata, which can be a data frame, a matrix, or a vector with length equal to a multiple of the number of columns of the original input matrix
x. Note that this is more flexible than the predic
- Type of prediction.
"terms". See the Note below.
- Return prediction or confidence levels.
interval="pint"to get prediction intervals on new data. Requires that the earth model was built with
varmod.method. This argument gets passed
- Confidence level for the
intervalargument. Default is
.95, meaning construct 95% confidence bands (estimate the 2.5% and 97.5% levels).
- Threshold, a value between 0 and 1 when predicting a probability.
Only applies when
type="class". Default is .5. See the Note below.
FALSE. Set to
TRUEto see which data, subset, etc.
- Unused, but provided for generic/method consistency.
- The predicted values (a matrix for multiple response models).
type="terms", a matrix with each column showing the contribution of a predictor.
"cint", a matrix with three columns:
fit: the predicted values
lwr: the lower confidence or prediction limit
upr: the upper confidence or prediction limit
interval="se", the standard errors.
Predicting with standard earth models
Use the default
type="link", or possibly
choices all return the same value unless the
was used in the original call to
Predicting with earth-GLM models
This section applies to earth models with a GLM component, i.e.,
glm argument was used
in the original call to
predict.glm for a description of these.
In brief: for logistic models
type="link" to get log-odds and
type="response" to get probabilities.
"earth" to get the linear fit (this gives the prediction you would get
if your original call to earth had no
Predicting with "class"
"class" to get the predicted class.
"class", this function first makes predictions with
type="response" and then assigns the predicted values to classes as follows:
(i) When the response is a logical, predict
the predicted probability is greater than
(ii) When the response is a numeric, predict
the predicted value is greater than
Actually, this is identical to the above case,
thresh here may legitimately be a value
outside the 0...1 range.
(iii) When the response is a two level factor,
predict the second level if its probability is more than
In other words, with the default
thresh=.5 predict the most probable level.
(iv) When the response is a three or more level factor,
predict the most probable level (and
thresh is ignored).
Predicting with "terms"
"terms" option returns a
"link" response suitable for
Only the additive terms and the first response (for multi-response models) are returned.
"terms" always returns the earth terms, and ignores the GLM component
of the model, if any.
data(trees) earth.mod <- earth(Volume ~ ., data = trees) predict(earth.mod) # same as earth.mod$fitted.values predict(earth.mod, c(10,80)) # yields 16.8