MA {aTSA} | R Documentation |
Applies moving average filter to estimate the linear trend or nonseasonal pattern.
MA(x, nlag = NULL, plot = TRUE)
x |
a numeric vector or univariate time series. |
nlag |
the number of period to calculate the average. The default is |
plot |
a logical value indicating to print out the plot. The default is |
The moving average filter uses the unweight mean of (2*nlag
+ 1) adjacent
observations. That is,
hat{X}[t] = (X[t - nlag] + ... + X[t] + ...+ X[t + nlag])/(2*nlag + 1)
for nlag < t < n - nlag.
For the values at the boundary t ≤ nlag or n - nlag ≤ t ≤ n, you can
refer to Equation (7) in Qiu et al., (2013) for details of calculations.
The default method for choosing the optimal nlag
uses the rule-of-thumb
criterion proposed by Qiu, et al., (2013), in which they showed that the moving
average
is a special case of local linear estimator in the sense that the kernel function is the
uniform one, and the moving average period nlag
is a function of bandwidth. Thus,
choosing the optimal nlag
is equivalent to choosing the optimal bandwidth in local
linear regression.
The plot of original values v.s fitted values will be displayed if plot = TRUE
.
A list with class "MA
" containing the following components:
estimate |
the smoothed values. |
nlag |
the period used to compute the average. |
accurate |
the accurate measurements. |
Debin Qiu
D. Qiu, Q. Shao, and L. Yang (2013), Efficient inference for autoregressive coefficient in the presence of trend. Journal of Multivariate Analysis 114, 40-53.
P.J. Brockwell, R.A. Davis, Time Series: Theory and Methods, second ed., Springer, New York, 1991.
x <- arima.sim(list(order = c(1,0,0),ar = 0.4),n = 100) y <- 5*(1:100)/100 + x MA(y) # moving average filter for co2 data MA(co2)