Movatterモバイル変換


[0]ホーム

URL:


sma() - Simple Moving Average

Ivan Svetunkov

2025-10-24

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

Let’s load the necessary packages:

require(smooth)

By default SMA does order selection based on AICc and returns themodel 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 - 2135.2066; Order 115 - 2157.6146## Order 1 - 2119.2666; Order 29 - 2109.953; Order 58 - 2135.2066## Order 1 - 2119.2666; Order 15 - 2088.1914; Order 29 - 2109.953## Order 15 - 2088.1914; Order 22 - 2101.1263; Order 29 - 2109.953## Order 15 - 2088.1914; Order 18 - 2093.311; Order 22 - 2101.1263## Order 15 - 2088.1914; Order 16 - 2088.1965; Order 18 - 2093.311## Order 12 - 2087.6591
## Time elapsed: 0.02 seconds## Model estimated using sma() function: SMA(12)## With backcasting initialisation## Distribution assumed in the model: Normal## Loss function type: MSE; Loss function value: 4385475## 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: 1## Number of degrees of freedom: 114## Information criteria:##      AIC     AICc      BIC     BICc ## 2087.144 2087.179 2089.889 2089.973

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 usedin construction of point forecasts up to h=13.


[8]ページ先頭

©2009-2025 Movatter.jp