tricubeMovingAverage {limma} | R Documentation

## Moving Average Smoother With Tricube Weights

### Description

Apply a moving average smoother with tricube distance weights to a numeric vector.

### Usage

    tricubeMovingAverage(x, span=0.5, power=3)

### Arguments

`x` | numeric vector
`span` | the smoother span. This gives the proportion of `x` values that contribute to each moving average. Larger values give more smoothness. Should be positive but not greater than 1.
`power` | a positive exponent used to compute the tricube weights. `power=3` gives the usual tricube weights. Smaller values give more even weighting. Should be greater than 0.

### Details

This function smooths a vector (considered as a time series) using a moving average with tricube weights. Specifically, the function computes running weighted means of `w` consecutive values of `x`, where the window width `w` is equal to `2*h+1` with `h = 2*floor(span*length(x)/2)`. The window width `w` is always odd so that each window has one of the original `x` values at its center. Each weighted mean uses a set of tricube weights so that values near the ends of the window receive less weight.

The smoother returns a vector of the same length as input. At the start and end of the vector, the series is considered to be extended by missing values, and the weighted average is computed only over the observed values. In other words, the window width is reduced to `h+1` at the boundaries with asymmetric weights.

The result of this function is similar to a least squares loess curve of degree zero, with a couple of differences. First, a continuity correction is applied when computing the distance to neighbouring points, so that exactly `w` points are included with positive weights in each average. Second, the span halves at the end points so that the smoother is more sensitive to trends at the ends.

The `filter` function in the stats package is called to do the low-level calculations.

This function is used by `barcodeplot` to compute enrichment worms.

### Value

Numeric vector of same length as `x` containing smoothed values.

### Author(s)

Gordon Smyth

### See Also

`filter`, `barcodeplot`, `loessByCol`

### Examples

    x <- rbinom(100,size=1,prob=0.5)
    plot(1:100,tricubeMovingAverage(x))

[Package limma version 3.43.8 Index]