sma() - Simple Moving Average

Simple Moving Average is a method of time series smoothing and is actually a very basic forecasting technique. It does not need estimation of parameters, but rather is based on order selection. It is a part of smooth package.

Let’s load the necessary packages:

require(smooth)

By default SMA does order selection based on AICc and returns the model with the lowest value:

y <- structure(c(2158.1, 1086.4, 1154.7, 1125.6, 920, 2188.6, 829.2, 
                 1353.1, 947.2, 1816.8, 1624.5, 868.5, 1783.3, 1713.1, 3479.7, 
                 2429.4, 3074.3, 3427.4, 2783.7, 1968.7, 2045.6, 1471.3, 2763.7, 
                 2328.4, 1821, 2409.8, 3485.8, 3289.2, 3048.3, 2914.1, 2173.9, 
                 3018.4, 2200.1, 6844.3, 4160.4, 1548.8, 3238.9, 3252.2, 3278.8, 
                 1766.8, 3572.8, 3467.6, 7464.7, 2748.4, 5126.7, 2870.8, 2170.2, 
                 4326.8, 3220.7, 3586, 3249.5, 3222.5, 2488.5, 3332.4, 2036.1, 
                 1968.2, 2967.2, 3151.6, 1610.5, 3985, 3894.1, 4625.5, 3291.7, 
                 3065.6, 2316.5, 2453.4, 4582.8, 2291.2, 3555.5, 1785, 2020, 2026.8, 
                 2102.9, 2307.7, 6242.1, 6170.5, 1863.5, 6318.9, 3992.8, 3435.1, 
                 1585.8, 2106.8, 1892.1, 4310.6, 6168, 7247.4, 3579.7, 6365.2, 
                 4658.9, 6911.8, 2143.7, 5973.9, 4017.2, 4473, 3591.9, 4676.5, 
                 8749.1, 11931.2, 8572.3, 8257.7, 11930.5, 15757.6, 5920.5, 3064.3, 
                 5472, 8634.7, 5032, 6236, 6356, 9857.8, 6322.2, 7907, 13842.4, 
                 13665.1, 3272), tsp = c(1983, 1992.5, 12), class = "ts")
sma(y, h=18, silent=FALSE)
## Order 1 - 2121.3383; Order 56 - 2361.8579; Order 112 - 28143.5094
## Order 1 - 2121.3383; Order 28 - 2183.7946; Order 56 - 2361.8579
## Order 1 - 2121.3383; Order 14 - 2120.4011; Order 28 - 2183.7946
## Order 1 - 2121.3383; Order 7 - 2118.0868; Order 14 - 2120.4011
## Order 7 - 2118.0868; Order 10 - 2119.8181; Order 14 - 2120.4011
## Order 7 - 2118.0868; Order 8 - 2116.3295; Order 10 - 2119.8181
## Order 12 - 2115.2251
## Time elapsed: 0.03 seconds
## Model estimated using sma() function: SMA(12)
## With backcasting initialisation
## Distribution assumed in the model: Normal
## Loss function type: MSE; Loss function value: 4403713
## ARMA parameters of the model:
##         Lag 1
## AR(1)  0.0833
## AR(2)  0.0833
## AR(3)  0.0833
## AR(4)  0.0833
## AR(5)  0.0833
## AR(6)  0.0833
## AR(7)  0.0833
## AR(8)  0.0833
## AR(9)  0.0833
## AR(10) 0.0833
## AR(11) 0.0833
## AR(12) 0.0833
## 
## Sample size: 115
## Number of estimated parameters: 13
## Number of degrees of freedom: 102
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2111.621 2115.225 2147.305 2155.856

It appears that SMA(13) is the optimal model for this time series, which is not obvious. Note also that the forecast trajectory of SMA(13) is not just a straight line. This is because the actual values are used in construction of point forecasts up to h=13.