predict.loess {stats} | R Documentation |
Predict LOESS Curve or Surface
Description
Predictions from a loess
fit, optionally with standard errors.
Usage
## S3 method for class 'loess'
predict(object, newdata = NULL, se = FALSE,
na.action = na.pass, ...)
Arguments
object |
an object fitted by |
newdata |
an optional data frame in which to look for variables with which to predict, or a matrix or vector containing exactly the variables needs for prediction. If missing, the original data points are used. |
se |
should standard errors be computed? |
na.action |
function determining what should be done with missing
values in data frame |
... |
arguments passed to or from other methods. |
Details
The standard errors calculation se = TRUE
is slower than
prediction, notably as it needs a relatively large workspace (memory),
notably matrices of dimension N \times Nf
where f =
span
, i.e., se = TRUE
is O(N^2)
and hence stops when the sample size N
is larger than about 40'600
(for default span = 0.75
).
When the fit was made using surface = "interpolate"
(the
default), predict.loess
will not extrapolate – so points outside
an axis-aligned hypercube enclosing the original data will have
missing (NA
) predictions and standard errors.
Value
If se = FALSE
, a vector giving the prediction for each row of
newdata
(or the original data). If se = TRUE
, a list
containing components
fit |
the predicted values. |
se |
an estimated standard error for each predicted value. |
residual.scale |
the estimated scale of the residuals used in computing the standard errors. |
df |
an estimate of the effective degrees of freedom used in estimating the residual scale, intended for use with t-based confidence intervals. |
If newdata
was the result of a call to
expand.grid
, the predictions (and s.e.'s if requested)
will be an array of the appropriate dimensions.
Predictions from infinite inputs will be NA
since loess
does not support extrapolation.
Note
Variables are first looked for in newdata
and then searched for
in the usual way (which will include the environment of the formula
used in the fit). A warning will be given if the
variables found are not of the same length as those in newdata
if it was supplied.
Author(s)
B. D. Ripley, based on the cloess
package of Cleveland,
Grosse and Shyu.
See Also
Examples
cars.lo <- loess(dist ~ speed, cars)
predict(cars.lo, data.frame(speed = seq(5, 30, 1)), se = TRUE)
# to get extrapolation
cars.lo2 <- loess(dist ~ speed, cars,
control = loess.control(surface = "direct"))
predict(cars.lo2, data.frame(speed = seq(5, 30, 1)), se = TRUE)