mas: Moving average smoothing

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/MAS.r

Description

The mas() function returns a simple moving average smoother of the provided time series. mas.rev() reverses the transformation(smoothing) process.

Usage

1
2
3
mas(x, order, ...)

mas.rev(xm, xi, order, addinit = TRUE)

Arguments

x

A numeric vector or univariate time series.

order

Order of moving average smoother. If NULL, it is automatically selected by fittestMAS.

...

Additional arguments passed to fittestMAS.

xm

A numeric vector or univariate time series that has been moving average smoothed. Possibly returned by mas().

xi

Initial order-1 values/observations used for reverse smoothing. First order-1 known non-transformed values used to recursively obtain the original series. By default, mas() returns xi as an attribute.

addinit

If TRUE, xi is included in the return.

Details

The moving average smoother transformation is given by

(1/k) * ( x[t] + x[t+1] + ... + x[t+k-1] )

where k=order, t assume values in the range 1:(n-k+1), and n=length(x). See also the ma of the forecast package.

Value

Numerical time series of length length(x)-order+1 containing the simple moving average smoothed values.

Author(s)

Rebecca Pontes Salles

References

R.H. Shumway and D.S. Stoffer, 2010, Time Series Analysis and Its Applications: With R Examples. 3rd ed. 2011 edition ed. New York, Springer.

See Also

Other transformation methods: Diff(), LogT(), WaveletT(), emd(), mlm_io(), outliers_bp(), pct(), train_test_subset()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data(CATS)

m <- mas(CATS[,1],order=5)

#automatically select order of moving average
m <- mas(CATS[,1],order=NULL,h=20)


x <- mas.rev(m, attributes(m)$xi, attributes(m)$order)

all(round(x,4)==round(CATS[,1],4))

TSPred documentation built on Jan. 21, 2021, 5:10 p.m.