Wrapper for smartFilter
that creates a set of symmetric weights for
the 2sided window based on the Gaussian kernel, exponential decay, linear
decay, or simple uniform weights, and then calculates the moving average (dot product)
using those weights.
1 2 3 4 5 6 7 8 
y 
The numerical vector for which the moving averages will be
calculated. If 
bw 
A single, positive whole number that indicates the 'bandwidth' of the window,
which is roughly half the width of the moving window. The total width of the window is 
type 
Character string which uniquely indentifies the type of weights
to use, corresponding to the Gaussian kernel, exponential decay, linear
decay, or uniform weights. Defaults to 
furthest.weight 
A single, positive number corresponding to the unormalized value of
the weights at the left and right edges of the window. Ignored when 
center.weight 
A single, positive number corresponding to the unnormalized value of the weights at the center of the window. 
x 
Object of class 
... 
For 
All the weights are normalized (so that they sum to 1) prior to calculating
the moving average. The moving "average" is really the moving dot product of the
normalized weights and the corresponding elements of y
.
Since it uses smartFilter
to calculate the moving average,
the moving average for points near the edge of the series or in the
neighborhood of missing values are calculated using as much of the window
weights as possible.
An object class movAvg2
, which is a numeric vector containing the moving average (dot product) of the
series, with attributes that describe the weights. If y = NULL
, numeric(0)
is returned.
print
: Prints the movAvg2
object by only showing the series of dot products and suppressing the attributes.
plot
: Plots the unnormalized weights.
Landon Sego
smartFilter
, filter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  z < movAvg2(rnorm(25), bw = 10, type = "e", center.weight = 2)
z
# Look at the attributes
attributes(z)
# Plot the weights
plot(z)
# If we just want to see the weights (without supplying data)
plot(movAvg2(bw = 20, type = "g", center.weight = 1))
# Note how it produces the same values as filter (except at the edge
# of the series
x < rnorm(10)
movAvg2(x, bw = 2, type = "u")
filter(x, rep(1, 5) / 5)
# These are also the same, except at the edge.
movAvg2(x, bw = 1, type = "l", furthest.weight = 0.5, center.weight = 1)
filter(x, c(0.5, 1, 0.5) / 2)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.