MA(x, nlag = NULL, plot = TRUE)
NULL
.TRUE
.MA
" containing the following components: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 \le nlag$ or $n - nlag \le t \le 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
.
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)
Run the code above in your browser using DataCamp Workspace