sma() - Simple Moving Average

knitr::opts_chunk$set(fig.width=6, fig.height=4, fig.path='Figs/', fig.show='hold',
                      warning=FALSE, message=FALSE)

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)

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.



Try the smooth package in your browser

Any scripts or data that you put into this service are public.

smooth documentation built on Sept. 17, 2023, 9:06 a.m.