Fit a Local Regression Model
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.
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, ...)
a formula object with the response on the left of a ~ operator,
and the terms, separated by "*" operators, on the right of a ~ operator.
an optional data.frame in which to interpret the variables named in the
formula, subset, and weights arguments.
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.
an expression specifying the subset of the rows of the data
to be used in the fit.
This can be one of the following:
All observations are included by default.
- 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.
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.
a logical value. If TRUE, the model frame is included in the returned
The default is FALSE.
the smoothing parameter.
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
the overall degree of the locally-fitted polynomial.
1 is locally-linear fitting, and 2 (the default)
is locally-quadratic fitting.
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.
for cases with degree equal to 2, and with two or more numeric predictors,
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.
a logical value. If TRUE (the default), numeric predictors are
normalized using the standard normalization.
If FALSE, no normalization is carried out.
the assumed distribution of the errors.
The values are "gaussian" (the default) or
"symmetric". If you specify "symmetric",
a robust fitting procedure is used.
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.
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.
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
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.
returns an object of class "loess" representing the fitted model. See the documentation
for loess.object for more information on the components.
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
Chambers, J.M., and Hastie, T.J. (1991) Statistical Models in S,
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.
loess(NOx ~ C * E, span = 1/2, degree = 2,
parametric = "C", drop.square = "C", data=Sdatasets::ethanol)
## 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