Moving Average Smoother With Tricube Weights
Apply a moving average smoother with tricube distance weights to a numeric vector.
tricubeMovingAverage(x, span=0.5, power=3)
x |
numeric vector |
span |
the smoother span. This gives the proportion of |
power |
a positive exponent used to compute the tricube weights. |
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.
Numeric vector of same length as x
containing smoothed values.
Gordon Smyth
x <- rbinom(100,size=1,prob=0.5) plot(1:100,tricubeMovingAverage(x))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.