predict.earth {earth}R Documentation

Predict with an "earth" model

Description

Predict with an earth model.

Usage

## S3 method for class 'earth':
predict(object = stop("no 'object' arg"), newdata = NULL,
                        type = c("link", "response", "earth", "class", "terms"),
                        thresh = .5, trace = FALSE, ...)

Arguments

object An earth object. This is the only required argument.
newdata Make predictions using newdata, which can be a dataframe, a matrix, or a vector with length equal to a multiple of the row length of the original input matrix x. Note that this is more flexible than the predict methods for most R models. Default is NULL, meaning return values predicted from the training set.
type Type of prediction. One of "link" (default), "response", "earth", "class", or "terms". See the Note below.
thresh Threshold, a value between 0 and 1 when predicting a probability. Only applies when type="class". Default is .5. See the Note below.
trace Default FALSE. Set to TRUE to see which data, subset, etc. predict.earth is using.
... Unused, but provided for generic/method consistency.

Value

The predicted values (a matrix for multiple response models). Except if type="terms", then a matrix with each column showing the contribution of a predictor.

Note

Predicting with standard earth models

Use the default type="link", or possibly type="class".

Actually, the "link", "response", and "earth" choices all return the same value unless the glm argument was used in the original call to earth.

Predicting with earth-GLM models

This section applies to earth models with a GLM component, i.e., when the glm argument was used in the original call to earth.

The "link" and "response" options: see predict.glm for a description of these. In brief: for logistic models use type="link" to get log-odds and type="response" to get probabilities.

Use option "earth" to get the linear fit (this gives the prediction you would get if your original call to earth had no glm argument).

Predicting with "class"

Use option "class" to get the predicted class. With option "class", this function first makes predictions with type="response" and then assigns the predicted values to classes as follows:

(i) When y is a logical, predict TRUE if the predicted probability is greater than thresh.

(ii) When y is a numeric, predict TRUE if the predicted value is greater than thresh. Actually, this is identical to the above case, although thresh here may legitimately be a value outside the 0...1 range.

(iii) When y is a two level factor, predict the second level if its probability is more than thresh. In other words, with the default thresh=.5 predict the most probable level.

(iv) When y is a three or more level factor, predict the most probable level (and thresh is ignored).

Predicting with "terms"

The "terms" option returns a "link" response suitable for termplot. Only the additive terms and the first response (for multi-response models) are returned. Also, "terms" always returns the earth terms, and ignores the GLM component of the model, if any.

See Also

earth, predict

Examples

data(trees)
a <- earth(Volume ~ ., data = trees)
predict(a)           # same as a$fitted.values
predict(a, c(10,80)) # yields 17.76888

[Package earth version 2.3-2 Index]