weightedLowess(x, y, weights = rep(1, length(y)), delta=NULL, npts = 200, span = 0.3, iterations = 4)
delta
span
). For integer
weights, the prior weights are equivalent to using rep(..., w)
on x
and y
prior to fitting.For large vectors, running time is reduced by only performing locally weighted regression for several points. Fitted values for all points adjacent to the chosen points are computed by linear interpolation between the chosen points. For this purpose, the first and last points are always chosen. Note that the regression itself uses all (neighbouring) points.
Points are defined as adjacent to a chosen point if the distance to the latter is positive and less
than delta
. The first chosen point is that corresponding to the smallest covariate; the
next chosen point is then the next non-adjacent point, and so on. By default, the smallest delta
is chosen to obtain a number of chosen points approximately equal to the specified npts
.
Increasing npts
or supplying a small delta
will improve the accuracy of the fit (i.e.
closer to the full lowess procedure) at the cost of running time.
Robustification is performed using the magnitude of the residuals. Residuals greater than 6 times the
median residual are assigned weights of zero. Otherwise, Tukey's biweight function is applied.
Weights are then used for weighted linear regression. Greater values of iterations
will
provide greater robustness.
lowess
y <- rt(100,df=4)
x <- runif(100)
w <- runif(100)
out <- weightedLowess(x, y, w, span=0.7)
plot(x,y,cex=w)
o <- order(x)
lines(x[o],out$fitted[o],col="red")
Run the code above in your browser using DataLab