loessFit(y, x, weights=NULL, span=0.3, iterations=4L, min.weight=1e-5, max.weight=1e5, equal.weights.as.null=TRUE, method="weightedLowess")NULL, so that lowess is called? Applies even if all weights are all zero."weightedLowess", "loess" or "locfit".y giving the loess fitx giving residuals from the fitlowess and weightedLowess with added error checking.
The idea is to provide the classic univariate lowess algorithm of Cleveland (1979) but allowing for prior weights and missing values.The venerable lowess code is fast, uses little memory and has an accurate interpolation scheme, so it is an advantage to use it when prior weights are not needed.
This functions calls lowess when weights=NULL, but returns values in original rather than sorted order and allows missing values.
The treatment of missing values is analogous to na.exclude.
By default, weights that are all equal (even all zero) are treated as if they were NULL, so lowess is called in this case also.
When unequal weights are provided, this function calls weightedLowess by default, although two other possibilities are also provided.
weightedLowess implements a similar algorithm to lowess except that it uses the prior weights both in the local regressions and in determining which other observations to include in the local neighbourhood of each observation.
Two alternative algorithms for weighted lowess curve fitting are provided as options.
If method="loess", then a call is made to loess(y~x,weights=weights,span=span,degree=1,family="symmetric",...).
This method differs from weightedLowess in that the prior weights are ignored when determining the neighbourhood of each observation.
If method="locfit", then repeated calls are made to locfit:::locfit.raw with deg=1.
In principle, this is similar to "loess", but "locfit" makes some approximations and is very much faster and uses much less memory than "loess" for long data vectors.
The arguments span and iterations here have the same meaning as for weightedLowess and loess.
span is equivalent to the argument f of lowess while iterations is equivalent to iter+1 for lowess.
It gives the total number of fits rather than the number of robustifying fits.
When there are insufficient observations to estimate the loess curve, loessFit returns a linear regression fit.
This mimics the behavior of lowess but not that of loess or locfit.raw.
weights=NULL, this function calls lowess.
Otherwise it calls weightedLowess, locfit.raw or loess.
See the help pages of those functions for references and credits.Compare with loess in the stats package.
See 05.Normalization for an outline of the limma package normalization functions.
x <- (1:100)/101
y <- sin(2*pi*x)+rnorm(100,sd=0.4)
out <- loessFit(y,x)
plot(x,y)
lines(x,out$fitted,col="red")
# Example using weights
y <- x-0.5
w <- rep(c(0,1),50)
y[w==0] <- rnorm(50,sd=0.1)
pch <- ifelse(w>0,16,1)
plot(x,y,pch=pch)
out <- loessFit(y,x,weights=w)
lines(x,out$fitted,col="red")
Run the code above in your browser using DataLab