dweights <- expand.grid(
time = 0:10,
alpha = seq(0, 1, by = .1))
library(ggplot2)
ggplot(dweights, aes(time, (1 - alpha)^time, colour = factor(alpha))) +
geom_line() + geom_point() + theme_bw() +
scale_x_reverse() +
theme(legend.position = "bottom") +
ggtitle("Exponential Decay in Weights")
ggplot(dweights, aes(time, pmax(1 - alpha * time, 0), colour = factor(alpha))) +
geom_line() + geom_point() + theme_bw() +
scale_x_reverse() +
theme(legend.position = "bottom") +
ggtitle("Linear Decay in Weights")
weighted.sma(c(1, 2, 3, 4, 5),
window = 3L, decay = "none",
missThreshold = 0)
weighted.sma(c(1, 2, 3, 4, 5),
window = 3L, decay = "exponential",
alpha = 0, missThreshold = 0)
weighted.sma(c(1, 2, 3, 4, 5),
window = 3L, decay = "linear",
alpha = 0, missThreshold = 0)
weighted.sma(c(1, 2, 3, 4, 5),
window = 3L, decay = "exponential",
alpha = .1, missThreshold = 0)
weighted.sma(c(1, 2, 3, 4, 5),
window = 3L, decay = "exponential",
alpha = .5, missThreshold = 0)
weighted.sma(c(1, 2, 3, 4, 5),
window = 3L, decay = "linear",
alpha = .1, missThreshold = 0)
weighted.sma(c(1, 2, 3, 4, 5),
window = 3L, decay = "linear",
alpha = .3, missThreshold = 0)
weighted.sma(c(1, NA, NA, 4, 5),
window = 4L, decay = "exponential",
alpha = .4, missThreshold = .4)
## clean up
rm(dweights)
Run the code above in your browser using DataLab