Description Usage Arguments Details Value Methods (by generic) Author(s) See Also Examples
Wrapper for smartFilter
that creates a set of symmetric weights for
the 2-sided 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. |
... |
For |
x |
Object of class |
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
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)
|
[1] -0.42246717 -0.04026814 -0.15453932 -0.19089063 -0.18035891 -0.05506676
[7] 0.11082438 0.26838750 0.47091483 0.51003175 0.66714743 0.55333958
[13] -0.03773782 -0.25563888 -0.28693830 -0.45483428 -0.48245691 -0.57125106
[19] -0.73233910 -0.92719849 -0.89455484 -1.02054225 -1.10389033 -0.77465587
[25] -0.23223133
$class
[1] "movAvg2" "numeric"
$type
[1] "exponential"
$bw
[1] 10
$furthest.weight
[1] 0.01
$center.weight
[1] 2
$wts
[1] 0.01000000 0.01698646 0.02885400 0.04901274 0.08325532 0.14142136
[7] 0.24022489 0.40805715 0.69314484 1.17740804 2.00000000 1.17740804
[13] 0.69314484 0.40805715 0.24022489 0.14142136 0.08325532 0.04901274
[19] 0.02885400 0.01698646 0.01000000
[1] 0.16653051 0.14638273 0.25636898 0.18141125 0.03419059 0.40835384
[7] 0.75468427 0.76139767 0.64940854 0.85349705
Time Series:
Start = 1
End = 10
Frequency = 1
[1] NA NA 0.25636898 0.18141125 0.03419059 0.40835384
[7] 0.75468427 0.76139767 NA NA
[1] 1.3138440 0.3182095 -0.7141024 -0.2474012 0.6719804 0.7880413
[7] 0.3241647 0.4701930 1.0945207 1.0924511
Time Series:
Start = 1
End = 10
Frequency = 1
[1] NA 0.3182095 -0.7141024 -0.2474012 0.6719804 0.7880413
[7] 0.3241647 0.4701930 1.0945207 NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.