Ch 4. – Exponential Smoothing – Computing in JMP Example 1: Dow Jones Index (pgs. 176 – 187) To begin we select Modeling > Time Series which will produce a plot of the time series and compute ACF and PACF (discussed later) for the time series. Notice the note that appears to the right of the Modeling drop-down menu. We can see that in addition to the ACF plots, there are options to fit models to the time series and make forecasts from them. Smoothing models are the exponential smoothing models we are examining in Chapter 4. The dialog box to begin modeling the Dow Jones Index is shown below. Notice the time series data must be evenly spaced, i.e. daily, weekly, quarterly, or annually in general. 1 Below is the default output from the Time Series modeling option. To fit exponential smoother models we select the model we wish to fit using the Smoothing Model pull-out menu as shown below. 2 Simple exponential smoothing – is appropriate when there is no trend or seasonal pattern in the data, but the mean (or level) of the time series ๐ฆ๐ก is changing slowly over time. Double exponential smoothing – is appropriate where there is evidence of some linear trends in the data. Simple exponential smoothing will tend to over or under estimate the time series when there are some linear trends in the time series. Simple exponential smoothing with a large ๐ will decrease the over or under estimate problem, but a double exponential smooth will generally handle it better. Linear exponential smoothing – is appropriate when both the mean (or level) and the growth rate (slope of linear trends) are changing over time. This is also referred to as Holt’s Trend Corrected exponential smoothing. In situations where a double exponential smooth is appropriate, this method would be appropriate as well. Seasonal exponential smoothing – is appropriate when there is a seasonal pattern in the time series, but not much in terms of long-term linear trend. In other words, the level is not changing a great deal but there strong seasonal patterns on top of a fairly constant mean (or level). Winter’s Method – is appropriate when there is a seasonal pattern on top of a long-term trend. 3 For the Dow Jones Index time series we see there is no evidence of a seasonal effect, but the trend does have some linear trends in, e.g. between February 2003 and February 2004. We first fit a simple exponential smooth to this time series. Above and to the left are the results of a simple exponential smooth fit to the DJI time series. We can see the optimal ๐ chosen automatically by JMP is ๐ = .842, which is quite large. The ๐ 2 = 78.63% which is quite good. The mean absolute percent error (MAPE) = 3.24% and the mean absolute error/deviation (MAD) = 319.94. The forecasts for the next 25 time periods are shown graphically and as you can see are constant. This is because for a simple exponential smooth the forecasts for the next time periods, regardless of how far into the future we look, is ๐ฆ ฬ๐ the last smoothed value from the exponential smooth of the data. The prediction interval gets wider the further out we look as shown by the formula in your notes. 4 The residuals plotted versus time are shown above and the ACF plot of the residuals is shown below. The residuals are consistent with white noise as there are no significant autocorrelations at lags > 1. 5 You can save the actual forecasts as the prediction intervals to the spreadsheet by selecting the Save Prediction Formula from the Model: Simple Exponential Smoothing (Zero to One) drop-down menu. The columns above are: Actual DJI – original time series (๐ฆ๐ก ) DJI Prediction Formula – the smoothed or fitted values (๐ฆฬ๐ก ) Time – duh? 6 Predicted DJI – the same as DJI Prediction Formula Std Error Pred DJI - s in the formulae in class unless it is a future forecast in which case is equal to ๐ √1 + (๐ − 1)๐2 for ๐ ≥ 1. Residual DJI – are the one-step ahead forecast errors for the original time series. These are used to compute SSE etc. which are minimized to find an optimal ๐. Upper (.95) DJI – upper limit of the prediction interval. Lower (.95) DJI – lower limit of the prediction interval. These columns will be the same for all forecast smoothers, how the predicted values and the standard errors for prediction are computed of course will change with the smoothing model used. We now consider a double exponential smooth model fit to this times series. You DO NOT need to start from scratch, you can actually just select that option from the same menu we used to fit the simple exponential smooth. This will fit the double exponential smooth and show the summary statistics for the fit right next to those from the simple exponential smooth as shown below. 7 We can see the double exponential smooth has a smaller ๐ 2 , thus there appears to be no advantage to this approach over the simple exponential smooth. We see the predictions or forecasts made from a double exponential smooth have a linear trend. The prediction intervals get large fast. 8 Linear Exponential Smoothing (a.k.a. Holt’s Trend Corrected) Example: Weekly Thermostat Sales (Thermostat.JMP) As we can see this time series as a long term increasing trend, and the growth rate appears to fluctuate with time, thus a linear exponential smooth or possibly a double exponential seems appropriate. Fitting both a double exponential and linear trend exponential smooth to this time series produces very similar results. (๐ 2 = .557) 9 The estimated smoothing parameters for double exponential and linear smooths are shown below. There is one optimal parameter for the double exponential smooth (simple exponential smoothing with ๏ฌ = .161 twice) and two optimal parameters for the linear trend smooth (๏ก๏ ๏ฝ๏ ๏ฎ๏ฒ๏ท๏ธ๏ and ๏ง๏ ๏ฝ๏ ๏ฎ๏ฑ๏ฐ๏ณ๏ฉ๏ฎ๏ ๏ ๏ ๏ ๏ ๏ ๏ ๏ The prediction intervals for future forecasts for the next 25 weeks of thermostat sales are very similar, though it appears the linear trend exponential is a bit narrower. The residuals from the linear trend exponential smoother are shown to the right. The residual series certainly appears to be stationary. 10 The predictions for the linear exponential smooth are shown below. … 11 Holt-Winters Method Holt-Winter’s Method of exponential smoothing is for time series with both a long-term trend and a seasonal trend on top of it. Example: Monthly Liquor Sales (1980-2000) – (U.S. Monthly Liquor Sales.JMP) The time series and ACF & PACF (soon to be discussed) are shown above. The time series clearly exhibits a long-term trend with a strong seasonal trend on top. The seasonal variation however seems get larger over time! This may present a problem! 12 Fitting a Holt-Winter’s exponential smooth this time series yields the results shown below. The ๐ 2 = 98.8% indicating a very good fit to the time series. The trend weight is essentially ๏ง๏ ๏ฝ๏ 0, suggesting the linear trend part of the smooth is not strong and level smooth essentially takes care of the long-term trend. 13 The residuals exhibit a non-constant variation. There is a multiplicative form of the Holt-Winter’s Method which will model the nonconstant nature of the seasonal variation, however it is not implemented in JMP. One way to handle the non-constant seasonal variation is to take the natural log (or any other base) of the liquor sales before smoothing. The log base 10 of the liquor sales (i.e. log10 (๐ฟ๐๐๐ข๐๐ ๐๐๐๐๐ )) is shown below. Note: I just called the logged time series ln(LS). 14 The residuals now appear to have constant variation. The forecasts of liquor sales in the log scale for next 25-months are shown below. To back-transform the predictions to the original scale we need exponentiate the results, i.e. … ๐๐๐๐๐๐๐๐ ๐ ๐๐๐๐ = 10 ๐๐๐๐๐๐๐ก๐๐๐ 15 The prediction intervals for liquor sales in the next 25 months are shown above. The highlighted columns were obtained by using the JMP calculator to back-transform the Upper CL and Lower CL in the two preceding columns. The Lower PI and Upper PI formulae in the JMP calculator are shown below. After back-transforming we have what should prove to be very good forecasts for the liquor sales for the next 25 months; assuming the current trends continue. 16 In the forecast library from CRAN there are a number of exponential smoothers that can be used to fit an exponential smooth model and make forecasts. > Sales.ts = ts(Sales,start=1980,frequency=12) > tsdisplay(Sales.ts) Additive Holt-Winter’s Fit > liquor.hw = hw(Sales.ts,seasonal="additive") > summary(liquor.hw) Forecast method: Holt-Winters' additive method Model Information: ETS(A,A,A) Call: hw(x = Sales.ts, seasonal = "additive") Smoothing alpha = beta = gamma = parameters: 0.3335 1e-04 0.4983 Initial states: l = 636.7332 b = 3.4108 s=513.0279 12.4489 -29.1804 -53.4223 24.0255 61.7841 1.913 -6.7716 -88.659 -96.9889 -198.7712 -139.406 sigma: 54.367 17 AIC AICc BIC 4671.698 4673.403 4732.772 Training set error measures: ME RMSE MAE MPE -0.02626900 54.36696148 38.55693750 -0.05075231 Forecasts: Point Jan 2008 Feb 2008 Mar 2008 Apr 2008 May 2008 Jun 2008 Jul 2008 Aug 2008 Sep 2008 Oct 2008 Nov 2008 Dec 2008 Jan 2009 Feb 2009 Mar 2009 Apr 2009 May 2009 Jun 2009 Jul 2009 Aug 2009 Sep 2009 Oct 2009 Nov 2009 Dec 2009 Forecast 1551.706 1513.810 1689.579 1721.138 1805.449 1817.071 1943.510 1832.384 1770.948 1782.941 1817.635 2467.998 1592.625 1554.729 1730.498 1762.057 1846.368 1857.990 1984.429 1873.303 1811.867 1823.859 1858.554 2508.917 Lo 80 1482.032 1440.358 1612.532 1640.655 1721.669 1730.117 1853.491 1739.400 1675.089 1684.288 1716.265 2351.188 1473.509 1433.348 1606.893 1636.266 1718.427 1727.933 1852.289 1739.111 1675.652 1685.651 1718.378 2357.169 Hi 80 1621.380 1587.262 1766.625 1801.621 1889.229 1904.026 2033.530 1925.369 1866.807 1881.593 1919.005 2584.807 1711.742 1676.110 1854.103 1887.848 1974.309 1988.047 2116.570 2007.496 1948.082 1962.068 1998.729 2660.664 Lo 95 1445.149 1401.475 1571.746 1598.050 1677.318 1684.085 1805.838 1690.177 1624.344 1632.065 1662.603 2289.353 1410.452 1369.093 1541.460 1569.676 1650.699 1659.085 1782.338 1668.074 1603.544 1612.487 1644.174 2276.838 MAPE 3.30142685 MASE 0.26527642 Hi 95 1658.264 1626.145 1807.411 1844.226 1933.580 1950.057 2081.183 1974.592 1917.552 1933.816 1972.667 2646.642 1774.798 1740.365 1919.535 1954.438 2042.037 2056.895 2186.520 2078.533 2020.189 2035.231 2072.934 2740.995 18 Multiplicative Holt-Winter’s Fit > liquor.mhw = hw(Sales.ts,seasonal=”multiplicative”) > summary(liquor.mhw) Forecast method: Holt-Winters' multiplicative method Model Information: ETS(M,A,M) Call: hw(x = Sales.ts, seasonal = "multiplicative") Smoothing alpha = beta = gamma = parameters: 0.6154 0.0104 1e-04 Initial states: l = 539.7408 b = 4.4147 s=1.389 1.0075 0.9774 0.9615 1.0217 1.0484 0.9986 0.9956 0.9295 0.9261 0.8494 0.8953 sigma: 0.0299 AIC AICc BIC 4396.707 4398.412 4457.781 Training set error measures: ME RMSE MAE MPE -0.9843634 42.7434366 30.3659230 -0.1179324 Forecasts: Point Jan 2008 Feb 2008 Mar 2008 Apr 2008 May 2008 Jun 2008 Jul 2008 Aug 2008 Sep 2008 Oct 2008 Nov 2008 Dec 2008 Jan 2009 Feb 2009 Mar 2009 Apr 2009 May 2009 Jun 2009 Jul 2009 Aug 2009 Sep 2009 Oct 2009 Nov 2009 Dec 2009 Forecast 1572.505 1492.283 1627.464 1633.908 1750.419 1756.259 1844.296 1797.695 1692.285 1720.667 1774.231 2446.580 1577.369 1496.898 1632.496 1638.958 1755.828 1761.685 1849.993 1803.246 1697.510 1725.978 1779.706 2454.127 Lo 80 1512.278 1424.853 1543.911 1540.770 1641.347 1637.971 1711.170 1659.551 1554.585 1573.067 1614.380 2215.791 1422.001 1343.307 1458.369 1457.564 1554.519 1552.757 1623.349 1575.312 1476.372 1494.482 1534.175 2106.167 Hi 80 1632.732 1559.712 1711.018 1727.045 1859.490 1874.547 1977.423 1935.838 1829.986 1868.267 1934.082 2677.368 1732.738 1650.489 1806.623 1820.352 1957.138 1970.613 2076.637 2031.180 1918.648 1957.473 2025.236 2802.086 MAPE 2.3613634 Lo 95 1480.395 1389.158 1499.680 1491.466 1583.608 1575.354 1640.698 1586.423 1481.690 1494.933 1529.759 2093.619 1339.754 1262.001 1366.192 1361.540 1447.952 1442.157 1503.371 1454.652 1359.308 1371.936 1404.199 1921.969 MASE 0.2089212 Hi 95 1664.614 1595.407 1755.249 1776.349 1917.229 1937.165 2047.895 2008.967 1902.880 1946.402 2018.703 2799.540 1814.985 1731.795 1898.801 1916.377 2063.705 2081.213 2196.616 2151.841 2035.711 2080.020 2155.212 2986.285 19 Other exponential smoothers are also available in the forecast package. ๏ท ๏ท ๏ท ses – this function performs simple exponential smoothing. holt – this function performs linear exponential smooth (Holt Trend Corrected), which is very comparable to double exponential smoothing. hw – does Holt-Winter’s seasonal smoothing as shown above. Both additive and multiplicative options are available. Even though it is in appropriate to apply simple exponential and linear exponential smoothing to these data, I will demonstrate the use of these smoothers for the liquor sales data. > Sales.ses = ses(Sales.ts,h=24) > Sales.ses Point Forecast Lo 80 Jan 2008 1841.114 1586.415 Feb 2008 1841.114 1584.635 Mar 2008 1841.114 1582.867 Apr 2008 1841.114 1581.111 May 2008 1841.114 1579.367 Jun 2008 1841.114 1577.634 Jul 2008 1841.114 1575.913 Aug 2008 1841.114 1574.203 Sep 2008 1841.114 1572.504 Oct 2008 1841.114 1570.815 Nov 2008 1841.114 1569.137 Dec 2008 1841.114 1567.469 Jan 2009 1841.114 1565.812 Feb 2009 1841.114 1564.164 Mar 2009 1841.114 1562.526 Apr 2009 1841.114 1560.897 Hi 80 2095.814 2097.594 2099.362 2101.118 2102.862 2104.595 2106.316 2108.026 2109.725 2111.414 2113.092 2114.760 2116.417 2118.065 2119.703 2121.332 Lo 95 1451.585 1448.863 1446.159 1443.473 1440.806 1438.156 1435.524 1432.909 1430.310 1427.727 1425.161 1422.610 1420.075 1417.555 1415.050 1412.559 Hi 95 2230.644 2233.366 2236.070 2238.755 2241.423 2244.073 2246.705 2249.320 2251.919 2254.502 2257.068 2259.619 2262.154 2264.674 2267.179 2269.670 20 May Jun Jul Aug Sep Oct Nov Dec 2009 2009 2009 2009 2009 2009 2009 2009 1841.114 1841.114 1841.114 1841.114 1841.114 1841.114 1841.114 1841.114 1559.278 1557.669 1556.068 1554.476 1552.893 1551.319 1549.753 1548.195 2122.951 2124.560 2126.161 2127.753 2129.336 2130.910 2132.476 2134.033 1410.083 1407.621 1405.173 1402.739 1400.318 1397.910 1395.515 1393.134 2272.146 2274.608 2277.056 2279.490 2281.911 2284.319 2286.713 2289.095 Lo 95 1502.727 1505.844 1508.960 1512.077 1515.193 1518.308 1521.424 1524.539 1527.653 1530.768 1533.882 1536.995 1540.109 1543.222 1546.334 1549.447 1552.559 Hi 95 2265.938 2270.960 2275.982 2281.005 2286.028 2291.051 2296.075 2301.099 2306.123 2311.148 2316.173 2321.198 2326.223 2331.249 2336.276 2341.302 2346.329 > plot(Sales.ses) > Sales.holt = > Sales.holt Point Jan 2008 Feb 2008 Mar 2008 Apr 2008 May 2008 Jun 2008 Jul 2008 Aug 2008 Sep 2008 Oct 2008 Nov 2008 Dec 2008 Jan 2009 Feb 2009 Mar 2009 Apr 2009 May 2009 holt(Sales.ts,h=24) Forecast 1884.332 1888.402 1892.471 1896.541 1900.610 1904.680 1908.749 1912.819 1916.888 1920.958 1925.027 1929.097 1933.166 1937.235 1941.305 1945.374 1949.444 Lo 80 1634.814 1638.260 1641.707 1645.153 1648.599 1652.045 1655.491 1658.936 1662.381 1665.826 1669.271 1672.715 1676.160 1679.604 1683.047 1686.491 1689.935 Hi 80 2133.851 2138.543 2143.236 2147.928 2152.621 2157.314 2162.008 2166.701 2171.395 2176.089 2180.783 2185.478 2190.172 2194.867 2199.562 2204.258 2208.953 21 Jun Jul Aug Sep Oct Nov Dec 2009 2009 2009 2009 2009 2009 2009 1953.513 1957.583 1961.652 1965.722 1969.791 1973.861 1977.930 1693.378 1696.821 1700.263 1703.706 1707.148 1710.590 1714.032 2213.649 2218.345 2223.041 2227.738 2232.434 2237.131 2241.828 1555.670 1558.782 1561.893 1565.003 1568.113 1571.223 1574.333 2351.357 2356.384 2361.412 2366.440 2371.469 2376.498 2381.528 > plot(Sales.holt) 22