Batch 1 Anmole
ARIMA-X
[Link]
26/09/2019
data=[Link]("ARIMA-X/[Link]")# Read the file
df<-data #ts
head(df)
## Year Mth TS agri_cdt WPIT CPIAL IIP RainDev
## 1 2007 Apr 22305 1941.546 109.5 394 128.2 -7.57
## 2 2007 May 23488 1931.055 109.5 395 136.9 -16.08
## 3 2007 Jun 29631 1941.359 109.5 399 136.7 22.13
## 4 2007 Jul 20594 1926.283 109.5 404 136.6 17.33
## 5 2007 Aug 20051 1908.914 110.3 408 134.6 21.34
## 6 2007 Sep 27466 1982.069 110.5 410 134.0 45.33
names(df)
## [1] "Year" "Mth" "TS" "agri_cdt" "WPIT" "CPIAL"
## [7] "IIP" "RainDev"
Things to check
AIC
MAPE
RMSE
RMarkdown
Residual
Batch 1 Anmole
Undertanding the data
tsdisplay(df$TS, lag=50)
[Link](df$TS, alternative="stationary", k=4)
##
## Augmented Dickey-Fuller Test
##
## data: df$TS
## Dickey-Fuller = -3.9679, Lag order = 4, p-value = 0.0149
## alternative hypothesis: stationary
[Link](df$TS, alternative="stationary", k=6)
##
## Augmented Dickey-Fuller Test
##
## data: df$TS
## Dickey-Fuller = -2.6434, Lag order = 6, p-value = 0.3117
## alternative hypothesis: stationary
[Link](df$TS, alternative="stationary", k=12)
Batch 1 Anmole
##
## Augmented Dickey-Fuller Test
##
## data: df$TS
## Dickey-Fuller = -2.0832, Lag order = 12, p-value = 0.5418
## alternative hypothesis: stationary
Batch 1 Anmole
Checking for trend
tsdisplay(diff(df$TS,1),lag=50)
[Link](diff(df$TS,1), alternative="stationary", k=4)
## Warning in [Link](diff(df$TS, 1), alternative = "stationary", k = 4): p-
## value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff(df$TS, 1)
## Dickey-Fuller = -7.4469, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary
[Link](diff(df$TS,1), alternative="stationary", k=10)
## Warning in [Link](diff(df$TS, 1), alternative = "stationary", k = 10):
p-
## value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
Batch 1 Anmole
##
## data: diff(df$TS, 1)
## Dickey-Fuller = -6.9717, Lag order = 10, p-value = 0.01
## alternative hypothesis: stationary
__There is no trend as it is trend stationary
Batch 1 Anmole
Checking for seasonality
#seasonal differencing
tsdisplay(diff(df$TS,12),lag=50)
[Link](diff(df$TS,12), alternative="stationary", k=13)
##
## Augmented Dickey-Fuller Test
##
## data: diff(df$TS, 12)
## Dickey-Fuller = -3.6518, Lag order = 13, p-value = 0.03497
## alternative hypothesis: stationary
1,0,0 1,1,0 or 0,1,1 ->>> seasonality
Batch 1 Anmole
Model 1
m3 <-arima(df$TS, order=c(1,0,0), seasonal = list(order = c(1, 1, 0), period
= 12))
summary(m3)
##
## Call:
## arima(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(1, 1, 0),
period = 12))
##
## Coefficients:
## ar1 sar1
## 0.8081 -0.3335
## s.e. 0.0692 0.1207
##
## sigma^2 estimated as 20934141: log likelihood = -729.92, aic = 1465.83
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 943.6982 4244.195 2875.019 1.560307 6.915774 0.3667942
## ACF1
## Training set -0.02000167
[Link](residuals(m3), lag=10, fitdf=2, type="Ljung")
##
## Box-Ljung test
##
## data: residuals(m3)
## X-squared = 13.008, df = 8, p-value = 0.1116
m1 <-arima(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1, 1), period
= 12))
summary(m1)
##
## Call:
## arima(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 1),
period = 12))
##
## Coefficients:
## ar1 sma1
## 0.7884 -0.2125
## s.e. 0.0726 0.1024
##
## sigma^2 estimated as 21966635: log likelihood = -731.24, aic = 1468.48
##
Batch 1 Anmole
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 983.0864 4347.599 2910.808 1.68214 6.973157 0.3713601
## ACF1
## Training set -0.0445108
[Link](residuals(m1), lag=10, fitdf=2, type="Ljung")
##
## Box-Ljung test
##
## data: residuals(m1)
## X-squared = 12.619, df = 8, p-value = 0.1256
Errors are random
Batch 1 Anmole
Model 2
m2 <-arima(df$TS, order=c(1,0,0), seasonal = list(order = c(1, 1, 0), period
= 12))
summary(m2)
##
## Call:
## arima(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(1, 1, 0),
period = 12))
##
## Coefficients:
## ar1 sar1
## 0.8081 -0.3335
## s.e. 0.0692 0.1207
##
## sigma^2 estimated as 20934141: log likelihood = -729.92, aic = 1465.83
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 943.6982 4244.195 2875.019 1.560307 6.915774 0.3667942
## ACF1
## Training set -0.02000167
[Link](residuals(m2), lag=10, fitdf=2, type="Ljung")
##
## Box-Ljung test
##
## data: residuals(m2)
## X-squared = 13.008, df = 8, p-value = 0.1116
[Link](residuals(m2), lag=10, fitdf=2, type="Ljung")
##
## Box-Ljung test
##
## data: residuals(m2)
## X-squared = 13.008, df = 8, p-value = 0.1116
fcast.m1 <- forecast(m2, h=12)
fcast.m1
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 87 61966.61 56103.02 67830.20 52999.02 70934.20
## 88 43587.62 36048.89 51126.35 32058.12 55117.11
## 89 35212.02 26756.70 43667.34 22280.72 48143.32
## 90 59804.46 50800.84 68808.09 46034.61 73574.32
## 91 83255.80 73911.49 92600.11 68964.91 97546.69
## 92 52428.79 42868.57 61989.01 37807.69 67049.89
Batch 1 Anmole
## 93 38525.03 28826.41 48223.65 23692.28 53357.79
## 94 44742.57 34954.64 54530.50 29773.22 59711.92
## 95 42353.28 32507.47 52199.10 27295.41 57411.16
## 96 48108.88 38225.45 57992.31 32993.48 63224.28
## 97 51781.12 41873.20 61689.03 36628.27 66933.96
## 98 54835.64 44911.77 64759.50 39658.39 70012.88
summary(fcast.m1)
##
## Forecast method: ARIMA(1,0,0)(1,1,0)[12]
##
## Model Information:
##
## Call:
## arima(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(1, 1, 0),
period = 12))
##
## Coefficients:
## ar1 sar1
## 0.8081 -0.3335
## s.e. 0.0692 0.1207
##
## sigma^2 estimated as 20934141: log likelihood = -729.92, aic = 1465.83
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 943.6982 4244.195 2875.019 1.560307 6.915774 0.3667942
## ACF1
## Training set -0.02000167
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 87 61966.61 56103.02 67830.20 52999.02 70934.20
## 88 43587.62 36048.89 51126.35 32058.12 55117.11
## 89 35212.02 26756.70 43667.34 22280.72 48143.32
## 90 59804.46 50800.84 68808.09 46034.61 73574.32
## 91 83255.80 73911.49 92600.11 68964.91 97546.69
## 92 52428.79 42868.57 61989.01 37807.69 67049.89
## 93 38525.03 28826.41 48223.65 23692.28 53357.79
## 94 44742.57 34954.64 54530.50 29773.22 59711.92
## 95 42353.28 32507.47 52199.10 27295.41 57411.16
## 96 48108.88 38225.45 57992.31 32993.48 63224.28
## 97 51781.12 41873.20 61689.03 36628.27 66933.96
## 98 54835.64 44911.77 64759.50 39658.39 70012.88
plot(fcast.m1)
Batch 1 Anmole
Batch 1 Anmole
Final Model
m4 <-arima(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1, 2), period
= 12))
summary(m4)
##
## Call:
## arima(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12))
##
## Coefficients:
## ar1 sma1 sma2
## 0.7753 -0.2965 0.4028
## s.e. 0.0726 0.1256 0.1662
##
## sigma^2 estimated as 18719145: log likelihood = -727.4, aic = 1462.81
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 784.0267 4013.385 2774.736 1.280259 6.771766 0.3540001
## ACF1
## Training set 0.01828299
[Link](residuals(m2), lag=10, fitdf=2, type="Ljung")
##
## Box-Ljung test
##
## data: residuals(m2)
## X-squared = 13.008, df = 8, p-value = 0.1116
Batch 1 Anmole
ARIMA X
library(TSA)
## Registered S3 methods overwritten by 'TSA':
## method from
## [Link] forecast
## [Link] forecast
##
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
#covariate_x<-[Link](df$agri_cdt, df$WPIT, df$CPIAL, df$IIP, df$RainDev)
armx1<-arimax(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1,2),
period = 12),
xtransf = df$agri_cdt, xreg=df$agri_cdt,method = c("ML"))
summary(armx1)
##
## Call:
## arimax(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12),
## xreg = df$agri_cdt, method = c("ML"), xtransf = df$agri_cdt)
##
## Coefficients:
## ar1 sma1 sma2 xreg
## 0.6481 -0.3969 0.4320 15.9824
## s.e. 0.0892 0.1239 0.1768 4.0690
##
## sigma^2 estimated as 16227994: log likelihood = -722.5, aic = 1453
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 27.38449 3736.794 2677.295 -1.133999 6.703173 0.3415686
## ACF1
## Training set 0.1217091
Batch 1 Anmole
ARMAX Model2
library(TSA)
covariate_x<-[Link](df$agri_cdt, df$WPIT, df$CPIAL, df$IIP, df$RainDev)
armx2<-arimax(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1,2),
period = 12),
xtransf = df$WPIT, xreg=df$WPIT,method = c("ML"))
summary(armx2)
##
## Call:
## arimax(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12),
## xreg = df$WPIT, method = c("ML"), xtransf = df$WPIT)
##
## Coefficients:
## ar1 sma1 sma2 xreg
## 0.7126 -0.3321 0.3506 373.1313
## s.e. 0.0875 0.1238 0.1691 245.7976
##
## sigma^2 estimated as 18535767: log likelihood = -726.5, aic = 1461
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 496.1127 3993.672 2802.908 0.3296495 6.837369 0.3575943
## ACF1
## Training set 0.07525393
[Link](residuals(m4), lag=18, fitdf=3, type="Ljung")
##
## Box-Ljung test
##
## data: residuals(m4)
## X-squared = 19.191, df = 15, p-value = 0.2052
Batch 1 Anmole
ARMAX Model2 - Forward way
library(TSA)
covariate_x<-[Link](df$agri_cdt, df$WPIT)
armx3<-arimax(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1,2),
period = 12),
xtransf = covariate_x, xreg=covariate_x,method = c("ML"))
summary(armx3)
##
## Call:
## arimax(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12),
## xreg = covariate_x, method = c("ML"), xtransf = covariate_x)
##
## Coefficients:
## ar1 sma1 sma2 df.agri_cdt [Link]
## 0.6492 -0.3967 0.4367 16.7313 -48.3394
## s.e. 0.0891 0.1242 0.1778 5.4527 233.9849
##
## sigma^2 estimated as 16194130: log likelihood = -722.48, aic = 1454.95
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 58.06771 3732.893 2665.362 -1.047675 6.662 0.3400462
## ACF1
## Training set 0.1205346
Batch 1 Anmole
ARMAX Model3 - Forward way
library(TSA)
covariate_x<-[Link](df$agri_cdt, df$CPIAL)
armx4<-arimax(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1,2),
period = 12),
xtransf = covariate_x, xreg=covariate_x,method = c("ML"))
summary(armx4)
##
## Call:
## arimax(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12),
## xreg = covariate_x, method = c("ML"), xtransf = covariate_x)
##
## Coefficients:
## ar1 sma1 sma2 df.agri_cdt [Link]
## 0.6316 -0.3937 0.3980 13.0172 18.2128
## s.e. 0.0971 0.1246 0.1841 7.5953 39.2499
##
## sigma^2 estimated as 16360677: log likelihood = -722.4, aic = 1454.79
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -66.47704 3752.04 2686.913 -1.370133 6.74367 0.3427957
## ACF1
## Training set 0.1204256
Batch 1 Anmole
ARMAX Model4 - Forward way
library(TSA)
covariate_x<-[Link](df$agri_cdt, df$IIP)
armx5<-arimax(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1,2),
period = 12),
xtransf = covariate_x, xreg=covariate_x,method = c("ML"))
summary(armx5)
##
## Call:
## arimax(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12),
## xreg = covariate_x, method = c("ML"), xtransf = covariate_x)
##
## Coefficients:
## ar1 sma1 sma2 df.agri_cdt [Link]
## 0.6041 -0.4008 0.4454 14.1400 109.7743
## s.e. 0.1026 0.1242 0.1754 4.0567 101.8850
##
## sigma^2 estimated as 15927998: log likelihood = -721.93, aic = 1453.87
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 19.00905 3702.099 2654.414 -1.201959 6.642797 0.3386495
## ACF1
## Training set 0.1330893
Batch 1 Anmole
ARMAX Model5 - Forward way
library(TSA)
covariate_x<-[Link](df$agri_cdt, df$RainDev)
armx6<-arimax(df$TS, order=c(1,0,0), seasonal = list(order = c(0, 1,2),
period = 12),
xtransf = covariate_x, xreg=covariate_x,method = c("ML"))
summary(armx6)
##
## Call:
## arimax(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12),
## xreg = covariate_x, method = c("ML"), xtransf = covariate_x)
##
## Coefficients:
## ar1 sma1 sma2 df.agri_cdt [Link]
## 0.6456 -0.3984 0.4118 15.7887 5.5575
## s.e. 0.0913 0.1249 0.1743 4.0916 12.2218
##
## sigma^2 estimated as 16492586: log likelihood = -713.14, aic = 1436.28
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 37.3044 3763.539 2698.115 -1.111362 6.752929 0.3442248
## ACF1
## Training set 0.1268562
Batch 1 Anmole
ARIMA X - Final only with agricdt
library(TSA)
#covariate_x<-[Link](df$agri_cdt, df$WPIT, df$CPIAL, df$IIP, df$RainDev)
summary(armx1)
##
## Call:
## arimax(x = df$TS, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 2),
period = 12),
## xreg = df$agri_cdt, method = c("ML"), xtransf = df$agri_cdt)
##
## Coefficients:
## ar1 sma1 sma2 xreg
## 0.6481 -0.3969 0.4320 15.9824
## s.e. 0.0892 0.1239 0.1768 4.0690
##
## sigma^2 estimated as 16227994: log likelihood = -722.5, aic = 1453
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 27.38449 3736.794 2677.295 -1.133999 6.703173 0.3415686
## ACF1
## Training set 0.1217091
MAPE is less then ARIMA Final model
[Link](residuals(m4), lag=18, fitdf=3, type="Ljung")
##
## Box-Ljung test
##
## data: residuals(m4)
## X-squared = 19.191, df = 15, p-value = 0.2052
Errors are random as well