tricubeMovingAverage(x, span=0.5, power=3)
x
values that contribute to each moving average. Larger values give more smoothness. Should be positive but not greater than 1.power=3
gives the usual tricube weights. Smaller values give more even weighting. Should be greater than 0.x
containing smoothed values.
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.
filter
, barcodeplot
, loessByCol
x <- rbinom(100,size=1,prob=0.5)
plot(1:100,tricubeMovingAverage(x))
Run the code above in your browser using DataLab