loessfit: Univariate Lowess With Prior Weights

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Univariate locally weighted linear regression allowing for prior weights. Returns fitted values and residuals.

Usage

1
loessFit(y, x, weights=NULL, span=0.3, iterations=4, min.weight=1e-5, max.weight=1e5, equal.weights.as.null=TRUE)

Arguments

y

numeric vector of response values. Missing values are allowed.

x

numeric vector of predictor values Missing values are allowed.

weights

numeric vector of non-negative weights. Missing values are treated as zero.

span

positive numeric value between 0 and 1 specifying proportion of data to be used in the local regression moving window. Larger numbers give smoother fits.

iterations

number of local regression fits. Values greater than 1 produce robust fits.

min.weight

minimum weight. Any lower weights will be reset.

max.weight

maximum weight. Any higher weights will be reset.

equal.weights.as.null

should equal weights be treated as if weights were NULL, so that lowess is called? Applies even if all weights are all zero.

Details

This function is essentially a wrapper function for lowess and locfit.raw with added error checking. The idea is to provide the classic univariate lowess algoritm 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 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.

When weights are provided, this function makes repeated calls to locfit.raw with deg=1. Each iteration applies robustifying weights computed from the previous fit, as described by Cleveland (1981).

By default, weights that are all equal (even all zero) are treated as if they were NULL.

In principle this function gives analogous results to loess(y~x,weights=weights,span=span,degree=1,family="symmetric"). However lowess and locfit.raw scale up much more efficiently for long data vectors.

The arguments span and iterations here have the same meaning as for 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.

Value

A list with components

fitted

numeric vector of same length as y giving the loess fit

residuals

numeric vector of same length as x giving residuals from the fit

Author(s)

Gordon Smyth

References

Cleveland, W. S. (1979). Robust locally weighted regression and smoothing scatterplots. Journal of the American Statistical Association 74, 829-836.

See Also

This function uses lowess and locfit.raw. 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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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")

richierocks/limma2 documentation built on May 27, 2019, 8:47 a.m.