loess
Fit a Local Regression Model

Description

Fits a local regression model. A loess model is a form of non-parametric regression where the regression surface is locally approximated by polynomials of degree 1 or 2.

Usage

loess(formula, data, weights, subset, na.action, model = FALSE, span = 0.75,
    enp.target, degree = 2, parametric = FALSE, drop.square = FALSE,
    normalize = TRUE, family = c("gaussian", "symmetric"),
    method = c("loess", "model.frame"), control, ...)

Arguments

formula a formula object with the response on the left of a ~ operator, and the terms, separated by "*" operators, on the right of a ~ operator.
data an optional data.frame in which to interpret the variables named in the formula, subset, and weights arguments.
weights an optional expression for weights to give to individual observations in the sum of squared residuals that forms the local fitting criterion. By default, an unweighted fit is carried out. If it is supplied, weights is treated as an expression to evaluate in the same data frame as the model formula. It should evaluate to a non-negative numeric vector. If the different observations have nonequal variances, weights should be inversely proportional to the variances.
subset an expression specifying the subset of the rows of the data to be used in the fit. This can be one of the following:
  • a logical vector (which is replicated to have a length equal to the number of observations).
  • a numeric vector indicating which observation numbers are to be included.
  • a character vector of the row names to be included.
All observations are included by default.
na.action a function to filter missing data. This function is applied to the model.frame after any subset argument has been used. The default (with na.fail) creates an error if any missing values are found. A possible alternative is na.exclude, which deletes observations that contain one or more missing values.
model a logical value. If TRUE, the model frame is included in the returned object. The default is FALSE.
span the smoothing parameter.
enp.target an alternative that specifies the amount of smoothing. An approximation is used to compute a value of span that yields approximately enp.target equivalent number of parameters.
degree the overall degree of the locally-fitted polynomial. 1 is locally-linear fitting, and 2 (the default) is locally-quadratic fitting.
parametric for two or more numeric predictors, this argument specifies those variables that should be conditionally parametric. The method of specification is the same as it is for drop.square.
drop.square for cases with degree equal to 2, and with two or more numeric predictors, this argument specifies those numeric predictors whose squares should be dropped from the set of fitting variables. This argument can be one of the following:
  • a character vector of the predictor names given in formula.
  • a numeric vector of indices that gives positions as determined by the order of specification of the predictor names in formula.
  • a logical vector of the length equal to the number of predictor names in formula.
normalize a logical value. If TRUE (the default), numeric predictors are normalized using the standard normalization. If FALSE, no normalization is carried out.
family the assumed distribution of the errors. The values are "gaussian" (the default) or "symmetric". If you specify "symmetric", a robust fitting procedure is used.
method a character string. The default is "loess", which fits the loess model. If set to "model.frame", the model frame is computed and returned, and no loess model is fit.
control the list that controls the methods of computation in the loess fitting. The list can be created by the function loess.control, whose documentation describes the computational options.
... additional arguments of the function loess.control can be specified directly in the call to loess without using the argument control.

Details

Loess models are non-parametric regression models that locally approximate the regression surface by polynomials. They are good at capturing nonlinearities in the surface and are fairly robust to outliers. See Chapter 8 in Chambers, J.M., and Hastie, T.J. (1991).
If loess runs slowly on a particular computer, you can change the components of the control list to speed up the computations by using further approximations. For example, changing the component trace.hat to "approximate" can reduce the computation time substantially for large datasets.
Value
returns an object of class "loess" representing the fitted model. See the documentation for loess.object for more information on the components.
Limitations
Locally quadratic models can have at most 4 predictor variables; locally linear models can have at most 8. The memory needed by loess increases exponentially with the number of variables.
References
Chambers, J.M., and Hastie, T.J. (1991) Statistical Models in S, 309-376.
Cleveland, W.S., and Devlin, S.J. (1988) Locally-weighted regression: an approach to regression analysis by local fitting. J. Am. Statist. Assoc., Vol. 83, pp 596-610.
Cleveland, W.S., and Grosse, E. (1991) Computational methods for local regression. Statistics and Computing, Vol. 1, pp 47-62.
See Also
loess.control, predict.loess
Examples
loess(NOx ~ C * E, span = 1/2, degree = 2,
      parametric = "C", drop.square = "C", data=Sdatasets::ethanol)
## Call:
## loess(formula = NOx ~ C * E, data = Sdatasets::ethanol, span = 1/2,
## degree = 2, parametric = "C", drop.square = "C")
##
##  Number of Observations:          88
##  Equivalent Number of Parameters: 9.17
##  Residual Standard Error:         0.1842
Package stats version 6.1.4-13
Package Index