ARIMA Model

Load data in R

setwd("H:/Dropbox/Research/fish")
suppressMessages(library(vars))
suppressMessages(library(fpp))
suppressMessages(library(readxl))
suppressMessages(library(ggfortify))
mydata <- read.csv("fishData.csv", stringsAsFactors = F)
mydata$X_date_ <- as.Date(mydata$X_date_, "%Y-%m-%d")
mydata <- read.zoo(mydata, format = "%Y-%m-%d")
autoplot(scale(mydata))
## Warning: Removed 12 rows containing missing values (geom_path).

Transform for vars

fish <- ts(mydata$sales, frequency = 12, start = c(2007,4),end = c(2016,3))
str(fish)
##  Time-Series [1:108] from 2007 to 2016: 16555 21567 17864 14217 9527 ...
##  - attr(*, "index")= Date[1:108], format: "2007-04-01" "2007-05-01" ...
head(fish)
## [1] 16555 21567 17864 14217  9527  4235
autoplot(fish) + ggtitle("Fish license")

Model selection

mod <- auto.arima(fish)
summary(mod)
## Series: fish 
## ARIMA(1,1,0)(2,1,1)[12]                    
## 
## Coefficients:
## Warning in sqrt(diag(x$var.coef)): 产生了NaNs
##           ar1     sar1    sar2     sma1
##       -0.0297  -0.0703  0.0498  -0.6875
## s.e.   0.0056   0.0027     NaN   0.1308
## 
## sigma^2 estimated as 6.01e+08:  log likelihood=-1097.1
## AIC=2204.19   AICc=2204.87   BIC=2216.96
## 
## Training set error measures:
##                     ME     RMSE      MAE       MPE    MAPE      MASE
## Training set -4177.506 22504.01 13407.13 -18.34982 27.6396 0.6298291
##                    ACF1
## Training set -0.0126558

EViews code

sales.arimasel
equation eqR01.ls d(d(sales), 0,12)  c sma(12)

Compare to EViews’ best model

#library(fpp)
modEviews <- arima(fish, order=c(1,0,3), seasonal = list(order=c(1,1,1), periods=12))
summary(modEviews)
## 
## Call:
## arima(x = fish, order = c(1, 0, 3), seasonal = list(order = c(1, 1, 1), periods = 12))
## 
## Coefficients:
##          ar1      ma1     ma2      ma3     sar1     sma1
##       0.9763  -0.0159  0.0966  -0.0194  -0.1346  -0.6258
## s.e.  0.0401   0.1132  0.1055   0.1229   0.2188   0.2007
## 
## sigma^2 estimated as 568578767:  log likelihood = -1108.76,  aic = 2231.52
## 
## Training set error measures:
##                    ME     RMSE     MAE     MPE     MAPE     MASE
## Training set 55.90747 22481.18 13840.6 12.7412 35.28086 0.288061
##                    ACF1
## Training set 0.03631357

EViews code

sales.arimasel
equation eqEViews01.ls sales  c  ar(1) ma(3) sar(12) sma(12)

Forecast for next year/12 months for model 1

fcstR <- forecast(mod, h=12)
autoplot(fcstR)
## Warning: `rbind_list()` is deprecated. Please use `bind_rows()` instead.

Forecast for next year/12 months for model 1

summary(fcstR)
## 
## Forecast method: ARIMA(1,1,0)(2,1,1)[12]
## 
## Model Information:
## Series: fish 
## ARIMA(1,1,0)(2,1,1)[12]                    
## 
## Coefficients:
## Warning in sqrt(diag(x$var.coef)): 产生了NaNs
##           ar1     sar1    sar2     sma1
##       -0.0297  -0.0703  0.0498  -0.6875
## s.e.   0.0056   0.0027     NaN   0.1308
## 
## sigma^2 estimated as 6.01e+08:  log likelihood=-1097.1
## AIC=2204.19   AICc=2204.87   BIC=2216.96
## 
## Error measures:
##                     ME     RMSE      MAE       MPE    MAPE      MASE
## Training set -4177.506 22504.01 13407.13 -18.34982 27.6396 0.6298291
##                    ACF1
## Training set -0.0126558
## 
## Forecasts:
##          Point Forecast     Lo 80    Hi 80      Lo 95    Hi 95
## Apr 2016      292655.54 261217.44 324093.6  244575.11 340736.0
## May 2016      338606.10 294805.88 382406.3  271619.44 405592.8
## Jun 2016      268469.57 215082.93 321856.2  186821.75 350117.4
## Jul 2016      230190.10 168694.05 291686.1  136140.01 324240.2
## Aug 2016      178715.69 110061.51 247369.9   73718.19 283713.2
## Sep 2016       88448.57  13315.17 163582.0  -26458.05 203355.2
## Oct 2016       53237.71 -27858.90 134334.3  -70788.86 177264.3
## Nov 2016       31158.23 -55492.17 117808.6 -101362.12 163678.6
## Dec 2016       31750.13 -60118.93 123619.2 -108751.47 172251.7
## Jan 2017       30438.00 -66368.80 127244.8 -117615.22 178491.2
## Feb 2017       26558.25 -74946.36 128062.9 -128679.66 181796.2
## Mar 2017       71404.65 -34589.80 177399.1  -90699.87 233509.2

EViews code


freeze(rFcst)  eqR01.forecast(e, g) salesfr01

Forecast for next year/12 months for model 2

fcstEViews <- forecast(modEviews, h=12)
autoplot(fcstEViews)
## Warning: `rbind_list()` is deprecated. Please use `bind_rows()` instead.

Forecast for next year/12 months for model 2

summary(fcstEViews)
## 
## Forecast method: ARIMA(1,0,3)(1,1,1)[12]
## 
## Model Information:
## 
## Call:
## arima(x = fish, order = c(1, 0, 3), seasonal = list(order = c(1, 1, 1), periods = 12))
## 
## Coefficients:
##          ar1      ma1     ma2      ma3     sar1     sma1
##       0.9763  -0.0159  0.0966  -0.0194  -0.1346  -0.6258
## s.e.  0.0401   0.1132  0.1055   0.1229   0.2188   0.2007
## 
## sigma^2 estimated as 568578767:  log likelihood = -1108.76,  aic = 2231.52
## 
## Error measures:
##                    ME     RMSE     MAE     MPE     MAPE      MASE
## Training set 55.90747 22481.18 13840.6 12.7412 35.28086 0.6501927
##                    ACF1
## Training set 0.03631357
## 
## Forecasts:
##          Point Forecast     Lo 80    Hi 80      Lo 95    Hi 95
## Apr 2016      291298.49 260734.23 321862.8  244554.49 338042.5
## May 2016      339578.85 297203.77 381953.9  274771.75 404386.0
## Jun 2016      267706.28 214842.59 320570.0  186858.25 348554.3
## Jul 2016      227771.93 166858.94 288684.9  134613.55 320930.3
## Aug 2016      175861.03 108160.88 243561.2   72322.59 279399.5
## Sep 2016       83891.90  10302.97 157480.8  -28652.65 196436.4
## Oct 2016       47954.89 -30838.29 126748.1  -72548.88 168458.7
## Nov 2016       24971.92 -58480.11 108423.9 -102656.95 152600.8
## Dec 2016       24930.83 -62731.57 112593.2 -109137.24 158998.9
## Jan 2017       22970.83 -68524.45 114466.1 -116959.13 162900.8
## Feb 2017       18437.18 -76567.53 113441.9 -126859.98 163734.3
## Mar 2017       62491.59 -35741.37 160724.6  -87742.76 212725.9

EViews code


freeze(eviewsFcst)  eqEViews01.forecast(e, g) salesfeviews01

VAR advantage and shortcoming

Vector autoregressions[https://www.otexts.org/fpp/9/2]

VARs are useful in several contexts:

http://www.eviews.com/help/helpintro.html#page/content/VAR-Vector_Error_Correction_(VEC)_Models.html

Model selection

library(vars)
mydata <- ts(mydata, frequency = 12, start = c(2007,4),end = c(2016,3))
VARselect(mydata, lag.max=18, type="const")$selection
## Warning in log(sigma.det): 产生了NaNs

## Warning in log(sigma.det): 产生了NaNs

## Warning in log(sigma.det): 产生了NaNs
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##     18     18     18     17

Model selection in EViews

smpl 2007m04 2015m03 
var   fishVARs.ls 1 12 gas_reg gdp income sales unempl


'test how many lag included 
fishvars.laglen(12)


'Test cointegration/ Error correction
'http://www.eviews.com/help/helpintro.html#page/content/VAR-Vector_Error_Correction_(VEC)_Models.html
'test cointegration
fishvars.coint(c)
'change sample for esimation
smpl 2007m04 2015m03
fishvars.ec(c,4) 1 12  gas_reg gdp income sales unempl 
'test lag numbers
fishvars.testlags

' Forecast
smpl 2015m04 2016m03
freeze(mode=overwrite, fcstVARs) fishvars.forecast(g, e) f

smpl 2014m04 2016m03
group gr02 sales salesfeviews01 salesfr01 sales_f
freeze(mode=overwrite, fcstCom) gr02.line

''model (1,0,3)(12,0, 12)12 is the best.

VECM Model

#install.packages("tsDyn")
library(tsDyn)

#Fit a VECM with Engle-Granger 2OLS estimator:
vecm.eg<-VECM(mydata, lag=12)
summary(vecm.eg) 
## #############
## ###Model VECM 
## #############
## Full sample size: 108    End sample size: 95
## Number of variables: 5   Number of estimated slope parameters 310
## AIC 4564.038     BIC 5365.956    SSR 41155676324
## Cointegrating vector (estimated by 2OLS):
##    gas_reg           gdp     income         sales    unempl
## r1       1 -3.580473e-05 0.02553383 -5.645018e-05 0.5368104
## 
## 
##                  ECT                    Intercept                
## Equation gas_reg -0.1951(0.1538)        -2.5898(1.8156)          
## Equation gdp     534.9695(746.1698)     1316.7612(8806.7975)     
## Equation income  0.1601(0.6841)         17.8943(8.0741)*         
## Equation sales   281.0379(813.0350)     10713.8131(9595.9847)    
## Equation unempl  0.0032(0.0080)         0.3133(0.0939)**         
##                  gas_reg -1              gdp -1               
## Equation gas_reg 0.3637(0.1928).         -1.7e-05(3.7e-05)    
## Equation gdp     2395.2687(935.1757)*    -0.0599(0.1791)      
## Equation income  -1.1685(0.8574)         0.0003(0.0002).      
## Equation sales   255.7983(1018.9778)     -0.2432(0.1951)      
## Equation unempl  0.0009(0.0100)          -1.3e-06(1.9e-06)    
##                  income -1               sales -1             
## Equation gas_reg -0.0154(0.0306)          3.5e-05(2.8e-05)    
## Equation gdp     -162.1497(148.2421)     -0.1817(0.1369)      
## Equation income  -0.0493(0.1359)          9.5e-05(0.0001)     
## Equation sales   -438.7106(161.5263)*    -0.3191(0.1491)*     
## Equation unempl  0.0018(0.0016)          -1.1e-06(1.5e-06)    
##                  unempl -1                   gas_reg -2              
## Equation gas_reg -2.3434(2.5314)             -0.1867(0.2213)         
## Equation gdp     -11421.5309(12278.9850)     -305.1803(1073.3290)    
## Equation income  1.1695(11.2574)             -1.9122(0.9840).        
## Equation sales   -6379.9815(13379.3189)      1074.0722(1169.5112)    
## Equation unempl  -0.0885(0.1309)             0.0028(0.0114)          
##                  gdp -2                income -2              
## Equation gas_reg  2.4e-05(3.5e-05)     0.0719(0.0345)*        
## Equation gdp     -0.3168(0.1691).      4.0585(167.1518)       
## Equation income  -0.0002(0.0002)       0.1707(0.1532)         
## Equation sales   0.2707(0.1842)        -301.4060(182.1304)    
## Equation unempl   9.9e-07(1.8e-06)     -0.0018(0.0018)        
##                  sales -2              unempl -2                  
## Equation gas_reg  7.7e-05(3.1e-05)*    0.1341(2.4448)             
## Equation gdp     0.0351(0.1493)        -15341.0419(11858.8221)    
## Equation income   1.7e-05(0.0001)      -12.9654(10.8722)          
## Equation sales   -0.3170(0.1626).      14856.2702(12921.5047)     
## Equation unempl  -1.4e-06(1.6e-06)     -0.0104(0.1264)            
##                  gas_reg -3               gdp -3               
## Equation gas_reg 0.0598(0.2105)           -2.1e-05(3.4e-05)    
## Equation gdp     2414.2917(1020.8216)*    0.1159(0.1660)       
## Equation income  1.2256(0.9359)            7.2e-05(0.0002)     
## Equation sales   -2525.5176(1112.2986)*   -0.0130(0.1809)      
## Equation unempl  -0.0107(0.0109)          -3.6e-06(1.8e-06).   
##                  income -3               sales -3             
## Equation gas_reg -0.0066(0.0354)          1.1e-05(3.3e-05)    
## Equation gdp     -105.7886(171.6227)     -0.1589(0.1584)      
## Equation income  0.0275(0.1573)          -9.3e-05(0.0001)     
## Equation sales   38.7596(187.0020)       -0.2586(0.1726)      
## Equation unempl  -0.0003(0.0018)         -1.2e-06(1.7e-06)    
##                  unempl -3                   gas_reg -4               
## Equation gas_reg 1.0650(2.4732)              0.0656(0.2181)           
## Equation gdp     -2918.0809(11996.6764)      -1430.6607(1057.8428)    
## Equation income  -0.9641(10.9986)            0.5912(0.9698)           
## Equation sales   -11182.3554(13071.7123)     390.2864(1152.6373)      
## Equation unempl  -0.5095(0.1279)***          -0.0023(0.0113)          
##                  gdp -4                income -4            
## Equation gas_reg  2.2e-05(3.5e-05)     0.0191(0.0347)       
## Equation gdp     0.1420(0.1721)        86.0010(168.2666)    
## Equation income  -0.0003(0.0002).      -0.2223(0.1543)      
## Equation sales   0.0960(0.1875)        16.4749(183.3452)    
## Equation unempl   2.1e-06(1.8e-06)     0.0002(0.0018)       
##                  sales -4              unempl -4                  
## Equation gas_reg  1.3e-05(3.3e-05)     -1.8883(2.6358)            
## Equation gdp     -0.0812(0.1600)       -4498.0246(12785.1078)     
## Equation income  -0.0002(0.0001)       16.1799(11.7215)           
## Equation sales   -0.3404(0.1743).      -17323.8614(13930.7959)    
## Equation unempl  -3.0e-06(1.7e-06).    -0.0991(0.1363)            
##                  gas_reg -5                gdp -5               
## Equation gas_reg 0.0485(0.2157)             2.6e-05(3.2e-05)    
## Equation gdp     1666.7760(1046.1195)      -0.1546(0.1538)      
## Equation income  -0.4410(0.9591)           -1.8e-05(0.0001)     
## Equation sales   -1293.7078(1139.8635)     0.1013(0.1676)       
## Equation unempl  0.0213(0.0112).           -4.8e-06(1.6e-06)**  
##                  income -5              sales -5             
## Equation gas_reg -0.0326(0.0334)         2.7e-05(3.4e-05)    
## Equation gdp     -289.9709(162.0881).   -0.3138(0.1644).     
## Equation income  -0.2646(0.1486).       -0.0003(0.0002).     
## Equation sales   75.9873(176.6130)      -0.2494(0.1791)      
## Equation unempl  -0.0028(0.0017)        -2.8e-06(1.8e-06)    
##                  unempl -5                  gas_reg -6               
## Equation gas_reg 0.7906(2.6825)             -0.1943(0.2218)          
## Equation gdp     14102.0058(13011.8589)     -1459.3551(1075.9152)    
## Equation income  -7.8154(11.9294)           -1.4136(0.9864)          
## Equation sales   9512.6963(14177.8664)      -70.6408(1172.3292)      
## Equation unempl  -0.1325(0.1387)            -0.0019(0.0115)          
##                  gdp -6                income -6             
## Equation gas_reg  3.7e-05(3.1e-05)     0.0452(0.0306)        
## Equation gdp     0.3316(0.1517)*       78.4726(148.2657)     
## Equation income  0.0002(0.0001)        -0.0340(0.1359)       
## Equation sales   0.0067(0.1653)        -60.7512(161.5520)    
## Equation unempl  -6.5e-07(1.6e-06)     -0.0032(0.0016)*      
##                  sales -6              unempl -6                 
## Equation gas_reg  4.7e-05(3.5e-05)     -3.3694(2.7043)           
## Equation gdp     -0.0346(0.1678)       11550.7965(13117.3623)    
## Equation income   3.9e-05(0.0002)      -4.2471(12.0261)          
## Equation sales   -0.3482(0.1828).      20687.4666(14292.8241)    
## Equation unempl  -2.3e-06(1.8e-06)     -0.0457(0.1399)           
##                  gas_reg -7                gdp -7               
## Equation gas_reg -0.2214(0.2132)            4.2e-07(3.3e-05)    
## Equation gdp     -1236.3713(1034.3020)     0.1296(0.1623)       
## Equation income  0.6176(0.9483)            -0.0001(0.0001)      
## Equation sales   -688.8040(1126.9870)      0.1149(0.1768)       
## Equation unempl  -0.0115(0.0110)           -3.9e-07(1.7e-06)    
##                  income -7              sales -7             
## Equation gas_reg 0.0808(0.0293)**        5.2e-05(3.3e-05)    
## Equation gdp     -18.8246(142.1652)     -0.1890(0.1585)      
## Equation income  0.0214(0.1303)         -0.0002(0.0001)      
## Equation sales   89.7915(154.9048)      -0.2326(0.1727)      
## Equation unempl  -0.0007(0.0015)        -3.5e-06(1.7e-06)*   
##                  unempl -7                  gas_reg -8             
## Equation gas_reg 1.2543(2.8529)             -0.1025(0.2018)        
## Equation gdp     32726.2672(13838.1205)*    -104.3663(978.8209)    
## Equation income  -14.3431(12.6869)          -0.7268(0.8974)        
## Equation sales   -2852.8343(15078.1702)     8.3954(1066.5341)      
## Equation unempl  -0.0950(0.1476)            0.0060(0.0104)         
##                  gdp -8                income -8              
## Equation gas_reg -9.5e-06(3.3e-05)     0.0342(0.0295)         
## Equation gdp     0.4598(0.1612)**      280.7320(143.1597).    
## Equation income  -2.1e-05(0.0001)      0.1402(0.1312)         
## Equation sales   -0.2048(0.1757)       -122.3082(155.9884)    
## Equation unempl  -2.3e-06(1.7e-06)     -0.0010(0.0015)        
##                  sales -8              unempl -8                
## Equation gas_reg  1.7e-05(3.4e-05)     0.0886(2.9098)           
## Equation gdp     0.0413(0.1641)        6806.5923(14114.4557)    
## Equation income  -4.2e-05(0.0002)      -10.7449(12.9402)        
## Equation sales   -0.4514(0.1788)*      7959.8742(15379.2681)    
## Equation unempl  -1.5e-06(1.7e-06)     -0.2741(0.1505).         
##                  gas_reg -9                gdp -9               
## Equation gas_reg 0.0208(0.1896)             3.8e-06(3.4e-05)    
## Equation gdp     -756.7692(919.7937)       0.2093(0.1652)       
## Equation income  0.0604(0.8433)            -0.0002(0.0002)      
## Equation sales   -1109.6027(1002.2175)     0.1259(0.1800)       
## Equation unempl  -0.0021(0.0098)            6.0e-07(1.8e-06)    
##                  income -9              sales -9             
## Equation gas_reg -0.0148(0.0315)         6.8e-05(3.5e-05).   
## Equation gdp     -20.3957(152.8635)     -0.0339(0.1676)      
## Equation income  -0.1674(0.1401)        0.0002(0.0002)       
## Equation sales   14.4365(166.5618)      -0.1815(0.1826)      
## Equation unempl  -0.0003(0.0016)         4.6e-07(1.8e-06)    
##                  unempl -9                   gas_reg -10            
## Equation gas_reg 2.7058(2.8117)              -0.3485(0.1741).       
## Equation gdp     21036.3629(13638.5958)      -2474.7788(844.6149)** 
## Equation income  7.6404(12.5039)             0.8794(0.7743)         
## Equation sales   -11998.7222(14860.7660)     634.0136(920.3018)     
## Equation unempl  -0.0755(0.1454)             0.0163(0.0090).        
##                  gdp -10               income -10            
## Equation gas_reg  4.2e-05(2.8e-05)     -0.0015(0.0276)       
## Equation gdp     0.2254(0.1371)        173.3305(134.0548)    
## Equation income  0.0002(0.0001)        -0.0193(0.1229)       
## Equation sales   -0.2140(0.1494)       -47.4597(146.0676)    
## Equation unempl  -3.1e-06(1.5e-06)*    -0.0003(0.0014)       
##                  sales -10             unempl -10                
## Equation gas_reg  4.8e-05(3.0e-05)     1.1114(2.8550)            
## Equation gdp     -0.0138(0.1479)       8637.2825(13848.2847)     
## Equation income  -0.0002(0.0001)       3.9099(12.6962)           
## Equation sales   -0.1215(0.1611)       -3651.0894(15089.2453)    
## Equation unempl  -4.1e-06(1.6e-06)*    0.2701(0.1477).           
##                  gas_reg -11              gdp -11              
## Equation gas_reg 0.2508(0.1933)           -3.6e-05(2.9e-05)    
## Equation gdp     326.1566(937.8008)       -0.2140(0.1387)      
## Equation income  -1.2618(0.8598)          0.0001(0.0001)       
## Equation sales   -662.5567(1021.8382)     0.1247(0.1512)       
## Equation unempl  -0.0135(0.0100)           2.4e-06(1.5e-06)    
##                  income -11             sales -11            
## Equation gas_reg 0.0025(0.0271)          4.0e-05(2.8e-05)    
## Equation gdp     -18.0584(131.4068)     -0.0379(0.1355)      
## Equation income  -0.2598(0.1205)*       -0.0001(0.0001)      
## Equation sales   150.6045(143.1824)     -0.2048(0.1477)      
## Equation unempl  -0.0021(0.0014)        -8.1e-07(1.4e-06)    
##                  unempl -11                  gas_reg -12            
## Equation gas_reg -0.1102(2.8333)             -0.2573(0.1944)        
## Equation gdp     34681.7501(13743.1325)*     -1740.8921(943.0775).  
## Equation income  -4.3690(12.5998)            -0.4689(0.8646)        
## Equation sales   -22147.1080(14974.6703)     651.4148(1027.5878)    
## Equation unempl  -0.0652(0.1465)             -0.0027(0.0101)        
##                  gdp -12               income -12            
## Equation gas_reg  1.0e-05(2.9e-05)     -0.0243(0.0259)       
## Equation gdp     0.0234(0.1400)        12.6388(125.6020)     
## Equation income   4.9e-05(0.0001)      0.2580(0.1152)*       
## Equation sales   -0.1426(0.1526)       -250.5293(136.8573).  
## Equation unempl  -1.6e-07(1.5e-06)     -0.0061(0.0013)***    
##                  sales -12            unempl -12                
## Equation gas_reg  5.5e-05(3.0e-05).   -2.2712(2.6478)           
## Equation gdp     -0.1418(0.1465)      7988.3246(12843.6004)     
## Equation income  -0.0002(0.0001)      -18.0133(11.7751)         
## Equation sales   0.5600(0.1597)**     -8513.8823(13994.5301)    
## Equation unempl  -4.5e-06(1.6e-06)**  -0.1412(0.1369)
#Fit a VECM with Johansen MLE estimator:
(vecm.jo<-VECM(mydata, lag=12, estim="ML")) 
##                            ECT     Intercept    gas_reg -1        gdp -1
## Equation gas_reg -1.269930e-02 -1.932702e+01  1.937113e-01 -2.036379e-05
## Equation gdp      2.007470e+01  2.723294e+04  2.805846e+03 -5.685487e-02
## Equation income  -1.646839e-02 -4.797690e+00 -1.130344e+00  3.023824e-04
## Equation sales   -1.040000e+02 -1.308441e+05  3.991822e+01 -2.890912e-01
## Equation unempl   2.184861e-04  6.015808e-01  3.718874e-03 -1.246597e-06
##                      income -1      sales -1     unempl -1    gas_reg -2
## Equation gas_reg  7.074944e-03  1.968382e-04 -2.022548e+00 -3.316674e-01
## Equation gdp     -1.840421e+02 -4.382655e-01 -1.257976e+04  8.418057e+01
## Equation income   4.866082e-03  3.046970e-04  3.987317e-01 -1.808003e+00
## Equation sales   -1.407506e+02  1.008442e+00 -9.149967e+03  1.215855e+03
## Equation unempl   1.408104e-03 -3.907505e-06 -9.362102e-02  5.209538e-03
##                         gdp -2     income -2      sales -2     unempl -2
## Equation gas_reg  8.695587e-06  6.847954e-02  2.144087e-04  2.570963e-01
## Equation gdp     -3.018542e-01  2.615415e+01 -1.800101e-01 -1.641171e+04
## Equation income  -1.975682e-04  1.966752e-01  2.001234e-04 -1.440312e+01
## Equation sales    6.955750e-02 -1.913584e+02  8.303470e-01  8.599730e+03
## Equation unempl   1.261957e-06 -1.764517e-03 -3.800788e-06 -1.194618e-02
##                     gas_reg -3        gdp -3     income -3      sales -3
## Equation gas_reg  1.968561e-03 -9.000882e-06 -3.777545e-02  1.268402e-04
## Equation gdp      2.626511e+03  9.064273e-02 -3.608569e+01 -3.344027e-01
## Equation income   1.370607e+00  7.529130e-05  2.438559e-02  7.031690e-05
## Equation sales   -1.998831e+03  2.985610e-02 -4.686892e+01  7.491686e-01
## Equation unempl  -9.825635e-03 -3.753862e-06  2.657687e-04 -3.160160e-06
##                      unempl -3    gas_reg -4        gdp -4     income -4
## Equation gas_reg     2.5366917 -1.639486e-01  3.568290e-05 -3.391418e-03
## Equation gdp     -6262.9297985 -9.382159e+02  1.063639e-01  1.400355e+02
## Equation income     -0.9117946  5.295408e-01 -3.038406e-04 -2.177131e-01
## Equation sales   -7571.3596060 -4.161958e+02  9.302676e-02 -1.418080e+01
## Equation unempl     -0.5341512  1.520471e-03  1.876351e-06  6.038132e-04
##                       sales -4     unempl -4    gas_reg -5        gdp -5
## Equation gas_reg  1.153170e-04 -7.025498e-01 -1.707959e-01  4.358271e-05
## Equation gdp     -2.354161e-01 -7.363252e+03  2.140747e+03 -1.873993e-01
## Equation income  -4.989198e-06  1.591145e+01 -4.931118e-01 -5.164171e-06
## Equation sales    5.705800e-01 -1.582710e+04 -2.033320e+03  1.970713e-01
## Equation unempl  -4.741629e-06 -1.188584e-01  2.502313e-02 -5.063117e-06
##                      income -5      sales -5     unempl -5    gas_reg -6
## Equation gas_reg -4.696301e-02  1.101267e-04     1.1236147 -5.075708e-01
## Equation gdp     -2.480845e+02 -4.350472e-01 12438.7853681 -8.179680e+02
## Equation income  -2.483334e-01 -1.327037e-04    -9.4557479 -1.553240e+00
## Equation sales    1.171026e+02  5.159638e-01  2816.2392968 -1.423608e+03
## Equation unempl  -2.608432e-03 -4.240189e-06    -0.1374674  3.375103e-03
##                         gdp -6    income -6      sales -6     unempl -6
## Equation gas_reg  6.107241e-05  0.040890792  1.168022e-04 -2.131381e+00
## Equation gdp      2.824734e-01 96.238366203 -1.353454e-01  8.378159e+03
## Equation income   1.888533e-04 -0.019710564  1.469813e-04 -4.857215e+00
## Equation sales    1.119235e-01 -5.749282105  3.041298e-01  2.075067e+04
## Equation unempl  -1.060456e-06 -0.003164324 -3.506677e-06 -6.619022e-02
##                     gas_reg -7        gdp -7     income -7      sales -7
## Equation gas_reg -4.493796e-01  1.773771e-05  0.0705944115  9.821960e-05
## Equation gdp     -7.326068e+02  8.911339e-02  5.1717488924 -2.548808e-01
## Equation income   5.831627e-01 -1.206614e-04  0.0226602585 -1.493567e-04
## Equation sales   -1.368222e+03  1.481432e-01 72.1594315981  1.996184e-01
## Equation unempl  -7.663978e-03 -6.817731e-07 -0.0005322688 -4.311628e-06
##                      unempl -7    gas_reg -8        gdp -8     income -8
## Equation gas_reg     4.1215833 -3.619582e-01  2.000962e-05  3.222804e-02
## Equation gdp     26610.8716913  4.105157e+02  3.995971e-01  2.907285e+02
## Equation income    -13.5099861 -8.722909e-01 -7.584500e-06  1.503083e-01
## Equation sales    7507.4810520 -1.247897e+03 -7.526673e-02 -8.082623e+01
## Equation unempl     -0.1433432  1.042391e-02 -2.793411e-06 -9.990981e-04
##                       sales -8     unempl -8    gas_reg -9        gdp -9
## Equation gas_reg  5.199872e-05     2.6227405 -1.633424e-01  1.114185e-05
## Equation gdp     -5.969816e-03  1408.4634056 -3.635833e+02  1.865488e-01
## Equation income   1.853822e-05    -9.9963974  7.863344e-03 -2.003253e-04
## Equation sales   -9.317437e-02 17171.7595100 -1.770734e+03  9.326230e-02
## Equation unempl  -2.075737e-06    -0.3167701  1.047068e-03  4.785957e-07
##                      income -9      sales -9     unempl -9   gas_reg -10
## Equation gas_reg -2.562016e-02  7.293961e-05     5.8073789 -5.528707e-01
## Equation gdp      4.098661e+00 -3.456524e-02 14617.5319657 -2.060023e+03
## Equation income  -1.679316e-01  2.665432e-04     8.8992490  7.813552e-01
## Equation sales   -1.258027e+01 -7.395514e-02   834.7093221 -2.802384e+02
## Equation unempl  -1.625288e-04  3.638696e-07    -0.1278899  1.977733e-02
##                        gdp -10    income -10     sales -10   unempl -10
## Equation gas_reg  5.011097e-05 -7.916881e-03  2.829546e-05    3.4660691
## Equation gdp      2.065268e-01  1.952545e+02  2.848054e-02 3562.9183304
## Equation income   1.888199e-04 -6.378558e-03 -1.857010e-04    4.4986807
## Equation sales   -1.875434e-01 -3.311188e+00 -2.007732e-01 4423.3243895
## Equation unempl  -3.225174e-06 -2.212723e-04 -3.795343e-06    0.2304621
##                    gas_reg -11       gdp -11    income -11     sales -11
## Equation gas_reg  1.091411e-01 -4.639625e-05  -0.009223215  1.111145e-05
## Equation gdp      6.181629e+02 -2.016257e-01   9.884889949  1.567728e-02
## Equation income  -1.321645e+00  7.901387e-05  -0.257898513 -1.508947e-04
## Equation sales   -1.259392e+03  2.258552e-03 132.375021123 -3.648202e-01
## Equation unempl  -1.107621e-02  2.545291e-06  -0.001892159 -3.241044e-07
##                     unempl -11   gas_reg -12       gdp -12    income -12
## Equation gas_reg  1.687013e+00 -4.069161e-01  6.368645e-07 -1.838793e-02
## Equation gdp      3.099925e+04 -1.421572e+03  3.683548e-02  1.114381e+01
## Equation income  -3.572156e+00 -5.119165e-01  3.263149e-05  2.798570e-01
## Equation sales   -1.440384e+04  1.130215e+02 -2.379695e-01 -1.378033e+02
## Equation unempl  -9.561553e-02 -1.489632e-04  3.846647e-09 -6.188414e-03
##                      sales -12    unempl -12
## Equation gas_reg  1.600102e-05    -2.1055792
## Equation gdp     -6.774621e-02  7463.1849757
## Equation income  -2.017844e-04   -18.2786463
## Equation sales    3.448866e-01 -9341.3191231
## Equation unempl  -3.791420e-06    -0.1438778
fcstVEC <- predict(vecm.eg, n.ahead = 12)

Forecast/predict of VECM

fcstVEC <- ts(fcstVEC, frequency = 12, start = c(2016,4),end = c(2017,3))

autoplot(fcstVEC[,'sales'])

ADL/ autoregression distribution lag model

Estimate in EViews tutorial

Selected Model: ARDL(12, 5, 2, 3, 7)

'ADL autoregression distribution model
'http://www.eviews.com/help/helpintro.html#page/content%2Fardl-Estimating_ARDL_Models_in_EViews.html%23

'Selected Model: ARDL(12, 5, 2, 3, 7)       
smpl 2007m04 2015m03
equation eqardl.ardl(deplags=12, reglags=12, trend=linear) sales gas_reg gdp income  unempl    @

smpl 2015m04 2016m03
eqardl.forecast(e,g) salesfardl
freeze(mode=overwrite,fcstARDL) eqardl.forecast(e,g) salesfardl

smpl 2014m04 2016m03
group gr03 sales salesfeviews01 salesfr01 sales_f salesfardl
freeze(mode=overwrite, fcstCom) gr03.line


'''''''''''''''''''''''

'''conclusion
'arma model (1,0,3)(12,0, 12)12 is the best.
' ARDL(12, 5, 2, 3, 7) autoregression distribution model is the second.
'arima model (0,1,0)(0,1, 1)12 is the third.
'vecm model is the fourth, and it may need more tuning.

Estimate ARDL in R tutorial

https://github.com/fcbarbi/ardl/blob/master/vignettes/ardl-vignette.Rmd

#install.packages("devtools")
#devtools::install_github("fcbarbi/ardl")
require(ardl)
## Loading required package: ardl
mydataZOO <- read.csv("fishData.csv", stringsAsFactors = F)
mydataZOO$X_date_ <- as.Date(mydataZOO$X_date_, "%Y-%m-%d")
mydataZOO <- head(mydataZOO, length(mydataZOO)-18)
mydataZOO <- read.zoo(mydataZOO, format = "%Y-%m-%d")
is.na(mydataZOO)
##     gas_reg   gdp income sales unempl
## 1     FALSE FALSE  FALSE FALSE  FALSE
## 2     FALSE FALSE  FALSE FALSE  FALSE
## 3     FALSE FALSE  FALSE FALSE  FALSE
## 4     FALSE FALSE  FALSE FALSE  FALSE
## 5     FALSE FALSE  FALSE FALSE  FALSE
## 6     FALSE FALSE  FALSE FALSE  FALSE
## 7     FALSE FALSE  FALSE FALSE  FALSE
## 8     FALSE FALSE  FALSE FALSE  FALSE
## 9     FALSE FALSE  FALSE FALSE  FALSE
## 10    FALSE FALSE  FALSE FALSE  FALSE
## 11    FALSE FALSE  FALSE FALSE  FALSE
## 12    FALSE FALSE  FALSE FALSE  FALSE
## 13    FALSE FALSE  FALSE FALSE  FALSE
## 14    FALSE FALSE  FALSE FALSE  FALSE
## 15    FALSE FALSE  FALSE FALSE  FALSE
## 16    FALSE FALSE  FALSE FALSE  FALSE
## 17    FALSE FALSE  FALSE FALSE  FALSE
## 18    FALSE FALSE  FALSE FALSE  FALSE
## 19    FALSE FALSE  FALSE FALSE  FALSE
## 20    FALSE FALSE  FALSE FALSE  FALSE
## 21    FALSE FALSE  FALSE FALSE  FALSE
## 22    FALSE FALSE  FALSE FALSE  FALSE
## 23    FALSE FALSE  FALSE FALSE  FALSE
## 24    FALSE FALSE  FALSE FALSE  FALSE
## 25    FALSE FALSE  FALSE FALSE  FALSE
## 26    FALSE FALSE  FALSE FALSE  FALSE
## 27    FALSE FALSE  FALSE FALSE  FALSE
## 28    FALSE FALSE  FALSE FALSE  FALSE
## 29    FALSE FALSE  FALSE FALSE  FALSE
## 30    FALSE FALSE  FALSE FALSE  FALSE
## 31    FALSE FALSE  FALSE FALSE  FALSE
## 32    FALSE FALSE  FALSE FALSE  FALSE
## 33    FALSE FALSE  FALSE FALSE  FALSE
## 34    FALSE FALSE  FALSE FALSE  FALSE
## 35    FALSE FALSE  FALSE FALSE  FALSE
## 36    FALSE FALSE  FALSE FALSE  FALSE
## 37    FALSE FALSE  FALSE FALSE  FALSE
## 38    FALSE FALSE  FALSE FALSE  FALSE
## 39    FALSE FALSE  FALSE FALSE  FALSE
## 40    FALSE FALSE  FALSE FALSE  FALSE
## 41    FALSE FALSE  FALSE FALSE  FALSE
## 42    FALSE FALSE  FALSE FALSE  FALSE
## 43    FALSE FALSE  FALSE FALSE  FALSE
## 44    FALSE FALSE  FALSE FALSE  FALSE
## 45    FALSE FALSE  FALSE FALSE  FALSE
## 46    FALSE FALSE  FALSE FALSE  FALSE
## 47    FALSE FALSE  FALSE FALSE  FALSE
## 48    FALSE FALSE  FALSE FALSE  FALSE
## 49    FALSE FALSE  FALSE FALSE  FALSE
## 50    FALSE FALSE  FALSE FALSE  FALSE
## 51    FALSE FALSE  FALSE FALSE  FALSE
## 52    FALSE FALSE  FALSE FALSE  FALSE
## 53    FALSE FALSE  FALSE FALSE  FALSE
## 54    FALSE FALSE  FALSE FALSE  FALSE
## 55    FALSE FALSE  FALSE FALSE  FALSE
## 56    FALSE FALSE  FALSE FALSE  FALSE
## 57    FALSE FALSE  FALSE FALSE  FALSE
## 58    FALSE FALSE  FALSE FALSE  FALSE
## 59    FALSE FALSE  FALSE FALSE  FALSE
## 60    FALSE FALSE  FALSE FALSE  FALSE
## 61    FALSE FALSE  FALSE FALSE  FALSE
## 62    FALSE FALSE  FALSE FALSE  FALSE
## 63    FALSE FALSE  FALSE FALSE  FALSE
## 64    FALSE FALSE  FALSE FALSE  FALSE
## 65    FALSE FALSE  FALSE FALSE  FALSE
## 66    FALSE FALSE  FALSE FALSE  FALSE
## 67    FALSE FALSE  FALSE FALSE  FALSE
## 68    FALSE FALSE  FALSE FALSE  FALSE
## 69    FALSE FALSE  FALSE FALSE  FALSE
## 70    FALSE FALSE  FALSE FALSE  FALSE
## 71    FALSE FALSE  FALSE FALSE  FALSE
## 72    FALSE FALSE  FALSE FALSE  FALSE
## 73    FALSE FALSE  FALSE FALSE  FALSE
## 74    FALSE FALSE  FALSE FALSE  FALSE
## 75    FALSE FALSE  FALSE FALSE  FALSE
## 76    FALSE FALSE  FALSE FALSE  FALSE
## 77    FALSE FALSE  FALSE FALSE  FALSE
## 78    FALSE FALSE  FALSE FALSE  FALSE
## 79    FALSE FALSE  FALSE FALSE  FALSE
## 80    FALSE FALSE  FALSE FALSE  FALSE
## 81    FALSE FALSE  FALSE FALSE  FALSE
## 82    FALSE FALSE  FALSE FALSE  FALSE
## 83    FALSE FALSE  FALSE FALSE  FALSE
## 84    FALSE FALSE  FALSE FALSE  FALSE
## 85    FALSE FALSE  FALSE FALSE  FALSE
## 86    FALSE FALSE  FALSE FALSE  FALSE
## 87    FALSE FALSE  FALSE FALSE  FALSE
## 88    FALSE FALSE  FALSE FALSE  FALSE
## 89    FALSE FALSE  FALSE FALSE  FALSE
## 90    FALSE FALSE  FALSE FALSE  FALSE
## 91    FALSE FALSE  FALSE FALSE  FALSE
## 92    FALSE FALSE  FALSE FALSE  FALSE
## 93    FALSE FALSE  FALSE FALSE  FALSE
## 94    FALSE FALSE  FALSE FALSE  FALSE
## 95    FALSE FALSE  FALSE FALSE  FALSE
## 96    FALSE FALSE  FALSE FALSE  FALSE
## 97    FALSE FALSE  FALSE FALSE  FALSE
## 98    FALSE FALSE  FALSE FALSE  FALSE
## 99    FALSE FALSE  FALSE FALSE  FALSE
## 100   FALSE FALSE  FALSE FALSE  FALSE
## 101   FALSE FALSE  FALSE FALSE  FALSE
## 102   FALSE FALSE  FALSE FALSE  FALSE
## 103   FALSE FALSE  FALSE FALSE  FALSE
## 104   FALSE FALSE  FALSE FALSE  FALSE
## 105   FALSE FALSE  FALSE FALSE  FALSE
## 106   FALSE FALSE  FALSE FALSE  FALSE
## 107   FALSE FALSE  FALSE FALSE  FALSE
## 108   FALSE FALSE  FALSE FALSE  FALSE
modARDL <- auto.ardl( sales~gas_reg+gdp+income+unempl, data=mydataZOO, 
                 ymax=12, xmax=c(12,12,12,12), ic="bic" )
summary(modARDL)
## 
## Time series regression with "zoo" data:
## Start = 2008-04-01, End = 2016-03-01
## 
## Call:
## dynlm::dynlm(formula = formula(fm), data = data, subset = subset)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -59937  -9561   -815   9209  62589 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   3.076e+05  9.726e+04   3.162  0.00226 ** 
## L(sales, 1)   6.933e-02  7.462e-02   0.929  0.35583    
## L(sales, 2)  -2.908e-01  6.989e-02  -4.161 8.35e-05 ***
## L(sales, 3)  -2.358e-02  6.948e-02  -0.339  0.73525    
## L(sales, 4)  -2.157e-01  6.566e-02  -3.286  0.00155 ** 
## L(sales, 5)  -1.703e-01  6.505e-02  -2.618  0.01070 *  
## L(sales, 6)  -1.522e-01  7.010e-02  -2.171  0.03312 *  
## L(sales, 7)  -1.806e-01  6.679e-02  -2.704  0.00847 ** 
## L(sales, 8)  -1.292e-01  6.860e-02  -1.883  0.06359 .  
## L(sales, 9)  -1.094e-01  1.011e-01  -1.082  0.28270    
## L(sales, 10) -1.021e-01  9.878e-02  -1.034  0.30446    
## L(sales, 11)  7.050e-03  9.532e-02   0.074  0.94124    
## L(sales, 12)  4.652e-01  7.476e-02   6.223 2.56e-08 ***
## gas_reg       4.015e+02  2.865e+02   1.402  0.16517    
## gdp          -3.438e-02  3.167e-02  -1.086  0.28114    
## income       -7.748e+01  9.672e+01  -0.801  0.42559    
## L(income, 1) -1.647e+02  1.078e+02  -1.528  0.13082    
## L(income, 2) -7.850e+01  1.038e+02  -0.756  0.45190    
## L(income, 3)  3.468e+02  7.821e+01   4.434 3.11e-05 ***
## unempl        1.069e+04  7.800e+03   1.370  0.17465    
## L(unempl, 1) -1.548e+04  7.091e+03  -2.183  0.03216 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21010 on 75 degrees of freedom
## Multiple R-squared:  0.9739, Adjusted R-squared:  0.967 
## F-statistic:   140 on 20 and 75 DF,  p-value: < 2.2e-16

ARDL(12, 1, 1, 3, 1)

Forecast by ARDL

In R, forecast need the new observation for other exogenous variables.

#fcstARDL <- forecast(modARDL, h=12)

Forecast ARDL with auto.arima

fit_arima_dl=auto.arima(mydata[,"sales"], xreg= scale(mydata[,c('gas_reg', 'gdp', 'income','unempl')]) )

summary(fit_arima_dl)
## Series: mydata[, "sales"] 
## ARIMA(0,0,0)(1,0,1)[12] with non-zero mean 
## 
## Coefficients:
##         sar1    sma1  intercept   gas_reg       gdp     income     unempl
##       0.8086  0.5676   86813.17  11701.60  25242.86  -40569.39  12893.785
## s.e.  0.0605  0.1982   25312.40   6156.54  15303.58   15342.38   6907.593
## 
## sigma^2 estimated as 2.087e+09:  log likelihood=-1321.65
## AIC=2659.29   AICc=2660.75   BIC=2680.75
## 
## Training set error measures:
##                    ME     RMSE      MAE       MPE     MAPE     MASE
## Training set 7373.343 44179.05 28060.08 -215.2871 283.6685 1.318184
##                   ACF1
## Training set 0.6375803

Forecast ARDL with auto.arima

#fcstAutoADL <- forecast(fit_arima_dl, h=12)