predict.loess
Evaluation of Local Regression Surfaces

Description

Returns the surface values of local regression surfaces and/or standard errors.

Usage

predict.loess(object, newdata = NULL, se = FALSE,
    na.action = na.pass, ...)

Arguments

object a loess object.
newdata a data frame specifying the values of the predictors at which the evaluation is carried out. The default is to predict at the data used to fit object. That is, if newdata = NULL (the default), use the x component of the object as newdata.
se a logical value. If TRUE, estimates of the standard errors of the surface values and other statistical information, are returned along with the surface values. The default is FALSE.
na.action a function to filter missing data. The default is the function na.pass.
... additional arguments for future functions.

Details

This function is a method for the generic function predict for the class loess. It can either be invoked by calling predict for an object x of the appropriate class, or it can be invoked directly by calling predict.loess, regardless of the class of the object.
For one predictor, newdata can be a vector rather than a data frame.
For two or more predictors, newdata must include the names of predictors used in formula as they appear in the database from which they come. For example, if the right side of formula is log(E)*C, then the names C and E must be in newdata. Note that the specification of E in this example is not on the transformed scale; rather, it is on the original scale.
For two or more predictors, one of two data structures can be given to newdata. If se = FALSE, then the result of predict.loess is a numeric array whose dimension is equal to the number of predictors. If se = TRUE, then the components fit and se.fit are both such arrays.
The computations of predict.loess that produce the component se.fit are much more costly than those that produce fit, so the number of points at which standard errors are computed should be modest compared to those at which we do evaluations. Often this means calling predict.loess twice: once at a large number of points, with se equal to FALSE to get a thorough description of the surface, and once at a small number of points to get standard-error information.
Suppose the computation method for the loess argument surface is interpolate (the default). Then the evaluation values of a numeric predictor must lie within the range of the values of the predictor used in the fit. The evaluation values for a predictor that is a factor must be one of the levels of the factor. For any evaluation point for which these conditions are not met, an NA is returned.
If se is TRUE or the computation method for loess surfaces is direct, then predict.loess must use the data originally used to fit the loess model to compute the predictions. If you fit the loess model using the data argument, then the data set given by data should not be changed between the fit and the prediction. If you attached a data frame to supply data for the model, then that same data frame must be attached to compute the predicted values.
Value
See Also
expand.grid, loess, predict
Examples
ethanol.cp <- loess(formula = NOx ~ C * E, data=Sdatasets::ethanol,
    span = 1/2, degree = 2, parametric = "C", drop.square = "C")

# Example 1 - evaluation at 5 points # newdata is a data frame with variables C and E newdata <- Sdatasets::ethanol[c(1, 2, 3, 5, 8), c("C", "E")] predict(ethanol.cp, newdata) ## 1 2 3 5 8 ## 3.845377 2.345562 1.382060 0.745741 1.187618

# Example 2 - evaluation at 9 grid points C.marginal <- with(Sdatasets::ethanol, seq(min(C), max(C), length = 3)) E.marginal <- with(Sdatasets::ethanol, seq(min(E), max(E), length = 3)) CE.grid <- expand.grid(list(C = C.marginal, E = E.marginal)) predict(ethanol.cp, CE.grid) ## E ## C E=0.5350 E=0.8835 E=1.2320 ## C= 7.50 -0.1039991 3.399360 0.6823181 ## C=12.75 0.2057837 3.850801 0.6481270 ## C=18.00 0.5155665 4.302243 0.6139359

# Example 3 - evaluate and compute estimates of standard errors gas.m <- loess(formula = NOx ~ E, data=Sdatasets::ethanol, span = 2/3, degree = 2) with(Sdatasets::ethanol, predict(gas.m, newdata = seq(min(E), max(E), length = 5), se = TRUE)$se.fit) ## [1] 0.18423300 0.07098989 0.07643326 0.07503963 0.11885234

Package stats version 6.0.0-69
Package Index