DSF_ExponentialMA: Exponential Moving Average over a Data Stream

View source: R/DSF_ExponentialMA.R

DSF_ExponentialMAR Documentation

Exponential Moving Average over a Data Stream

Description

Applies an exponential moving average to components of a data stream.

Usage

DSF_ExponentialMA(dsd, dim = NULL, alpha = 0.5)

Arguments

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 [0, 1]. Larger means discounting older observations faster.

Details

The exponential moving average is calculated by:

S_t = α Y_t + (1 - α)\; S_{i-1}

with S_0 = Y_0.

Value

An object of class DSF_ExponentialMA (subclass of DSF and DSD).

Author(s)

Michael Hahsler

See Also

Other DSF: DSF_Convolve(), DSF_Downsample(), DSF_Func(), DSF_dplyr(), DSF()

Examples

# 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)")

stream documentation built on Sept. 3, 2022, 1:06 a.m.