MA: Moving Average Filter

Description Usage Arguments Details Value Author(s) References Examples

Description

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

Usage

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

Arguments

x

a numeric vector or univariate time series.

nlag

the number of period to calculate the average. The default is NULL.

plot

a logical value indicating to print out the plot. The default is TRUE.

Details

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.

Value

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.

Author(s)

Debin Qiu

References

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.

Examples

1
2
3
4
5
6
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)

Example output

Attaching package: 'aTSA'

The following object is masked from 'package:graphics':

    identify

$estimate
Time Series:
Start = 1 
End = 100 
Frequency = 1 
  [1] 0.6387425 0.6590607 0.6508086 0.5968644 0.5658027 0.6109360 0.6567755
  [8] 0.6061405 0.5733140 0.6005756 0.6280033 0.6435557 0.6698231 0.7161950
 [15] 0.7365786 0.7528205 0.8049371 0.7898944 0.8225097 0.8678371 0.9272548
 [22] 0.9742486 0.9804581 1.0771285 1.1104515 1.1471694 1.2057320 1.2704004
 [29] 1.3123336 1.3783760 1.4999898 1.5715452 1.5932780 1.6505608 1.7606218
 [36] 1.7667835 1.8293516 1.8695368 1.9097981 1.9551338 2.0059362 2.1147994
 [43] 2.1527060 2.1886304 2.2972661 2.4160437 2.4421950 2.4669107 2.4909263
 [50] 2.5243503 2.5224441 2.5240943 2.5953401 2.6149915 2.7037747 2.7350338
 [57] 2.8199104 2.9280315 3.0334148 3.0761166 3.0888172 3.1504843 3.1792681
 [64] 3.1711703 3.1502549 3.1798364 3.2005116 3.2107623 3.2448449 3.3777179
 [71] 3.4097859 3.3733659 3.4778518 3.5125684 3.6048906 3.7384782 3.8787807
 [78] 4.0565227 4.1044334 4.1646354 4.2404381 4.3199907 4.3256961 4.3834520
 [85] 4.4444224 4.5190063 4.5760211 4.6564349 4.7633190 4.7922302 4.8453810
 [92] 4.8934182 4.9603479 4.9792846 4.9599485 4.9006939 4.9540365 4.9994692
 [99] 5.0173693 5.0734275

$nlag
[1] 18

$accurate
          SST           SSE           MSE          RMSE          MAPE 
 3.764954e+02  1.084435e+02  1.095388e+00  1.046608e+00  8.723922e+01 
          MPE           MAE            ME     R.squared R.adj.squared 
 3.020073e+01  8.150173e-01  3.684542e-02  7.119661e-01  7.119661e-01 
 RW.R.squared           AIC           SBC           APC 
-4.550608e+16  1.010587e+01  1.271104e+01  1.106342e+00 

attr(,"class")
[1] "MA"
$estimate
          Jan      Feb      Mar      Apr      May      Jun      Jul      Aug
1959 317.0796 317.0890 317.1194 317.1554 317.2053 317.2825 317.3730 317.4459
1960 317.4247 317.4377 317.4700 317.5119 317.5632 317.6231 317.6914 317.7526
1961 317.7642 317.7751 317.7956 317.8292 317.8679 317.9218 317.9748 318.0227
1962 318.0606 318.0748 318.1028 318.1415 318.1885 318.2493 318.3129 318.3716
1963 318.4968 318.5438 318.5933 318.6386 318.6911 318.7756 318.8851 318.9953
1964 319.2715 319.3186 319.3566 319.3901 319.4363 319.5100 319.6139 319.7343
1965 320.0412 320.0881 320.1367 320.1780 320.2410 320.3278 320.4416 320.5675
1966 320.9075 320.9551 321.0031 321.0566 321.1245 321.2161 321.3308 321.4532
1967 321.8141 321.8706 321.9222 321.9698 322.0311 322.1175 322.2374 322.3702
1968 322.7281 322.7830 322.8389 322.8971 322.9600 323.0599 323.1820 323.3152
1969 323.7212 323.7928 323.8616 323.9412 324.0318 324.1424 324.2886 324.4417
1970 324.9281 324.9953 325.0559 325.1273 325.2104 325.3205 325.4573 325.6035
1971 326.0343 326.1045 326.1688 326.2378 326.3232 326.4389 326.5791 326.7332
1972 327.1690 327.2428 327.3151 327.3902 327.4776 327.5898 327.7270 327.8774
1973 328.3037 328.3687 328.4359 328.5008 328.5867 328.6961 328.8367 328.9859
1974 329.4485 329.5228 329.5962 329.6748 329.7713 329.8940 330.0371 330.1961
1975 330.6841 330.7676 330.8583 330.9425 331.0434 331.1672 331.3181 331.4892
1976 332.0065 332.1030 332.1920 332.2812 332.3994 332.5361 332.6988 332.8743
1977 333.3987 333.4837 333.5668 333.6527 333.7528 333.8778 334.0240 334.1824
1978 334.6851 334.7724 334.8594 334.9510 335.0633 335.1965 335.3548 335.5259
1979 336.0606 336.1515 336.2382 336.3301 336.4323 336.5725 336.7411 336.9211
1980 337.5067 337.6087 337.7067 337.8101 337.9277 338.0782 338.2554 338.4433
1981 339.0539 339.1561 339.2517 339.3512 339.4711 339.6153 339.7889 339.9680
1982 340.5440 340.6398 340.7314 340.8275 340.9346 341.0744 341.2413 341.4216
1983 342.0032 342.0992 342.1974 342.2941 342.4028 342.5452 342.7144 342.9006
1984 343.5020 343.5974 343.7012 343.8114 343.9302 344.0810 344.2596 344.4520
1985 345.0918 345.1990 345.3095 345.4189 345.5420 345.7027 345.8883 346.0867
1986 346.7271 346.8329 346.9416 347.0555 347.1851 347.3373 347.5239 347.7202
1987 348.3797 348.4995 348.6051 348.7131 348.8410 348.9987 349.1816 349.3798
1988 349.9853 350.0904 350.1872 350.2881 350.4074 350.5563 350.7334 350.9299
1989 351.5051 351.5919 351.6829 351.7728 351.8830 352.0231 352.1922 352.3710
1990 352.9191 353.0170 353.1134 353.2087 353.3225 353.4675 353.6389 353.8138
1991 354.3960 354.5016 354.6003 354.7011 354.8149 354.9671 355.1381 355.3212
1992 355.8865 355.9799 356.0732 356.1727 356.2849 356.4198 356.5830 356.7600
1993 357.2962 357.3914 357.4771 357.5689 357.6726 357.8086 357.9733 358.1458
1994 358.6755 358.7734 358.8032 358.8230 358.8536 358.9006 358.9703 359.0640
1995 359.3970 359.4262 359.4380 359.4408 359.4577 359.5018 359.5753 359.6756
1996 360.0360 360.0696 360.0843 360.0918 360.1058 360.1545 360.2362 360.3521
1997 360.7897 360.8330 360.8584 360.8698 360.8943 360.9577 361.0631 361.2080
          Sep      Oct      Nov      Dec
1959 317.4847 317.4870 317.4618 317.4336
1960 317.7901 317.8012 317.7829 317.7676
1961 318.0610 318.0691 318.0641 318.0528
1962 318.4141 318.4335 318.4340 318.4611
1963 319.0942 319.1598 319.1992 319.2312
1964 319.8451 319.9215 319.9661 320.0023
1965 320.6811 320.7624 320.8201 320.8614
1966 321.5705 321.6566 321.7146 321.7611
1967 322.4925 322.5824 322.6361 322.6790
1968 323.4353 323.5281 323.5940 323.6560
1969 324.5875 324.6999 324.7870 324.8575
1970 325.7441 325.8473 325.9161 325.9703
1971 326.8675 326.9680 327.0389 327.1010
1972 328.0151 328.1184 328.1872 328.2404
1973 329.1272 329.2337 329.3140 329.3795
1974 330.3410 330.4556 330.5377 330.6062
1975 331.6415 331.7629 331.8478 331.9242
1976 333.0286 333.1478 333.2374 333.3177
1977 334.3254 334.4358 334.5223 334.6029
1978 335.6837 335.8058 335.8961 335.9763
1979 337.0892 337.2278 337.3257 337.4143
1980 338.6201 338.7596 338.8604 338.9511
1981 340.1335 340.2655 340.3648 340.4489
1982 341.5870 341.7158 341.8223 341.9076
1983 343.0687 343.2063 343.3108 343.4004
1984 344.6282 344.7716 344.8846 344.9885
1985 346.2702 346.4135 346.5232 346.6228
1986 347.9028 348.0498 348.1627 348.2685
1987 349.5544 349.6935 349.7928 349.8852
1988 351.0994 351.2297 351.3254 351.4161
1989 352.5313 352.6541 352.7432 352.8275
1990 353.9811 354.1102 354.2083 354.2960
1991 355.4906 355.6182 355.7185 355.7997
1992 356.9211 357.0461 357.1357 357.2115
1993 358.3038 358.4267 358.5113 358.5901
1994 359.1573 359.2334 359.2949 359.3516
1995 359.7778 359.8619 359.9310 359.9880
1996 360.4669 360.5715 360.6588 360.7271
1997 361.3532 361.4767 361.5746 361.6434

$nlag
[1] 46

$accurate
          SST           SSE           MSE          RMSE          MAPE 
 1.046023e+05  2.335284e+03  5.000609e+00  2.236204e+00  5.602060e-01 
          MPE           MAE            ME     R.squared R.adj.squared 
-2.410122e-04  1.891952e+00  2.871285e-02  9.776746e-01  9.776746e-01 
 RW.R.squared           AIC           SBC           APC 
 8.231147e+17  7.542729e+02  7.584213e+02  5.011294e+00 

attr(,"class")
[1] "MA"

aTSA documentation built on May 1, 2019, 8:47 p.m.