View source: R/DSF_ExponentialMA.R
DSF_ExponentialMA | R Documentation |
Applies an exponential moving average to components of a data stream.
DSF_ExponentialMA(dsd = NULL, dim = NULL, alpha = 0.5)
dsd |
The input stream as an DSD object. |
dim |
columns to which the filter should be applied. Default is all columns. |
alpha |
smoothing coefficient in |
The exponential moving average is calculated by:
S_t = \alpha Y_t + (1 - \alpha)\; S_{i-1}
with S_0 = Y_0
.
An object of class DSF_ExponentialMA
(subclass of DSF and DSD).
Michael Hahsler
Other DSF:
DSF()
,
DSF_Convolve()
,
DSF_Downsample()
,
DSF_FeatureSelection()
,
DSF_Func()
,
DSF_Scale()
,
DSF_dplyr()
# Smooth a time series
data(presidents)
stream <- data.frame(
presidents,
.time = time(presidents)) %>%
DSD_Memory()
plot(stream, dim = 1, n = 120, method = "ts", main = "Original")
smoothStream <- stream %>% DSF_ExponentialMA(alpha = .7)
smoothStream
reset_stream(smoothStream)
plot(smoothStream, dim = 1, n = 120, method = "ts", main = "With ExponentialMA(.7)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.