aTSA (version 3.1.2)

MA: Moving Average Filter


Applies moving average filter to estimate the linear trend or nonseasonal pattern.


MA(x, nlag = NULL, plot = TRUE)


a numeric vector or univariate time series.
the number of period to calculate the average. The default is NULL.
a logical value indicating to print out the plot. The default is TRUE.


  • A list with class "MA" containing the following components:
  • estimatethe smoothed values.
  • nlagthe period used to compute the average.
  • accuratethe accurate measurements.


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 \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.


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.


Run this code
x <- arima.sim(list(order = c(1,0,0),ar = 0.4),n = 100)
y <- 5*(1:100)/100 + x

# moving average filter for co2 data

Run the code above in your browser using DataCamp Workspace