Exponential Smoothing Model

By Salerno | December 18, 2019

Introduction

The main idea here is breaking the ice in terms of exponential smoothing models

First of all it is importan to show some behaviours patterns usually found in time series

  1. Trends: it is usually observed when the time series follow one specific direction. It can be linear or not.

  2. Seasonality: it is a pattern that repeat in a certain times (specific period)

  3. Cycle: Like seasonality but it appears in non specific time

library(fpp)
## Carregando pacotes exigidos: forecast
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Registered S3 methods overwritten by 'forecast':
##   method             from    
##   fitted.fracdiff    fracdiff
##   residuals.fracdiff fracdiff
## Carregando pacotes exigidos: fma
## Carregando pacotes exigidos: expsmooth
## Carregando pacotes exigidos: lmtest
## Carregando pacotes exigidos: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Carregando pacotes exigidos: tseries

data(elecequip)

plot(elecequip, xlab = "Time", ylab = "New Orders Index")

decomp <- decompose(elecequip, type = "additive")
plot(decomp)

seasonality_adjust <- elecequip - decomp$seasonal
plot(seasonality_adjust)

library(mFilter)

hpfilter(elecequip, type = "lambda")
## 
## Title:
##  Hodrick-Prescott Filter 
## 
## Call:
##  hpfilter(x = elecequip, type = "lambda")
## 
## Method:
##  hpfilter
## 
## Filter Type:
##  lambda
## 
## Series:
##  elecequip
## 
##          elecequip  Trend    Cycle
## Jan 1996     79.43  77.77   1.6588
## Feb 1996     75.86  78.17  -2.3142
## Mar 1996     86.40  78.58   7.8227
## Apr 1996     72.67  78.98  -6.3103
## May 1996     74.93  79.38  -4.4535
## Jun 1996     83.88  79.79   4.0933
## Jul 1996     79.88  80.19  -0.3099
## Aug 1996     62.47  80.59 -18.1232
## Sep 1996     85.50  81.00   4.5035
## Oct 1996     83.19  81.40   1.7903
## Nov 1996     84.29  81.80   2.4873
## Dec 1996     89.79  82.21   7.5845
## Jan 1997     78.72  82.61  -3.8879
## Feb 1997     77.49  83.01  -5.5199
## Mar 1997     89.94  83.41   6.5285
## Apr 1997     81.35  83.81  -2.4627
## May 1997     78.76  84.21  -5.4533
## Jun 1997     89.59  84.61   4.9767
## Jul 1997     83.75  85.01  -1.2626
## Aug 1997     69.87  85.41 -15.5412
## Sep 1997     91.18  85.81   5.3710
## Oct 1997     89.52  86.21   3.3142
## Nov 1997     91.12  86.60   4.5185
## Dec 1997     92.97  87.00   5.9741
## Jan 1998     81.97  87.39  -5.4190
## Feb 1998     85.26  87.78  -2.5207
## Mar 1998     93.09  88.17   4.9190
## Apr 1998     81.19  88.56  -7.3697
## May 1998     85.74  88.95  -3.2068
## Jun 1998     91.24  89.33   1.9079
## Jul 1998     83.56  89.72  -6.1556
## Aug 1998     66.45  90.10 -23.6470
## Sep 1998     93.45  90.48   2.9737
## Oct 1998     86.03  90.85  -4.8230
## Nov 1998     86.91  91.23  -4.3169
## Dec 1998     93.42  91.60   1.8226
## Jan 1999     81.68  91.96 -10.2844
## Feb 1999     81.68  92.33 -10.6472
## Mar 1999     91.35  92.69  -1.3356
## Apr 1999     79.55  93.04 -13.4889
## May 1999     87.08  93.39  -6.3065
## Jun 1999     96.71  93.73   2.9822
## Jul 1999     98.10  94.06   4.0379
## Aug 1999     79.22  94.39 -15.1686
## Sep 1999    103.68  94.71   8.9732
## Oct 1999    101.00  95.02   5.9842
## Nov 1999     99.52  95.31   4.2050
## Dec 1999    111.94  95.60  16.3364
## Jan 2000     95.42  95.88  -0.4610
## Feb 2000     98.49  96.15   2.3432
## Mar 2000    116.37  96.40  19.9697
## Apr 2000    101.09  96.64   4.4488
## May 2000    104.20  96.87   7.3309
## Jun 2000    114.79  97.08  17.7064
## Jul 2000    107.75  97.28  10.4654
## Aug 2000     96.23  97.47  -1.2419
## Sep 2000    123.65  97.65  26.0045
## Oct 2000    116.24  97.81  18.4346
## Nov 2000    117.00  97.95  19.0483
## Dec 2000    128.75  98.08  30.6653
## Jan 2001    100.69  98.20   2.4851
## Feb 2001    102.99  98.31   4.6771
## Mar 2001    119.21  98.41  20.8005
## Apr 2001     92.56  98.50  -5.9355
## May 2001     98.86  98.57   0.2884
## Jun 2001    111.26  98.64  12.6211
## Jul 2001     96.25  98.70  -2.4480
## Aug 2001     79.81  98.75 -18.9401
## Sep 2001    102.18  98.80   3.3840
## Oct 2001     96.28  98.84  -2.5565
## Nov 2001    101.38  98.87   2.5076
## Dec 2001    109.97  98.90  11.0654
## Jan 2002     89.66  98.93  -9.2739
## Feb 2002     89.23  98.96  -9.7311
## Mar 2002    104.36  98.99   5.3729
## Apr 2002     87.17  99.01 -11.8426
## May 2002     89.43  99.04  -9.6085
## Jun 2002    102.25  99.07   3.1845
## Jul 2002     88.26  99.09 -10.8342
## Aug 2002     75.73  99.13 -23.3952
## Sep 2002     99.60  99.16   0.4409
## Oct 2002     96.57  99.20  -2.6263
## Nov 2002     96.22  99.24  -3.0173
## Dec 2002    101.12  99.28   1.8377
## Jan 2003     89.45  99.33  -9.8818
## Feb 2003     86.87  99.39 -12.5161
## Mar 2003     98.94  99.45  -0.5055
## Apr 2003     85.62  99.51 -13.8902
## May 2003     85.31  99.58 -14.2703
## Jun 2003    101.22  99.66   1.5639
## Jul 2003     91.93  99.74  -7.8073
## Aug 2003     77.01  99.82 -22.8141
## Sep 2003    104.50  99.92   4.5836
## Oct 2003     99.83 100.01  -0.1838
## Nov 2003    101.10 100.12   0.9837
## Dec 2003    109.16 100.22   8.9365
## Jan 2004     89.93 100.34 -10.4052
## Feb 2004     92.73 100.45  -7.7214
## Mar 2004    105.22 100.57   4.6482
## Apr 2004     91.56 100.70  -9.1361
## May 2004     92.60 100.82  -8.2241
## Jun 2004    104.46 100.96   3.5046
## Jul 2004     96.28 101.09  -4.8097
## Aug 2004     79.61 101.23 -21.6166
## Sep 2004    105.55 101.37   4.1842
## Oct 2004     99.15 101.51  -2.3567
## Nov 2004     99.81 101.65  -1.8387
## Dec 2004    113.72 101.79  11.9287
## Jan 2005     91.73 101.93 -10.2041
## Feb 2005     90.45 102.08 -11.6264
## Mar 2005    105.56 102.22   3.3423
## Apr 2005     92.15 102.36 -10.2076
## May 2005     91.23 102.50 -11.2652
## Jun 2005    108.95 102.63   6.3201
## Jul 2005     99.33 102.76  -3.4311
## Aug 2005     83.30 102.89 -19.5878
## Sep 2005    110.85 103.01   7.8405
## Oct 2005    104.99 103.13   1.8648
## Nov 2005    107.10 103.23   3.8660
## Dec 2005    114.38 103.34  11.0449
## Jan 2006     99.09 103.43  -4.3378
## Feb 2006     99.73 103.51  -3.7813
## Mar 2006    116.05 103.58  12.4651
## Apr 2006    103.51 103.65  -0.1378
## May 2006    102.99 103.70  -0.7093
## Jun 2006    119.45 103.74  15.7112
## Jul 2006    107.98 103.77   4.2145
## Aug 2006     90.50 103.78 -13.2789
## Sep 2006    121.85 103.78  18.0715
## Oct 2006    117.12 103.76  13.3563
## Nov 2006    113.66 103.73   9.9261
## Dec 2006    120.35 103.69  16.6612
## Jan 2007    103.92 103.63   0.2920
## Feb 2007    103.97 103.55   0.4187
## Mar 2007    125.63 103.46  22.1713
## Apr 2007    104.69 103.35   1.3402
## May 2007    108.36 103.22   5.1352
## Jun 2007    123.09 103.08  20.0065
## Jul 2007    108.88 102.93   5.9539
## Aug 2007     93.98 102.75  -8.7727
## Sep 2007    121.94 102.56  19.3764
## Oct 2007    116.79 102.36  14.4311
## Nov 2007    115.78 102.14  13.6409
## Dec 2007    127.28 101.90  25.3756
## Jan 2008    109.35 101.66   7.6945
## Feb 2008    105.64 101.39   4.2470
## Mar 2008    121.30 101.12  20.1821
## Apr 2008    108.62 100.83   7.7892
## May 2008    103.13 100.53   2.5971
## Jun 2008    117.84 100.23  17.6149
## Jul 2008    103.62  99.91   3.7116
## Aug 2008     89.22  99.58 -10.3642
## Sep 2008    109.41  99.25  10.1563
## Oct 2008    103.93  98.92   5.0121
## Nov 2008    100.07  98.58   1.4919
## Dec 2008    101.15  98.24   2.9144
## Jan 2009     77.33  97.89 -20.5617
## Feb 2009     75.01  97.55 -22.5376
## Mar 2009     86.31  97.20 -10.8945
## Apr 2009     74.09  96.86 -22.7734
## May 2009     74.09  96.53 -22.4351
## Jun 2009     85.58  96.19 -10.6104
## Jul 2009     79.84  95.86 -16.0198
## Aug 2009     65.24  95.53 -30.2937
## Sep 2009     87.92  95.21  -7.2925
## Oct 2009     84.45  94.90 -10.4462
## Nov 2009     87.93  94.58  -6.6550
## Dec 2009    102.42  94.28   8.1413
## Jan 2010     79.16  93.98 -14.8173
## Feb 2010     78.40  93.68 -15.2807
## Mar 2010     94.32  93.39   0.9311
## Apr 2010     84.45  93.10  -8.6514
## May 2010     84.92  92.82  -7.8982
## Jun 2010    103.18  92.54  10.6412
## Jul 2010     89.42  92.26  -2.8429
## Aug 2010     77.66  91.99 -14.3301
## Sep 2010     95.68  91.72   3.9598
## Oct 2010     94.03  91.45   2.5772
## Nov 2010    100.99  91.19   9.8027
## Dec 2010    101.26  90.92  10.3365
## Jan 2011     91.47  90.66   0.8090
## Feb 2011     87.66  90.40  -2.7396
## Mar 2011    103.33  90.14  13.1909
## Apr 2011     88.56  89.88  -1.3193
## May 2011     92.32  89.62   2.7001
## Jun 2011    102.21  89.36  12.8491
## Jul 2011     92.80  89.10   3.6979
## Aug 2011     76.44  88.84 -12.4034
## Sep 2011     94.00  88.58   5.4150
## Oct 2011     91.67  88.33   3.3434
## Nov 2011     91.98  88.07   3.9117
par(mfrow= c(2,1))
plot(elecequip, xlab = "Time", ylab = "New Orders Index")
lines(hpfilter(elecequip, type = "lambda")$trend, col = "red", lwd = 2)
legend(1996, 200, c("Original Serie", "Trend - HP Filter"), col = c("black", "red"), lwd = c(1,2), bty = "n")
plot(hpfilter(elecequip, type = "lambda")$cycle,  xlab = "Time", ylab = "New Orders Index")

data("cafe")

hpfilter(cafe, type = "lambda")
## 
## Title:
##  Hodrick-Prescott Filter 
## 
## Call:
##  hpfilter(x = cafe, type = "lambda")
## 
## Method:
##  hpfilter
## 
## Filter Type:
##  lambda
## 
## Series:
##  cafe
## 
##         cafe  Trend     Cycle
## 1982 Q2 1013  953.8   59.3606
## 1982 Q3 1012  987.7   24.1833
## 1982 Q4 1166 1021.6  144.5689
## 1983 Q1 1082 1055.6   26.8652
## 1983 Q2 1059 1089.9  -31.1704
## 1983 Q3 1118 1124.5   -6.3973
## 1983 Q4 1224 1159.7   64.0448
## 1984 Q1 1164 1195.5  -31.7802
## 1984 Q2 1179 1232.1  -53.3481
## 1984 Q3 1197 1269.8  -73.1150
## 1984 Q4 1349 1308.6   40.4965
## 1985 Q1 1234 1348.6 -115.0907
## 1985 Q2 1273 1389.9 -117.0789
## 1985 Q3 1370 1432.5  -62.7984
## 1985 Q4 1563 1476.4   86.6934
## 1986 Q1 1438 1521.5  -84.0213
## 1986 Q2 1513 1567.8  -55.0147
## 1986 Q3 1602 1615.2  -13.1065
## 1986 Q4 1797 1663.6  133.8182
## 1987 Q1 1640 1712.8  -72.5178
## 1987 Q2 1666 1762.9  -97.3750
## 1987 Q3 1775 1813.7  -38.6690
## 1987 Q4 1985 1865.1  119.9458
## 1988 Q1 1816 1916.9 -100.4610
## 1988 Q2 1878 1969.0  -91.0946
## 1988 Q3 1975 2021.3  -46.1976
## 1988 Q4 2115 2073.6   41.3445
## 1989 Q1 2107 2125.5  -18.8252
## 1989 Q2 2126 2177.0  -51.3891
## 1989 Q3 2254 2227.7   25.9821
## 1989 Q4 2544 2277.5  266.4495
## 1990 Q1 2462 2325.9  136.2583
## 1990 Q2 2412 2373.1   39.3871
## 1990 Q3 2455 2419.0   36.4293
## 1990 Q4 2630 2463.5  166.6536
## 1991 Q1 2446 2506.9  -60.7940
## 1991 Q2 2419 2549.2 -129.8715
## 1991 Q3 2565 2590.5  -25.5991
## 1991 Q4 2941 2630.9  310.0842
## 1992 Q1 2736 2670.4   65.4553
## 1992 Q2 2730 2709.3   20.5977
## 1992 Q3 2681 2747.7  -66.8466
## 1992 Q4 2913 2786.0  127.2520
## 1993 Q1 2626 2824.4 -198.7352
## 1993 Q2 2542 2863.2 -321.4167
## 1993 Q3 2654 2902.6 -248.4765
## 1993 Q4 2994 2942.5   51.2021
## 1994 Q1 2901 2982.8  -81.5088
## 1994 Q2 2815 3023.4 -208.0690
## 1994 Q3 3072 3064.0    7.5123
## 1994 Q4 3320 3104.3  215.9564
## 1995 Q1 3157 3144.1   12.6794
## 1995 Q2 3196 3183.1   12.9629
## 1995 Q3 3330 3221.2  108.9803
## 1995 Q4 3676 3258.2  417.2970
## 1996 Q1 3521 3294.0  227.1101
## 1996 Q2 3424 3328.7   95.2563
## 1996 Q3 3389 3362.8   25.9299
## 1996 Q4 3502 3396.4  105.9659
## 1997 Q1 3388 3430.1  -42.5169
## 1997 Q2 3425 3464.3  -39.1660
## 1997 Q3 3492 3499.3   -7.3023
## 1997 Q4 3695 3535.6  159.5777
## 1998 Q1 3377 3573.6 -196.6176
## 1998 Q2 3339 3613.8 -274.6801
## 1998 Q3 3456 3656.5 -199.9783
## 1998 Q4 3770 3701.9   67.6907
## 1999 Q1 3614 3750.1 -136.3451
## 1999 Q2 3715 3801.3  -85.9001
## 1999 Q3 3714 3855.4 -141.3035
## 1999 Q4 4088 3912.4  175.5694
## 2000 Q1 3829 3972.3 -143.5686
## 2000 Q2 3809 4034.9 -225.6144
## 2000 Q3 4079 4100.3  -21.1751
## 2000 Q4 4416 4168.1  247.5831
## 2001 Q1 4330 4238.2   91.8075
## 2001 Q2 4285 4310.4  -25.4097
## 2001 Q3 4419 4384.7   34.4665
## 2001 Q4 4583 4461.1  121.6871
## 2002 Q1 4291 4539.5 -248.7187
## 2002 Q2 4367 4620.0 -252.7976
## 2002 Q3 4574 4702.4 -128.4408
## 2002 Q4 4862 4786.6   75.9184
## 2003 Q1 4616 4872.1 -255.6731
## 2003 Q2 4801 4958.6 -157.9157
## 2003 Q3 5147 5045.7  100.8500
## 2003 Q4 5765 5132.9  632.1820
## 2004 Q1 5534 5219.6  314.1754
## 2004 Q2 5478 5305.8  172.6299
## 2004 Q3 5650 5391.5  258.3492
## 2004 Q4 5796 5476.9  319.4289
## 2005 Q1 5240 5562.4 -322.1968
## 2005 Q2 5367 5648.6 -281.7934
## 2005 Q3 5528 5735.8 -207.6250
## 2005 Q4 6096 5824.3  271.6204
## 2006 Q1 5648 5914.0 -266.3153
## 2006 Q2 5915 6005.3  -90.0601
## 2006 Q3 6101 6098.1    3.0244
## 2006 Q4 6520 6192.5  327.5330
## 2007 Q1 6228 6288.4  -60.4414
## 2007 Q2 6413 6386.2   27.0894
## 2007 Q3 6616 6485.9  129.8512
## 2007 Q4 7003 6587.8  415.1532
## 2008 Q1 6410 6692.2 -282.5769
## 2008 Q2 6415 6799.5 -384.6707
## 2008 Q3 6501 6910.1 -409.2831
## 2008 Q4 7025 7024.1    0.4713
## 2009 Q1 6691 7141.5 -450.4664
## 2009 Q2 6992 7262.0 -270.3553
## 2009 Q3 7292 7385.2  -93.2727
## 2009 Q4 8068 7510.5  557.4726
## 2010 Q1 7451 7637.4 -186.6696
## 2010 Q2 7608 7765.4 -157.0979
## 2010 Q3 8317 7894.2  422.6056
## 2010 Q4 8426 8023.2  403.2570
par(mfrow= c(2,1))
plot(cafe, xlab = "Time", ylab = "Expenditures Quarters")
lines(hpfilter(cafe, type = "lambda")$trend, col = "red", lwd = 2)
legend(1985, 8000, c("Original Serie", "Trend - HP Filter"), col = c("black", "red"), lwd = c(1,2), bty = "n")
plot(hpfilter(cafe, type = "lambda")$cycle,  xlab = "Time", ylab = "Cycle Component")

comments powered by Disqus