sma() - Simple Moving Average

Ivan Svetunkov

2023-09-16

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 - 2119.2666; Order 58 - 2137.8509; Order 115 - 2166.153
## Order 1 - 2119.2666; Order 29 - 2110.5061; Order 58 - 2137.8509
## Order 1 - 2119.2666; Order 15 - 2088.1727; Order 29 - 2110.5061
## Order 15 - 2088.1727; Order 22 - 2101.2155; Order 29 - 2110.5061
## Order 15 - 2088.1727; Order 18 - 2093.1735; Order 22 - 2101.2155
## Order 15 - 2088.1727; Order 16 - 2088.1798; Order 18 - 2093.1735
## Order 12 - 2087.6726
## Time elapsed: 0.01 seconds
## Model estimated using sma() function: SMA(12)
## Distribution assumed in the model: Normal
## Loss function type: MSE; Loss function value: 4403812
## ARMA parameters of the model:
## AR:
##  phi1[1]  phi2[1]  phi3[1]  phi4[1]  phi5[1]  phi6[1]  phi7[1]  phi8[1] 
##   0.0833   0.0833   0.0833   0.0833   0.0833   0.0833   0.0833   0.0833 
##  phi9[1] phi10[1] phi11[1] phi12[1] 
##   0.0833   0.0833   0.0833   0.0833 
## 
## Sample size: 115
## Number of estimated parameters: 0
## Number of degrees of freedom: 115
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 2085.624 2085.624 2085.624 2085.624

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.