solprep <- read_csv("C:/Users/hassa/Downloads/RMIT/3rd Semester/Forecasting/Assignment 2/data1.csv")
## Parsed with column specification:
## cols(
## solar = col_double(),
## ppt = col_double()
## )
class(solprep)
## [1] "spec_tbl_df" "tbl_df" "tbl" "data.frame"
head(solprep)
## # A tibble: 6 x 2
## solar ppt
## <dbl> <dbl>
## 1 5.05 1.33
## 2 6.42 0.921
## 3 10.8 0.947
## 4 16.9 0.615
## 5 24.0 0.544
## 6 26.3 0.703
solar = ts(solprep$solar,start=c(1960,1),frequency = 12)
ppt = ts(solprep$ppt,start=c(1960,1),frequency = 12)
class(solar)
## [1] "ts"
class(ppt)
## [1] "ts"
solarppt = ts.intersect(solar , ppt)
plot(solarppt , yax.flip=T, main = "Fig 1.0")
cor(solprep)
## solar ppt
## solar 1.0000000 -0.4540277
## ppt -0.4540277 1.0000000
# Analysing solar time series:
plot(solar, main = "Time series plot for Solar radiations Fig 1.1")
points(y=solar,x=time(solar), pch=as.vector(season(solar)))
# Analysing prep time series:
plot(ppt, main = "Time series plot for precipitation Fig 1.2")
points(y=ppt,x=time(ppt), pch=as.vector(season(ppt)))
plot(solarppt, plot.type="s",col = c("blue", "red"), main = "Measurements of solar radiations and
precipitation Fig 1.3")
legend("topleft",lty=1, text.width = 1, col=c("blue","red"), c("Solar", "Precipitation"))
data.scaled = scale(solarppt)
plot(data.scaled, plot.type="s",col = c("blue", "red"), main = "Measurements of solar radiations and
precipitation Fig 1.4")
legend("topleft",lty=1, text.width = 1, col=c("blue","red"), c("Solar", "Precipitation"))
# X-12 decomposition:
fits.x12 = x12(solar)
plot(fits.x12 , sa=TRUE , trend=TRUE, main = "X12 - Solar radiations Fig 2.0")
plotSeasFac(fits.x12, main = "Seasonal Factors by period and SI Ratio Fig 2.1")
fitp.x12 = x12(ppt)
plot(fitp.x12 , sa=TRUE , trend=TRUE, main = "X12 - Precipitations Fig 2.2")
plotSeasFac(fitp.x12, main = "Seasonal Factors by period and SI Ratio Fig 2.3")
# Checking stationarity and seasonality using ACF and PACF:
par(mfrow=c(1,2))
acf(solar, main="Sample ACF for solar
radiations Fig 2.4")
pacf(solar, main="Sample PACF for solar
radiations Fig 2.5")
par(mfrow=c(1,2))
acf(ppt, main="Sample ACF for
ppt Fig 2.6")
pacf(ppt, main="Sample PACF for
ppt Fig 2.7")
adf.test(solar)
## Warning in adf.test(solar): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: solar
## Dickey-Fuller = -4.7661, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary
adf.test(ppt)
## Warning in adf.test(ppt): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: ppt
## Dickey-Fuller = -6.7438, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary
# Since seasonality has been confirmed we go ahead and use STL decomposition:
fit.solar <- stl(solar, t.window=15, s.window="periodic", robust=TRUE)
plot(fit.solar, main = "STL on Solar Series Fig 2.8")
fit.ppt <- stl(ppt, t.window=15, s.window="periodic", robust=TRUE)
plot(fit.ppt, main = "STL on Precipitation Series Fig 2.9")
par(mfrow=c(1,1))
monthplot(fit.solar,choice = "trend", main="Seasonal sub-series plot of the seasonal
component of solar series Fig 2.10", ylab="Trend")
monthplot(fit.ppt,choice = "trend", main="Seasonal sub-series plot of the seasonal
component of precipitation series Fig 2.11", ylab="Trend")
#Adjusting seasonal component:
# Solar:
par(mfrow=c(1,1))
fit.solar.seasonal = fit.solar$time.series[,"seasonal"]
solar.seasonally.adjusted = solar - fit.solar.seasonal
plot(solar.seasonally.adjusted, ylab='Solar radiations ',xlab='Time',type='o', main = "Seasonally adjusted solar radiations series
Fig 2.12")
# Precipitation:
fit.ppt.seasonal = fit.ppt$time.series[,"seasonal"]
ppt.seasonally.adjusted = solar - fit.ppt.seasonal
plot(ppt.seasonally.adjusted, ylab='Precipitation',xlab='Time',type='o', main = "Seasonally adjusted precipitation series
Fig 2.13")
Then I tried to fit the polynomial DLM of order 10 and checks its summary the values were insignificant; value of adjusted R-square is also very low but the p-value is good.
Then checked the residuals (Fig 3.1) were not random, correlation is prominent, pattern in histogram was also almost normalized. According to the ACF and BG test result we can conclude that the serial correlation left in residuals is highly significant.
Was not able to do the VIF test because of the aliased coefficients in the model.
Finally, the MASE value of 1.580235 was observed which is not good.
Then I tried to fit the polynomial DLM of order 1 and checks its summary the values were significant; value of adjusted R-square is also very low but the p-value is good.
Then checked the residuals (Fig 3.2) were not random, correlation is prominent, pattern in histogram is almost normalized. According to the ACF and BG test result we can conclude that the serial correlation left in residuals is highly significant.
Then checked the multicollinearity and all were FALSE which means that there is no multicollinearity between these two variables.
Finally, the MASE value of 1.688457 was observed which is not good.
# dlm:
for ( i in 1:10){
modelca1 = dlm( x =as.vector(ppt) , y = as.vector(solar), q = i )
cat("q = ", i, "AIC = ", AIC(modelca1$model), "BIC = ", BIC(modelca1$model),"\n")
}
## q = 1 AIC = 4728.713 BIC = 4746.676
## q = 2 AIC = 4712.649 BIC = 4735.095
## q = 3 AIC = 4688.551 BIC = 4715.478
## q = 4 AIC = 4663.6 BIC = 4695.003
## q = 5 AIC = 4644.622 BIC = 4680.499
## q = 6 AIC = 4637.489 BIC = 4677.837
## q = 7 AIC = 4632.716 BIC = 4677.532
## q = 8 AIC = 4625.986 BIC = 4675.267
## q = 9 AIC = 4615.084 BIC = 4668.827
## q = 10 AIC = 4602.658 BIC = 4660.858
modelca2 = dlm( x = as.vector(ppt) ,
y = as.vector(solar), q = 10 )
summary(modelca2)
##
## Call:
## lm(formula = model.formula, data = design)
##
## Residuals:
## Min 1Q Median 3Q Max
## -18.9353 -5.4124 -0.7911 4.0184 30.8900
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 19.0105 1.0942 17.374 < 2e-16 ***
## x.t -7.3843 1.8995 -3.887 0.000112 ***
## x.1 -0.4763 2.5395 -0.188 0.851288
## x.2 -0.1324 2.5734 -0.051 0.958980
## x.3 1.7902 2.5781 0.694 0.487691
## x.4 1.9686 2.5808 0.763 0.445877
## x.5 3.4928 2.5807 1.353 0.176402
## x.6 0.5243 2.5787 0.203 0.838943
## x.7 1.6762 2.5797 0.650 0.516088
## x.8 0.9282 2.5673 0.362 0.717817
## x.9 0.3754 2.5338 0.148 0.882272
## x.10 -5.3798 1.8760 -2.868 0.004272 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.256 on 638 degrees of freedom
## Multiple R-squared: 0.3081, Adjusted R-squared: 0.2962
## F-statistic: 25.82 on 11 and 638 DF, p-value: < 2.2e-16
##
## AIC and BIC values for the model:
## AIC BIC
## 1 4602.658 4660.858
checkresiduals(modelca2$model)
##
## Breusch-Godfrey test for serial correlation of order up to 15
##
## data: Residuals
## LM test = 588.43, df = 15, p-value < 2.2e-16
VIF.modelca2 = vif(modelca2$model)
VIF.modelca2 > 10
## x.t x.1 x.2 x.3 x.4 x.5 x.6 x.7 x.8 x.9 x.10
## FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
MASE(modelca2)
## MASE
## modelca2 1.577996
# finiteDLMauto:
finiteDLMauto( x = as.vector(ppt) , y = as.vector(solar), q.min = 1, q.max = 10,
model.type = "dlm", error.type ="AIC", trace = TRUE)
## q - k MASE AIC BIC R.Adj.Sq Ljung-Box
## 10 10 1.57800 4602.658 4660.858 0.29615 0
## 9 9 1.59312 4615.084 4668.827 0.28882 0
## 8 8 1.60481 4625.986 4675.267 0.28251 0
## 7 7 1.60704 4632.716 4677.532 0.28096 0
## 6 6 1.60753 4637.489 4677.837 0.28214 0
## 5 5 1.61385 4644.622 4680.499 0.28072 0
## 4 4 1.64636 4663.600 4695.003 0.26577 0
## 3 3 1.66270 4688.551 4715.478 0.24326 0
## 2 2 1.67597 4712.649 4735.095 0.22173 0
## 1 1 1.68846 4728.713 4746.676 0.21036 0
finiteDLMauto( x = as.vector(ppt) , y = as.vector(solar), q.min = 1, q.max = 10,
model.type = "dlm", error.type ="BIC", trace = TRUE)
## q - k MASE AIC BIC R.Adj.Sq Ljung-Box
## 10 10 1.57800 4602.658 4660.858 0.29615 0
## 9 9 1.59312 4615.084 4668.827 0.28882 0
## 8 8 1.60481 4625.986 4675.267 0.28251 0
## 7 7 1.60704 4632.716 4677.532 0.28096 0
## 6 6 1.60753 4637.489 4677.837 0.28214 0
## 5 5 1.61385 4644.622 4680.499 0.28072 0
## 4 4 1.64636 4663.600 4695.003 0.26577 0
## 3 3 1.66270 4688.551 4715.478 0.24326 0
## 2 2 1.67597 4712.649 4735.095 0.22173 0
## 1 1 1.68846 4728.713 4746.676 0.21036 0
# polyDlm:
modelca2 = polyDlm( x =as.vector(ppt) ,
y = as.vector(solar) ,
q = 10 , k = 10 , show.beta = FALSE)
summary(modelca2)
##
## Call:
## "Y ~ (Intercept) + X.t"
##
## Residuals:
## Min 1Q Median 3Q Max
## -19.0521 -5.4604 -0.7981 4.0705 30.8643
##
## Coefficients: (1 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.901e+01 1.094e+00 17.382 < 2e-16 ***
## z.t0 -7.349e+00 1.897e+00 -3.875 0.000118 ***
## z.t1 8.893e+00 9.385e+01 0.095 0.924533
## z.t2 3.090e+00 2.181e+02 0.014 0.988702
## z.t3 -1.004e+01 1.974e+02 -0.051 0.959477
## z.t4 6.545e+00 9.302e+01 0.070 0.943921
## z.t5 -2.069e+00 2.537e+01 -0.082 0.935048
## z.t6 3.641e-01 4.157e+00 0.088 0.930227
## z.t7 -3.648e-02 4.032e-01 -0.090 0.927934
## z.t8 1.950e-03 2.132e-02 0.091 0.927177
## z.t9 -4.323e-05 4.736e-04 -0.091 0.927293
## z.t10 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.25 on 639 degrees of freedom
## Multiple R-squared: 0.3079, Adjusted R-squared: 0.297
## F-statistic: 28.42 on 10 and 639 DF, p-value: < 2.2e-16
checkresiduals(modelca2$model)
##
## Breusch-Godfrey test for serial correlation of order up to 15
##
## data: Residuals
## LM test = 587.98, df = 15, p-value < 2.2e-16
MASE(modelca2)
## MASE
## modelca2 1.580235
modelca3 = polyDlm( x =as.vector(ppt) ,
y = as.vector(solar) ,
q = 1 , k = 1 , show.beta = FALSE)
summary(modelca3)
##
## Call:
## "Y ~ (Intercept) + X.t"
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.816 -5.736 -0.742 4.717 32.283
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 23.2467 0.5839 39.814 < 2e-16 ***
## z.t0 -15.7626 1.5425 -10.219 < 2e-16 ***
## z.t1 19.8764 2.9067 6.838 1.84e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.715 on 656 degrees of freedom
## Multiple R-squared: 0.2128, Adjusted R-squared: 0.2104
## F-statistic: 88.65 on 2 and 656 DF, p-value: < 2.2e-16
checkresiduals(modelca3$model)
##
## Breusch-Godfrey test for serial correlation of order up to 10
##
## data: Residuals
## LM test = 568.25, df = 10, p-value < 2.2e-16
VIF.modelca3 = vif(modelca3$model)
VIF.modelca3 > 10
## z.t0 z.t1
## FALSE FALSE
MASE(modelca3)
## MASE
## modelca3 1.688457
# koyckDlm:
modelca4 = koyckDlm(x = as.vector(ppt) , y = as.vector(solar))
summary(modelca4)
##
## Call:
## "Y ~ (Intercept) + Y.1 + X.t"
##
## Residuals:
## Min 1Q Median 3Q Max
## -13.0926 -3.5961 0.3176 3.6103 14.8399
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.23925 0.76549 -2.925 0.00356 **
## Y.1 0.98546 0.02424 40.650 < 2e-16 ***
## X.t 5.34684 0.84383 6.336 4.37e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.814 on 656 degrees of freedom
## Multiple R-Squared: 0.7598, Adjusted R-squared: 0.7591
## Wald test: 1104 on 2 and 656 DF, p-value: < 2.2e-16
##
## alpha beta phi
## Geometric coefficients: -154.0203 5.346844 0.9854613
checkresiduals(modelca4$model)
VIF.modelca4 = vif(modelca4$model)
VIF.modelca4 > 10
## Y.1 X.t
## FALSE FALSE
attr(modelca4$model,"class") = "lm"
AIC(modelca4$model)
## [1] 3946.476
BIC(modelca4$model)
## [1] 3964.439
MASE(modelca4)
## MASE
## modelca4 1.032483
# ardlDlm:
for (i in 1:15){
for(j in 1:15){
modelca5 = ardlDlm(x =as.vector(ppt) ,
y = as.vector(solar), p = i , q = j )
cat("p = ", i, "q = ", j, "AIC = ", AIC(modelca5$model), "BIC = ", BIC(modelca5$model),"\n")
}
}
## p = 1 q = 1 AIC = 3712.311 BIC = 3734.765
## p = 1 q = 2 AIC = 3239.416 BIC = 3266.352
## p = 1 q = 3 AIC = 3143.522 BIC = 3174.936
## p = 1 q = 4 AIC = 3138.399 BIC = 3174.288
## p = 1 q = 5 AIC = 3100.283 BIC = 3140.644
## p = 1 q = 6 AIC = 3033.2 BIC = 3078.031
## p = 1 q = 7 AIC = 3014.566 BIC = 3063.864
## p = 1 q = 8 AIC = 3011.894 BIC = 3065.654
## p = 1 q = 9 AIC = 3006.442 BIC = 3064.663
## p = 1 q = 10 AIC = 2996.457 BIC = 3059.135
## p = 1 q = 11 AIC = 2979.302 BIC = 3046.433
## p = 1 q = 12 AIC = 2942.604 BIC = 3014.186
## p = 1 q = 13 AIC = 2929.206 BIC = 3005.235
## p = 1 q = 14 AIC = 2926.209 BIC = 3006.683
## p = 1 q = 15 AIC = 2919.972 BIC = 3004.888
## p = 2 q = 1 AIC = 3639.223 BIC = 3666.159
## p = 2 q = 2 AIC = 3229.051 BIC = 3260.476
## p = 2 q = 3 AIC = 3137.634 BIC = 3173.535
## p = 2 q = 4 AIC = 3132.962 BIC = 3173.337
## p = 2 q = 5 AIC = 3097.288 BIC = 3142.134
## p = 2 q = 6 AIC = 3031.898 BIC = 3081.212
## p = 2 q = 7 AIC = 3013.616 BIC = 3067.395
## p = 2 q = 8 AIC = 3010.8 BIC = 3069.04
## p = 2 q = 9 AIC = 3005.437 BIC = 3068.136
## p = 2 q = 10 AIC = 2995.768 BIC = 3062.922
## p = 2 q = 11 AIC = 2977.955 BIC = 3049.562
## p = 2 q = 12 AIC = 2942.125 BIC = 3018.181
## p = 2 q = 13 AIC = 2928.617 BIC = 3009.12
## p = 2 q = 14 AIC = 2924.793 BIC = 3009.738
## p = 2 q = 15 AIC = 2918.361 BIC = 3007.746
## p = 3 q = 1 AIC = 3608.793 BIC = 3640.207
## p = 3 q = 2 AIC = 3226.623 BIC = 3262.524
## p = 3 q = 3 AIC = 3139.409 BIC = 3179.798
## p = 3 q = 4 AIC = 3134.777 BIC = 3179.638
## p = 3 q = 5 AIC = 3098.808 BIC = 3148.139
## p = 3 q = 6 AIC = 3032.418 BIC = 3086.216
## p = 3 q = 7 AIC = 3013.636 BIC = 3071.897
## p = 3 q = 8 AIC = 3010.775 BIC = 3073.495
## p = 3 q = 9 AIC = 3005.95 BIC = 3073.127
## p = 3 q = 10 AIC = 2996.59 BIC = 3068.221
## p = 3 q = 11 AIC = 2978.439 BIC = 3054.521
## p = 3 q = 12 AIC = 2943.273 BIC = 3023.803
## p = 3 q = 13 AIC = 2929.094 BIC = 3014.068
## p = 3 q = 14 AIC = 2925.218 BIC = 3014.634
## p = 3 q = 15 AIC = 2918.579 BIC = 3012.433
## p = 4 q = 1 AIC = 3602.664 BIC = 3638.553
## p = 4 q = 2 AIC = 3224.285 BIC = 3264.66
## p = 4 q = 3 AIC = 3131.289 BIC = 3176.15
## p = 4 q = 4 AIC = 3131.424 BIC = 3180.772
## p = 4 q = 5 AIC = 3096.024 BIC = 3149.839
## p = 4 q = 6 AIC = 3027.07 BIC = 3085.35
## p = 4 q = 7 AIC = 3006.43 BIC = 3069.173
## p = 4 q = 8 AIC = 3003.603 BIC = 3070.804
## p = 4 q = 9 AIC = 2998.61 BIC = 3070.266
## p = 4 q = 10 AIC = 2986.78 BIC = 3062.889
## p = 4 q = 11 AIC = 2969.385 BIC = 3049.943
## p = 4 q = 12 AIC = 2932.294 BIC = 3017.298
## p = 4 q = 13 AIC = 2917.646 BIC = 3007.093
## p = 4 q = 14 AIC = 2914.65 BIC = 3008.537
## p = 4 q = 15 AIC = 2908.197 BIC = 3006.521
## p = 5 q = 1 AIC = 3599.402 BIC = 3639.764
## p = 5 q = 2 AIC = 3221.853 BIC = 3266.699
## p = 5 q = 3 AIC = 3127.103 BIC = 3176.434
## p = 5 q = 4 AIC = 3127.868 BIC = 3181.684
## p = 5 q = 5 AIC = 3097.877 BIC = 3156.177
## p = 5 q = 6 AIC = 3029.06 BIC = 3091.824
## p = 5 q = 7 AIC = 3008.224 BIC = 3075.448
## p = 5 q = 8 AIC = 3005.42 BIC = 3077.101
## p = 5 q = 9 AIC = 3000.385 BIC = 3076.52
## p = 5 q = 10 AIC = 2988.572 BIC = 3069.158
## p = 5 q = 11 AIC = 2970.343 BIC = 3055.376
## p = 5 q = 12 AIC = 2933.501 BIC = 3022.979
## p = 5 q = 13 AIC = 2918.19 BIC = 3012.109
## p = 5 q = 14 AIC = 2915.232 BIC = 3013.59
## p = 5 q = 15 AIC = 2908.636 BIC = 3011.429
## p = 6 q = 1 AIC = 3586.116 BIC = 3630.948
## p = 6 q = 2 AIC = 3214.331 BIC = 3263.645
## p = 6 q = 3 AIC = 3119.154 BIC = 3172.952
## p = 6 q = 4 AIC = 3120.48 BIC = 3178.76
## p = 6 q = 5 AIC = 3094.149 BIC = 3156.912
## p = 6 q = 6 AIC = 3030.976 BIC = 3098.223
## p = 6 q = 7 AIC = 3010.203 BIC = 3081.908
## p = 6 q = 8 AIC = 3007.386 BIC = 3083.546
## p = 6 q = 9 AIC = 3002.341 BIC = 3082.954
## p = 6 q = 10 AIC = 2990.569 BIC = 3075.631
## p = 6 q = 11 AIC = 2972.342 BIC = 3061.85
## p = 6 q = 12 AIC = 2934.744 BIC = 3028.696
## p = 6 q = 13 AIC = 2919.101 BIC = 3017.493
## p = 6 q = 14 AIC = 2916.365 BIC = 3019.194
## p = 6 q = 15 AIC = 2909.475 BIC = 3016.737
## p = 7 q = 1 AIC = 3575.799 BIC = 3625.097
## p = 7 q = 2 AIC = 3212.372 BIC = 3266.151
## p = 7 q = 3 AIC = 3117.291 BIC = 3175.551
## p = 7 q = 4 AIC = 3118.61 BIC = 3181.352
## p = 7 q = 5 AIC = 3091.439 BIC = 3158.663
## p = 7 q = 6 AIC = 3022.352 BIC = 3094.058
## p = 7 q = 7 AIC = 3002.413 BIC = 3078.6
## p = 7 q = 8 AIC = 2998.638 BIC = 3079.278
## p = 7 q = 9 AIC = 2994.189 BIC = 3079.28
## p = 7 q = 10 AIC = 2980.152 BIC = 3069.691
## p = 7 q = 11 AIC = 2960.241 BIC = 3054.225
## p = 7 q = 12 AIC = 2921.752 BIC = 3020.177
## p = 7 q = 13 AIC = 2908.528 BIC = 3011.392
## p = 7 q = 14 AIC = 2905.445 BIC = 3012.744
## p = 7 q = 15 AIC = 2898.172 BIC = 3009.903
## p = 8 q = 1 AIC = 3538.751 BIC = 3592.512
## p = 8 q = 2 AIC = 3180.78 BIC = 3239.02
## p = 8 q = 3 AIC = 3093.999 BIC = 3156.719
## p = 8 q = 4 AIC = 3095.328 BIC = 3162.529
## p = 8 q = 5 AIC = 3068.742 BIC = 3140.423
## p = 8 q = 6 AIC = 3006.28 BIC = 3082.441
## p = 8 q = 7 AIC = 2991.824 BIC = 3072.465
## p = 8 q = 8 AIC = 2993.801 BIC = 3078.922
## p = 8 q = 9 AIC = 2990.093 BIC = 3079.664
## p = 8 q = 10 AIC = 2977.316 BIC = 3071.333
## p = 8 q = 11 AIC = 2959.055 BIC = 3057.515
## p = 8 q = 12 AIC = 2921.816 BIC = 3024.715
## p = 8 q = 13 AIC = 2908.703 BIC = 3016.039
## p = 8 q = 14 AIC = 2905.932 BIC = 3017.702
## p = 8 q = 15 AIC = 2898.381 BIC = 3014.582
## p = 9 q = 1 AIC = 3503.723 BIC = 3561.943
## p = 9 q = 2 AIC = 3168.825 BIC = 3231.525
## p = 9 q = 3 AIC = 3074.896 BIC = 3142.074
## p = 9 q = 4 AIC = 3075.884 BIC = 3147.54
## p = 9 q = 5 AIC = 3048.439 BIC = 3124.574
## p = 9 q = 6 AIC = 2983.773 BIC = 3064.386
## p = 9 q = 7 AIC = 2972.197 BIC = 3057.289
## p = 9 q = 8 AIC = 2973.907 BIC = 3063.477
## p = 9 q = 9 AIC = 2975.583 BIC = 3069.631
## p = 9 q = 10 AIC = 2963.123 BIC = 3061.616
## p = 9 q = 11 AIC = 2947.033 BIC = 3049.968
## p = 9 q = 12 AIC = 2913.567 BIC = 3020.94
## p = 9 q = 13 AIC = 2899.978 BIC = 3011.787
## p = 9 q = 14 AIC = 2897.119 BIC = 3013.359
## p = 9 q = 15 AIC = 2891.053 BIC = 3011.723
## p = 10 q = 1 AIC = 3486.25 BIC = 3548.927
## p = 10 q = 2 AIC = 3165.653 BIC = 3232.807
## p = 10 q = 3 AIC = 3072.759 BIC = 3144.39
## p = 10 q = 4 AIC = 3073.91 BIC = 3150.018
## p = 10 q = 5 AIC = 3046.099 BIC = 3126.684
## p = 10 q = 6 AIC = 2980.553 BIC = 3065.615
## p = 10 q = 7 AIC = 2968.654 BIC = 3058.193
## p = 10 q = 8 AIC = 2970.239 BIC = 3064.256
## p = 10 q = 9 AIC = 2972.143 BIC = 3070.636
## p = 10 q = 10 AIC = 2962.601 BIC = 3065.571
## p = 10 q = 11 AIC = 2946.44 BIC = 3053.851
## p = 10 q = 12 AIC = 2913.952 BIC = 3025.8
## p = 10 q = 13 AIC = 2899.906 BIC = 3016.187
## p = 10 q = 14 AIC = 2897.117 BIC = 3017.829
## p = 10 q = 15 AIC = 2891.07 BIC = 3016.209
## p = 11 q = 1 AIC = 3477.139 BIC = 3544.27
## p = 11 q = 2 AIC = 3162.828 BIC = 3234.434
## p = 11 q = 3 AIC = 3071.052 BIC = 3147.135
## p = 11 q = 4 AIC = 3072.21 BIC = 3152.768
## p = 11 q = 5 AIC = 3043.91 BIC = 3128.944
## p = 11 q = 6 AIC = 2978.876 BIC = 3068.385
## p = 11 q = 7 AIC = 2966.892 BIC = 3060.876
## p = 11 q = 8 AIC = 2968.47 BIC = 3066.929
## p = 11 q = 9 AIC = 2970.38 BIC = 3073.315
## p = 11 q = 10 AIC = 2960.572 BIC = 3067.982
## p = 11 q = 11 AIC = 2948.052 BIC = 3059.937
## p = 11 q = 12 AIC = 2915.641 BIC = 3031.962
## p = 11 q = 13 AIC = 2901.696 BIC = 3022.449
## p = 11 q = 14 AIC = 2898.937 BIC = 3024.119
## p = 11 q = 15 AIC = 2892.818 BIC = 3022.426
## p = 12 q = 1 AIC = 3472.271 BIC = 3543.853
## p = 12 q = 2 AIC = 3160.003 BIC = 3236.06
## p = 12 q = 3 AIC = 3068.088 BIC = 3148.618
## p = 12 q = 4 AIC = 3069.332 BIC = 3154.336
## p = 12 q = 5 AIC = 3041.35 BIC = 3130.828
## p = 12 q = 6 AIC = 2974.581 BIC = 3068.533
## p = 12 q = 7 AIC = 2963.3 BIC = 3061.726
## p = 12 q = 8 AIC = 2964.786 BIC = 3067.685
## p = 12 q = 9 AIC = 2966.735 BIC = 3074.108
## p = 12 q = 10 AIC = 2957.638 BIC = 3069.486
## p = 12 q = 11 AIC = 2946.207 BIC = 3062.529
## p = 12 q = 12 AIC = 2917.586 BIC = 3038.381
## p = 12 q = 13 AIC = 2903.694 BIC = 3028.92
## p = 12 q = 14 AIC = 2900.937 BIC = 3030.59
## p = 12 q = 15 AIC = 2894.784 BIC = 3028.861
## p = 13 q = 1 AIC = 3466.396 BIC = 3542.425
## p = 13 q = 2 AIC = 3149.639 BIC = 3230.141
## p = 13 q = 3 AIC = 3054.07 BIC = 3139.045
## p = 13 q = 4 AIC = 3055.592 BIC = 3145.039
## p = 13 q = 5 AIC = 3029.941 BIC = 3123.86
## p = 13 q = 6 AIC = 2963.045 BIC = 3061.437
## p = 13 q = 7 AIC = 2948.98 BIC = 3051.844
## p = 13 q = 8 AIC = 2950.463 BIC = 3057.799
## p = 13 q = 9 AIC = 2952.384 BIC = 3064.193
## p = 13 q = 10 AIC = 2942.543 BIC = 3058.824
## p = 13 q = 11 AIC = 2930.864 BIC = 3051.617
## p = 13 q = 12 AIC = 2902.893 BIC = 3028.119
## p = 13 q = 13 AIC = 2904.307 BIC = 3034.005
## p = 13 q = 14 AIC = 2901.428 BIC = 3035.552
## p = 13 q = 15 AIC = 2895.384 BIC = 3033.931
## p = 14 q = 1 AIC = 3457.014 BIC = 3537.489
## p = 14 q = 2 AIC = 3142.399 BIC = 3227.344
## p = 14 q = 3 AIC = 3048.7 BIC = 3138.116
## p = 14 q = 4 AIC = 3050.305 BIC = 3144.192
## p = 14 q = 5 AIC = 3025.438 BIC = 3123.796
## p = 14 q = 6 AIC = 2959.487 BIC = 3062.315
## p = 14 q = 7 AIC = 2945.846 BIC = 3053.145
## p = 14 q = 8 AIC = 2947.343 BIC = 3059.113
## p = 14 q = 9 AIC = 2949.294 BIC = 3065.534
## p = 14 q = 10 AIC = 2938.922 BIC = 3059.633
## p = 14 q = 11 AIC = 2926.974 BIC = 3052.156
## p = 14 q = 12 AIC = 2900.118 BIC = 3029.771
## p = 14 q = 13 AIC = 2901.711 BIC = 3035.835
## p = 14 q = 14 AIC = 2903.258 BIC = 3041.852
## p = 14 q = 15 AIC = 2897.289 BIC = 3040.305
## p = 15 q = 1 AIC = 3443.884 BIC = 3528.8
## p = 15 q = 2 AIC = 3131.919 BIC = 3221.304
## p = 15 q = 3 AIC = 3042.451 BIC = 3136.305
## p = 15 q = 4 AIC = 3044.249 BIC = 3142.573
## p = 15 q = 5 AIC = 3020.493 BIC = 3123.286
## p = 15 q = 6 AIC = 2954.704 BIC = 3061.966
## p = 15 q = 7 AIC = 2940.973 BIC = 3052.705
## p = 15 q = 8 AIC = 2942.547 BIC = 3058.747
## p = 15 q = 9 AIC = 2944.503 BIC = 3065.173
## p = 15 q = 10 AIC = 2934.634 BIC = 3059.773
## p = 15 q = 11 AIC = 2923.348 BIC = 3052.956
## p = 15 q = 12 AIC = 2896.573 BIC = 3030.651
## p = 15 q = 13 AIC = 2898.068 BIC = 3036.614
## p = 15 q = 14 AIC = 2899.728 BIC = 3042.744
## p = 15 q = 15 AIC = 2899.254 BIC = 3046.74
modelca6 = ardlDlm(x =as.vector(ppt) ,
y = as.vector(solar), p = 9 , q = 15 )
summary(modelca6)
##
## Time series regression with "ts" data:
## Start = 16, End = 660
##
## Call:
## dynlm(formula = as.formula(model.text), data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.9250 -1.0273 -0.1059 1.0047 17.7120
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.72860 0.54818 4.978 8.36e-07 ***
## X.t -0.25000 0.52374 -0.477 0.63330
## X.1 0.06512 0.71130 0.092 0.92708
## X.2 0.84196 0.72275 1.165 0.24449
## X.3 0.91264 0.72134 1.265 0.20627
## X.4 -1.06564 0.71401 -1.492 0.13609
## X.5 0.22576 0.71440 0.316 0.75210
## X.6 -2.56092 0.71233 -3.595 0.00035 ***
## X.7 2.11687 0.71688 2.953 0.00327 **
## X.8 0.81572 0.71332 1.144 0.25326
## X.9 -1.57762 0.52537 -3.003 0.00278 **
## Y.1 1.09456 0.03984 27.472 < 2e-16 ***
## Y.2 0.12209 0.05904 2.068 0.03907 *
## Y.3 -0.17339 0.05826 -2.976 0.00303 **
## Y.4 -0.15757 0.05745 -2.743 0.00627 **
## Y.5 -0.19002 0.05761 -3.298 0.00103 **
## Y.6 0.10409 0.05818 1.789 0.07408 .
## Y.7 0.08006 0.05807 1.379 0.16852
## Y.8 -0.10972 0.05777 -1.899 0.05799 .
## Y.9 0.12455 0.05809 2.144 0.03242 *
## Y.10 0.06356 0.05821 1.092 0.27527
## Y.11 0.11699 0.05791 2.020 0.04380 *
## Y.12 -0.16714 0.05792 -2.886 0.00404 **
## Y.13 -0.06223 0.05791 -1.075 0.28299
## Y.14 -0.04757 0.05787 -0.822 0.41141
## Y.15 0.06061 0.03877 1.563 0.11847
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.228 on 619 degrees of freedom
## Multiple R-squared: 0.9508, Adjusted R-squared: 0.9488
## F-statistic: 478.8 on 25 and 619 DF, p-value: < 2.2e-16
checkresiduals(modelca6$model)
##
## Breusch-Godfrey test for serial correlation of order up to 29
##
## data: Residuals
## LM test = 55.251, df = 29, p-value = 0.002316
VIF.modelca6 = vif(modelca6$model)
VIF.modelca6 > 10
## X.t L(X.t, 1) L(X.t, 2) L(X.t, 3) L(X.t, 4) L(X.t, 5)
## FALSE FALSE FALSE FALSE FALSE FALSE
## L(X.t, 6) L(X.t, 7) L(X.t, 8) L(X.t, 9) L(y.t, 1) L(y.t, 2)
## FALSE FALSE FALSE FALSE TRUE TRUE
## L(y.t, 3) L(y.t, 4) L(y.t, 5) L(y.t, 6) L(y.t, 7) L(y.t, 8)
## TRUE TRUE TRUE TRUE TRUE TRUE
## L(y.t, 9) L(y.t, 10) L(y.t, 11) L(y.t, 12) L(y.t, 13) L(y.t, 14)
## TRUE TRUE TRUE TRUE TRUE TRUE
## L(y.t, 15)
## TRUE
MASE(modelca6)
## MASE
## modelca6 0.3812687
# Forecasting:
forecast.ardldlm = dLagM::forecast(model=modelca6, x = c(0.189009998,0.697262522,0.595213491,0.487388526,0.261677017,0.808606651,0.94186202,0.905636325,1.059964682,0.341438784,0.525805322,0.602471062, 0.109860632,0.781464707,0.69685501,0.502413906,0.649385609,0.745960773,0.663047123,0.533770112,0.61542621,0.54606508,0.142673325,0.013650407), h=24)$forecasts
forecast.ardldlm
## [1] 5.6685145 5.5469002 7.6026670 10.9141865 18.1481627 20.3932993
## [7] 21.8324065 16.8962240 14.6455820 13.2075047 8.3822395 6.4341929
## [13] 6.2354723 11.4372455 12.6418302 8.3207547 4.2004823 0.9825388
## [19] 9.3370308 17.6871819 23.2888147 25.7715376 16.7694623 14.4553104
plot(ts(c(as.vector(solar), forecast.ardldlm),start=c(1960,1),frequency = 12), ylab = "Solar Radiation", main = "Forecasting of the amount
of Solar Radiation for the next 2 years Fig 3.5")
As it is observed that there is no trend and there is seasonality, the models which includes seasonality components are (Additive or Multiplicative) and might include the error term so the candidate models are:
Then by using the first candidate make a model checks its summary and residuals.
Then checked its summary and observed the values of AIC, AICc and BIC are 5434.708, 5435.662 and 5511.076 respectively. The MASE is about 0.24716 and the p-values is also good.
Then checked the residuals (Fig 4.0) they are random, correlation is prominent, pattern in histogram was also almost normalized but ACF has some patterns.
Then by using the second candidate make a model checks its summary and residuals.
Then checked its summary and observed the values of AIC, AICc and BIC are 5428.422, 5429.489 and 5509.282 respectively. The MASE is about 0.2461797 which is slightly better than the previous model and the p-values is also good.
Then checked the residuals (Fig 4.1) they are random, correlation is prominent, pattern in histogram was also almost normalized but ACF has some patterns.
Then by using the third candidate make a model checks its summary and residuals.
Then checked its summary and observed the values of AIC, AICc and BIC are 6648.746, 6649.699 and 6725.114 respectively. The MASE is about 0.2233077 which is smaller than all the previous model and the p-values is also good.
Then checked the residuals (Fig 4.2) they are random, correlation is prominent, pattern in histogram was also almost normalized and ACF also seems fine.
Then by using the fourth candidate make a model checks its summary and residuals.
Then checked its summary and observed the values of AIC, AICc and BIC are 6584.208, 6585.161 and 6660.576 respectively. The MASE is about 0.2320404 which is slightly higher than the previous model and the p-values is ok.
Then checked the residuals (Fig 4.3) they are random, correlation is prominent, pattern in histogram was also almost normalized and ACF also seems fine.
Then by using the fifth candidate make a model checks its summary and residuals.
Then checked its summary and observed the values of AIC, AICc and BIC are 6366.701, 6367.768 and 6447.561 respectively. The MASE is about 0.2035619 which is slightly higher than the previous model and the p-values is ok.
Then checked the residuals (Fig 4.4) they are random, correlation is prominent, pattern in histogram was also almost normalized and ACF also seems fine.
The third, fourth and fifth candidate models gives the best result according to MASE but taking other aspects into consideration like p-value, AIC, AICc, BIC and residual analysis the fifth model of holt’s winter with multiplicative seasonality is the best one.
Then just for testing purposes an automatic ets test was run and it gave us the model “ETS(A,Ad,A)”, so this model was fitted on the solar series and then analysed.
Then checked the residuals (Fig 4.5) they are random, correlation is prominent, pattern in histogram was also almost normalized but ACF has some patterns.
Then the forecasting was plotted for the best model and found out that this candidate model shows the beter prediction then ardlm as shown in (Fig 4.6).
So finally, the fifth model with the lowest MASE was selected and forecasting was done with the help of that model.
Forecasting was done to calculate the amount of solar radiations for the next two years and the following plot was observed (Fig 4.8), and this model in the exponential smoothing package shows some great forecasting as compared to the one done in dLagM model.
So, at last this forecasting was selected to be the best forecast.
fit1.hw <- hw(solar,seasonal="additive", h=5*frequency(solar))
summary(fit1.hw)
##
## Forecast method: Holt-Winters' additive method
##
## Model Information:
## Holt-Winters' additive method
##
## Call:
## hw(y = solar, h = 5 * frequency(solar), seasonal = "additive")
##
## Smoothing parameters:
## alpha = 0.9993
## beta = 0.0019
## gamma = 1e-04
##
## Initial states:
## l = 11.3306
## b = 0.209
## s = -10.7542 -8.4968 -3.227 3.0768 7.9264 10.9122
## 10.1422 7.3322 2.2353 -1.9528 -7.3626 -9.8316
##
## sigma: 2.3575
##
## AIC AICc BIC
## 5434.708 5435.662 5511.076
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.1179476 2.328736 1.504489 -2.230359 12.68101 0.24716
## ACF1
## Training set 0.1703355
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2015 6.127399 3.1061581 9.148641 1.5068095 10.74799
## Feb 2015 8.655602 4.3802222 12.930983 2.1169727 15.19423
## Mar 2015 14.122221 8.8814747 19.362968 6.1071910 22.13725
## Apr 2015 18.366625 12.3095941 24.423656 9.1031957 27.63005
## May 2015 23.522264 16.7439512 30.300578 13.1557290 33.88880
## Jun 2015 26.390991 18.9586817 33.823300 15.0242549 37.75773
## Jul 2015 27.219228 19.1837595 35.254697 14.9300392 39.50842
## Aug 2015 24.290519 15.6920179 32.889020 11.1402463 37.44079
## Sep 2015 19.495874 10.3670365 28.624711 5.5345219 33.45723
## Oct 2015 13.253765 3.6218809 22.885648 -1.4769303 27.98446
## Nov 2015 8.042144 -2.0695730 18.153861 -7.4223926 23.50668
## Dec 2015 5.840110 -4.7313921 16.411612 -10.3276072 22.00783
## Jan 2016 6.819616 -4.1942247 17.833457 -10.0246000 23.66383
## Feb 2016 9.347819 -2.0927719 20.788410 -8.1490551 26.84469
## Mar 2016 14.814438 2.9609172 26.667959 -3.3139578 32.94283
## Apr 2016 19.058842 6.8048110 31.312872 0.3179190 37.79976
## May 2016 24.214481 11.5711780 36.857784 4.8782175 43.55074
## Jun 2016 27.083208 14.0608586 40.105557 7.1672434 46.99917
## Jul 2016 27.911445 14.5194061 41.303485 7.4300887 48.39280
## Aug 2016 24.982736 11.2296053 38.735867 3.9491378 46.01633
## Sep 2016 20.188091 6.0818048 34.294377 -1.3856120 41.76179
## Oct 2016 13.945981 -0.5061083 28.398071 -8.1565824 36.04855
## Nov 2016 8.734361 -6.0566988 23.525420 -13.8866128 31.35533
## Dec 2016 6.532327 -8.5913309 21.655984 -16.5973115 29.66196
## Jan 2017 7.511833 -7.9385282 22.962194 -16.1174555 31.14112
## Feb 2017 10.040036 -5.7313777 25.811450 -14.0802599 34.16033
## Mar 2017 15.506655 -0.5805619 31.593872 -9.0966201 40.10993
## Apr 2017 19.751059 3.3529822 36.149135 -5.3276351 44.82975
## May 2017 24.906698 8.2024281 41.610968 -0.6402783 50.45367
## Jun 2017 27.775425 10.7693726 44.781476 1.7669125 53.78394
## Jul 2017 28.603662 11.3000071 45.907317 2.1400055 55.06732
## Aug 2017 25.674953 8.0776596 43.272246 -1.2377847 52.58769
## Sep 2017 20.880308 2.9931440 38.767471 -6.4757484 48.23636
## Oct 2017 14.638198 -3.5352503 32.811647 -13.1556929 42.43209
## Nov 2017 9.426578 -9.0297392 27.882894 -18.7999231 37.65308
## Dec 2017 7.224543 -11.5113813 25.960468 -21.4295807 35.87867
## Jan 2018 8.204050 -10.8084216 27.216522 -20.8730161 37.28112
## Feb 2018 10.732253 -8.5537326 30.018238 -18.7631166 40.22762
## Mar 2018 16.198872 -3.3577754 35.755519 -13.7104391 46.10818
## Apr 2018 20.443275 0.6186997 40.267851 -9.8757968 50.76235
## May 2018 25.598915 5.5090332 45.688797 -5.1259078 56.32374
## Jun 2018 28.467641 8.1149718 48.820311 -2.6590806 59.59436
## Jul 2018 29.295879 8.6828417 49.908916 -2.2290411 60.82080
## Aug 2018 26.367170 5.4960925 47.238247 -5.5523883 58.28673
## Sep 2018 21.572524 0.4456486 42.699400 -10.7382439 53.88329
## Oct 2018 15.330415 -6.0501007 36.710931 -17.3682620 48.02909
## Nov 2018 10.118794 -11.5132798 31.750868 -22.9646081 43.20220
## Dec 2018 7.916760 -13.9648644 29.798385 -25.5482967 41.38182
## Jan 2019 8.896267 -13.2330166 31.025550 -24.9475516 42.74009
## Feb 2019 11.424470 -10.9505524 33.799492 -22.7951736 45.64411
## Mar 2019 16.891089 -5.7278620 39.510039 -17.7016112 51.48379
## Apr 2019 21.135492 -1.7256366 43.996621 -13.8275871 56.09857
## May 2019 26.291132 3.1895190 49.392744 -9.0397360 61.62200
## Jun 2019 29.159858 5.8194018 52.500314 -6.5362894 64.85601
## Jul 2019 29.988096 6.4103847 53.565807 -6.0709017 66.04709
## Aug 2019 27.059386 3.2459605 50.872812 -9.3601057 63.47888
## Sep 2019 22.264741 -1.7829062 46.312389 -14.5129618 59.04244
## Oct 2019 16.022632 -8.2577885 40.303052 -21.1110666 53.15633
## Nov 2019 10.811011 -13.7007762 35.322798 -26.6765326 48.29855
## Dec 2019 8.608977 -16.1328122 33.350766 -29.2303243 46.44828
checkresiduals(fit1.hw)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 205.55, df = 8, p-value < 2.2e-16
##
## Model df: 16. Total lags used: 24
fit2.hw <- hw(solar,seasonal="additive",damped = TRUE, h=5*frequency(solar))
summary(fit2.hw)
##
## Forecast method: Damped Holt-Winters' additive method
##
## Model Information:
## Damped Holt-Winters' additive method
##
## Call:
## hw(y = solar, h = 5 * frequency(solar), seasonal = "additive",
##
## Call:
## damped = TRUE)
##
## Smoothing parameters:
## alpha = 0.9999
## beta = 1e-04
## gamma = 1e-04
## phi = 0.9388
##
## Initial states:
## l = 11.154
## b = 0.7632
## s = -10.4919 -8.137 -3.348 2.5794 8.08 11.1219
## 9.9586 6.9916 1.9573 -1.8565 -7.1607 -9.6946
##
## sigma: 2.3446
##
## AIC AICc BIC
## 5428.422 5429.489 5509.282
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.01091357 2.314163 1.498521 -1.468083 12.44796 0.2461797
## ACF1
## Training set 0.1700724
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2015 5.945198 2.9405301 8.949866 1.3499548 10.54044
## Feb 2015 8.479778 4.2305479 12.729009 1.9811413 14.97842
## Mar 2015 13.784309 8.5799016 18.988716 5.8248548 21.74376
## Apr 2015 17.598568 11.5887764 23.608360 8.4073847 26.78975
## May 2015 22.632258 15.9128030 29.351713 12.3557383 32.90878
## Jun 2015 25.599150 18.2380236 32.960277 14.3412786 36.85702
## Jul 2015 26.761775 18.8104968 34.713053 14.6013444 38.92221
## Aug 2015 23.722251 15.2216103 32.222892 10.7216429 36.72286
## Sep 2015 18.222624 9.2059552 27.239293 4.4328191 32.01243
## Oct 2015 12.293259 2.7884705 21.798047 -2.2430606 26.82958
## Nov 2015 7.504219 -2.4648770 17.473315 -7.7421977 22.75064
## Dec 2015 5.150488 -5.2622860 15.563263 -10.7744758 21.07545
## Jan 2016 5.947275 -4.8911752 16.785726 -10.6287044 22.52326
## Feb 2016 8.481728 -2.7662508 19.729707 -8.7205712 25.68403
## Mar 2016 13.786139 2.1429879 25.429291 -4.0205242 31.59280
## Apr 2016 17.600287 5.5749058 29.625668 -0.7909464 35.99152
## May 2016 22.633871 10.2380087 35.029734 3.6760353 41.59171
## Jun 2016 25.600665 12.8450464 38.356283 6.0926298 45.10870
## Jul 2016 26.763197 13.6576670 39.868726 6.7200186 46.80637
## Aug 2016 23.723586 10.2772227 37.169950 3.1591478 44.28802
## Sep 2016 18.223877 4.4450855 32.002669 -2.8489663 39.29672
## Oct 2016 12.294435 -1.8089722 26.397843 -9.2748652 33.86374
## Nov 2016 7.505324 -6.9154138 21.926061 -14.5492911 29.55994
## Dec 2016 5.151525 -9.5797258 19.882776 -17.3779790 27.68103
## Jan 2017 5.948249 -9.0871906 20.983688 -17.0464714 28.94297
## Feb 2017 8.482642 -6.8508988 23.816183 -14.9679850 31.93327
## Mar 2017 13.786997 -1.8389729 29.412968 -10.1108619 37.68486
## Apr 2017 17.601092 1.6880528 33.514132 -6.7358014 41.93799
## May 2017 22.634628 6.4395949 38.829660 -2.1335375 47.40279
## Jun 2017 25.601375 9.1291648 42.073585 0.4093036 50.79345
## Jul 2017 26.763863 10.0190534 43.508673 1.1548866 52.37284
## Aug 2017 23.724212 6.7111602 40.737263 -2.2950052 49.74343
## Sep 2017 18.224465 0.9473269 35.501602 -8.1986374 44.64757
## Oct 2017 12.294987 -5.2422687 29.832242 -14.5259309 39.11590
## Nov 2017 7.505841 -10.2877372 25.299420 -19.7070886 34.71877
## Dec 2017 5.152011 -12.8942567 23.198279 -22.4473739 32.75140
## Jan 2018 5.948705 -12.3468264 24.244236 -22.0318957 33.92931
## Feb 2018 8.483070 -10.0583229 27.024464 -19.8735437 36.83968
## Mar 2018 13.787399 -4.9966434 32.571442 -14.9403150 42.51511
## Apr 2018 17.601470 -1.4221329 36.625072 -11.4926198 46.69556
## May 2018 22.634982 3.3747944 41.895169 -6.8209329 52.09090
## Jun 2018 25.601707 6.1078017 45.095613 -4.2116486 55.41506
## Jul 2018 26.764175 7.0393167 46.489034 -3.4023928 56.93074
## Aug 2018 23.724505 3.7713624 43.677647 -6.7911931 54.24020
## Sep 2018 18.224740 -1.9541074 38.403587 -12.6361439 49.08562
## Oct 2018 12.295245 -8.1068132 32.697304 -18.9070105 43.49750
## Nov 2018 7.506084 -13.1167729 28.128941 -24.0338538 39.04602
## Dec 2018 5.152239 -15.6890799 25.993558 -26.7218076 37.02629
## Jan 2019 5.948919 -15.1086483 27.006486 -26.2558509 38.15369
## Feb 2019 8.483271 -12.7882989 29.754841 -24.0487878 41.01533
## Mar 2019 13.787588 -7.6958556 35.271031 -19.0685035 46.64368
## Apr 2019 17.601647 -4.0916031 39.294896 -15.5753158 50.77861
## May 2019 22.635148 0.7340999 44.536196 -10.8596146 56.12991
## Jun 2019 25.601863 3.4949682 47.708758 -8.2077152 59.41144
## Jul 2019 26.764322 4.4534771 49.075166 -7.3571707 60.88581
## Aug 2019 23.724642 1.2116941 46.237591 -10.7059408 58.15523
## Sep 2019 18.224869 -4.4883862 40.938124 -16.5120571 52.96179
## Oct 2019 12.295366 -10.6164456 35.207178 -22.7452262 47.33596
## Nov 2019 7.506198 -15.6024666 30.614862 -27.8354544 42.84785
## Dec 2019 5.152346 -18.1515090 28.456200 -30.4878245 40.79252
checkresiduals(fit2.hw)
##
## Ljung-Box test
##
## data: Residuals from Damped Holt-Winters' additive method
## Q* = 210.76, df = 7, p-value < 2.2e-16
##
## Model df: 17. Total lags used: 24
fit3.hw <- hw(solar,seasonal="multiplicative", h=2*frequency(solar))
summary(fit3.hw)
##
## Forecast method: Holt-Winters' multiplicative method
##
## Model Information:
## Holt-Winters' multiplicative method
##
## Call:
## hw(y = solar, h = 2 * frequency(solar), seasonal = "multiplicative")
##
## Smoothing parameters:
## alpha = 0.8251
## beta = 1e-04
## gamma = 0.0259
##
## Initial states:
## l = 10.5659
## b = -0.2371
## s = 0.5024 0.6292 0.9319 1.2229 1.4923 1.6309
## 1.5606 1.3672 1.0278 0.8128 0.5106 0.3114
##
## sigma: 0.3971
##
## AIC AICc BIC
## 6648.746 6649.699 6725.114
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.04281136 2.12539 1.359297 -0.4896895 10.87401 0.2233077
## ACF1
## Training set 0.06551473
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2015 5.610335 2.75534413 8.465326 1.2440033 9.976666
## Feb 2015 6.512806 2.03809262 10.987520 -0.3306776 13.356290
## Mar 2015 8.786120 1.33667747 16.235562 -2.6068190 20.179058
## Apr 2015 10.192785 -0.02672876 20.412298 -5.4366123 25.822181
## May 2015 12.512597 -1.96157245 26.986766 -9.6237347 34.648928
## Jun 2015 14.061609 -4.41048190 32.533701 -14.1890164 42.312235
## Jul 2015 14.502088 -6.89909775 35.903274 -18.2282011 47.232377
## Aug 2015 12.945620 -8.35024040 34.241481 -19.6235881 45.514829
## Sep 2015 10.352210 -8.52365174 29.228072 -18.5159294 39.220350
## Oct 2015 7.418279 -7.51119146 22.347750 -15.4143760 30.250935
## Nov 2015 4.989730 -6.05900058 16.038460 -11.9078451 21.887305
## Dec 2015 3.871776 -5.53876625 13.282319 -10.5204066 18.263960
## Jan 2016 4.199400 -7.01753622 15.416336 -12.9554236 21.354224
## Feb 2016 4.838892 -9.30305408 18.980837 -16.7893479 26.467131
## Mar 2016 6.477174 -14.21845674 27.172805 -25.1740619 38.128410
## Apr 2016 7.452633 -18.56883703 33.474103 -32.3437711 47.249037
## May 2016 9.069749 -25.52978297 43.669280 -43.8456686 61.985166
## Jun 2016 10.099485 -31.99838423 52.197355 -54.2836502 74.482621
## Jul 2016 10.315199 -36.68017471 57.310572 -61.5580226 82.188420
## Aug 2016 9.113765 -36.29212001 54.519651 -60.3285438 78.556075
## Sep 2016 7.208700 -32.09306283 46.510463 -52.8981594 67.315559
## Oct 2016 5.105869 -25.38360449 35.595343 -41.5237568 51.735495
## Nov 2016 3.391945 -18.81647619 25.600367 -30.5729044 37.356795
## Dec 2016 2.597256 -16.07148862 21.266001 -25.9541251 31.148637
checkresiduals(fit3.hw)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' multiplicative method
## Q* = 38.585, df = 8, p-value = 5.868e-06
##
## Model df: 16. Total lags used: 24
fit4.hw <- hw(solar,seasonal="multiplicative",exponential = TRUE, h=5*frequency(solar))
summary(fit4.hw)
##
## Forecast method: Holt-Winters' multiplicative method with exponential trend
##
## Model Information:
## Holt-Winters' multiplicative method with exponential trend
##
## Call:
## hw(y = solar, h = 5 * frequency(solar), seasonal = "multiplicative",
##
## Call:
## exponential = TRUE)
##
## Smoothing parameters:
## alpha = 0.6499
## beta = 1e-04
## gamma = 0.0597
##
## Initial states:
## l = 9.3759
## b = 0.9889
## s = 0.3552 0.4789 0.952 1.0553 1.4608 1.7926
## 1.6746 1.4529 1.1145 0.8672 0.5333 0.2627
##
## sigma: 0.3755
##
## AIC AICc BIC
## 6584.208 6585.161 6660.576
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.06388152 2.208727 1.412454 -1.303792 11.28449 0.2320404
## ACF1
## Training set 0.153871
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2015 5.797870 2.97914127 8.639807 1.644427474 10.08164
## Feb 2015 7.513359 3.34951727 12.086812 1.776075505 15.14153
## Mar 2015 10.758212 4.35349718 18.537524 2.106769334 24.63747
## Apr 2015 12.694087 4.57249648 22.654960 2.278843226 31.88680
## May 2015 15.340074 4.94165089 29.167861 2.507785659 41.06949
## Jun 2015 17.239431 5.11339134 33.674137 2.569511030 50.43154
## Jul 2015 18.004700 4.87967149 35.945475 2.368986841 57.32599
## Aug 2015 16.206596 4.13374510 33.623020 1.848377916 55.02534
## Sep 2015 13.011256 3.03797566 26.719663 1.384463300 46.37224
## Oct 2015 9.215869 1.95869287 19.842040 0.778253176 33.66363
## Nov 2015 6.214762 1.23796550 13.835791 0.484541733 24.02569
## Dec 2015 4.565667 0.79942799 10.072896 0.318601385 18.19733
## Jan 2016 5.220661 0.85191836 11.844437 0.333097263 22.00930
## Feb 2016 6.765364 0.97461353 15.679979 0.411623568 30.40340
## Mar 2016 9.687175 1.32055366 22.405436 0.490075887 46.21142
## Apr 2016 11.430324 1.49942805 25.309714 0.545389487 54.52494
## May 2016 13.812889 1.72334790 32.375938 0.633684274 66.54740
## Jun 2016 15.523155 1.76130552 37.165623 0.683339891 77.38735
## Jul 2016 16.212237 1.73688573 39.112202 0.667969779 77.79028
## Aug 2016 14.593143 1.42714888 35.783835 0.526816671 73.99590
## Sep 2016 11.715916 1.09720777 28.867406 0.386589873 62.97202
## Oct 2016 8.298381 0.73432376 20.764577 0.254772202 44.81023
## Nov 2016 5.596049 0.47498064 13.634956 0.165502522 31.96281
## Dec 2016 4.111130 0.30693173 10.103351 0.102762210 23.08154
## Jan 2017 4.700916 0.34077620 11.455586 0.108451855 27.93883
## Feb 2017 6.091836 0.41153565 14.623204 0.142476360 34.24187
## Mar 2017 8.722765 0.57272432 21.361564 0.171126426 51.21713
## Apr 2017 10.292374 0.62521372 25.330971 0.203461389 61.93930
## May 2017 12.437743 0.69422891 31.462603 0.220746702 72.89489
## Jun 2017 13.977742 0.72734228 34.815583 0.221942090 83.10217
## Jul 2017 14.598223 0.73967972 35.475739 0.215652517 90.10927
## Aug 2017 13.140319 0.61010909 31.536671 0.175293660 84.00275
## Sep 2017 10.549535 0.46031504 25.634413 0.137920006 67.83462
## Oct 2017 7.472233 0.30713038 18.215372 0.096019860 49.37026
## Nov 2017 5.038933 0.19667979 11.903813 0.056634514 33.79673
## Dec 2017 3.701845 0.13325885 8.771328 0.034893897 26.50091
## Jan 2018 4.232915 0.14176887 10.110233 0.042735728 29.03712
## Feb 2018 5.485362 0.17374491 13.180913 0.042337983 39.63338
## Mar 2018 7.854368 0.23010252 18.916882 0.058274558 52.68137
## Apr 2018 9.267714 0.26941164 21.272417 0.069594807 67.23293
## May 2018 11.199499 0.30989087 26.881461 0.083207249 81.01326
## Jun 2018 12.586184 0.31792254 29.445596 0.086571893 91.66146
## Jul 2018 13.144893 0.31260736 31.058934 0.082098956 95.09699
## Aug 2018 11.832130 0.27412365 29.193981 0.067111573 95.12446
## Sep 2018 9.499273 0.19752408 22.514504 0.049742958 72.99732
## Oct 2018 6.728333 0.13708672 16.501488 0.035693856 49.00958
## Nov 2018 4.537281 0.08776856 10.737959 0.020983370 30.66318
## Dec 2018 3.333307 0.06055159 7.870714 0.013673368 23.02917
## Jan 2019 3.811506 0.06522347 9.044785 0.014436128 28.36450
## Feb 2019 4.939265 0.08028840 11.336514 0.019510520 36.49698
## Mar 2019 7.072424 0.10623340 16.277128 0.025812970 54.43265
## Apr 2019 8.345064 0.12275074 19.162108 0.028530524 61.27708
## May 2019 10.084530 0.14091459 22.351285 0.029835468 75.21518
## Jun 2019 11.333163 0.14788676 24.899355 0.029638167 91.86197
## Jul 2019 11.836249 0.14232035 26.717738 0.027589269 90.80075
## Aug 2019 10.654179 0.12651664 23.945552 0.025190493 82.86509
## Sep 2019 8.553570 0.08925397 19.128946 0.020093198 66.01332
## Oct 2019 6.058491 0.06521343 13.737042 0.012525610 48.66728
## Nov 2019 4.085570 0.04060032 9.375168 0.008598106 33.17750
## Dec 2019 3.001459 0.02816107 6.415085 0.005961340 23.82144
checkresiduals(fit4.hw)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' multiplicative method with exponential trend
## Q* = 21.246, df = 8, p-value = 0.006521
##
## Model df: 16. Total lags used: 24
fit5.hw <- hw(solar,seasonal="multiplicative",damped = TRUE, h=5*frequency(solar))
summary(fit5.hw)
##
## Forecast method: Damped Holt-Winters' multiplicative method
##
## Model Information:
## Damped Holt-Winters' multiplicative method
##
## Call:
## hw(y = solar, h = 5 * frequency(solar), seasonal = "multiplicative",
##
## Call:
## damped = TRUE)
##
## Smoothing parameters:
## alpha = 0.805
## beta = 1e-04
## gamma = 0.0124
## phi = 0.94
##
## Initial states:
## l = 9.9033
## b = 0.4703
## s = 0.4341 0.5649 0.8263 1.1716 1.4514 1.6316
## 1.5503 1.3834 1.1045 0.8837 0.5761 0.4221
##
## sigma: 0.3145
##
## AIC AICc BIC
## 6366.701 6367.768 6447.561
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0456208 2.045442 1.239102 -2.172476 10.00296 0.2035619
## ACF1
## Training set 0.04177493
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2015 5.611616 3.3502090 7.873023 2.1530925 9.070139
## Feb 2015 7.060438 3.3373603 10.783517 1.3664818 12.754395
## Mar 2015 10.515176 3.8550902 17.175263 0.3294535 20.700899
## Apr 2015 12.993446 3.5145037 22.472389 -1.5033454 27.490238
## May 2015 16.284381 2.9386340 29.630128 -4.1261776 36.694939
## Jun 2015 18.261020 1.7242212 34.797820 -7.0298315 43.551872
## Jul 2015 19.031597 0.2101276 37.853067 -9.7533565 47.816551
## Aug 2015 17.105654 -1.2074754 35.418784 -10.9018606 45.113169
## Sep 2015 13.764743 -2.0801991 29.609686 -10.4680049 37.997491
## Oct 2015 9.774733 -2.2585804 21.808047 -8.6286319 28.178099
## Nov 2015 6.581938 -2.0456267 15.209503 -6.6127835 19.776659
## Dec 2015 5.163049 -2.0168711 12.342970 -5.8176914 16.143790
## Jan 2016 5.616270 -2.6571166 13.889656 -7.0367828 18.269322
## Feb 2016 7.066360 -3.9144360 18.047156 -9.7273184 23.860039
## Mar 2016 10.524088 -6.6891829 27.737360 -15.8013383 36.849515
## Apr 2016 13.004566 -9.3405081 35.349641 -21.1692761 47.178409
## May 2016 16.298445 -13.0720043 45.668893 -28.6197807 61.216670
## Jun 2016 18.276925 -16.2140342 52.767885 -34.4724452 71.026296
## Jul 2016 19.048304 -18.5466197 56.643228 -38.4481704 76.544779
## Aug 2016 17.120781 -18.1782620 52.419825 -36.8644468 71.106009
## Sep 2016 13.777000 -15.8651593 43.419159 -31.5567705 59.110770
## Oct 2016 9.783493 -12.1627698 31.729756 -23.7804195 43.347405
## Nov 2016 6.587872 -8.8063951 21.982139 -16.9556278 30.131371
## Dec 2016 5.167730 -7.4021686 17.737629 -14.0562710 24.391731
## Jan 2017 5.621391 -8.6173336 19.860116 -16.1548593 27.397642
## Feb 2017 7.072836 -11.5506968 25.696368 -21.4093994 35.555071
## Mar 2017 10.533777 -18.2831270 39.350681 -33.5378745 54.605428
## Apr 2017 13.016590 -23.9602666 49.993446 -43.5346319 69.567811
## May 2017 16.313574 -31.7864590 64.413606 -57.2490781 89.876225
## Jun 2017 18.293954 -37.6661323 74.254041 -67.2896128 103.877522
## Jul 2017 19.066115 -41.4169669 79.549196 -73.4347761 111.567005
## Aug 2017 17.136842 -39.2196179 73.493302 -69.0529257 103.326610
## Sep 2017 13.789964 -33.2070276 60.786955 -58.0857320 85.665659
## Oct 2017 9.792726 -24.7827962 44.368248 -43.0859719 62.671423
## Nov 2017 6.594106 -17.5190371 30.707248 -30.2837638 43.471975
## Dec 2017 5.172632 -14.4124885 24.757753 -24.7802253 35.125490
## Jan 2018 5.626738 -16.4482035 27.701680 -28.1339719 39.387449
## Feb 2018 7.079578 -21.6650836 35.824241 -36.8815886 51.040745
## Mar 2018 10.543840 -33.7520469 54.839727 -57.2008731 78.288553
## Apr 2018 13.029049 -43.5957293 69.653827 -73.5710763 99.629174
## May 2018 16.329218 -57.0729428 89.731378 -95.9296992 128.588134
## Jun 2018 18.311528 -66.8108540 103.433910 -111.8719210 148.494977
## Jul 2018 19.084459 -72.6443909 110.813310 -121.2027110 159.371630
## Aug 2018 17.153356 -68.0816522 102.388364 -113.2023398 147.509051
## Sep 2018 13.803271 -57.0947408 84.701283 -94.6258813 122.232424
## Oct 2018 9.802188 -42.2336507 61.838027 -69.7797599 89.384137
## Nov 2018 6.600486 -29.6097187 42.810690 -48.7782429 61.979214
## Dec 2018 5.177643 -24.1727779 34.528064 -39.7099521 50.065238
## Jan 2019 5.632196 -27.3848682 38.649259 -44.8630460 56.127437
## Feb 2019 7.086452 -35.8304219 50.003326 -58.5492425 72.722146
## Mar 2019 10.554087 -55.4725310 76.580704 -90.4249112 111.533085
## Apr 2019 13.041723 -71.2326855 97.316131 -115.8448624 141.928308
## May 2019 16.345115 -92.7428126 125.433042 -150.4904731 183.180703
## Jun 2019 18.329369 -108.0080581 144.666797 -174.8870523 211.545791
## Jul 2019 19.103068 -116.8701338 155.076270 -188.8499990 227.056135
## Aug 2019 17.170093 -109.0302062 143.370393 -175.8366093 210.176796
## Sep 2019 13.816749 -91.0420216 118.675520 -146.5509017 174.184400
## Oct 2019 9.811766 -67.0716275 86.695159 -107.7712373 127.394768
## Nov 2019 6.606938 -46.8432208 60.057097 -75.1380259 88.351902
## Dec 2019 5.182708 -38.1032646 48.468680 -61.0174741 71.382889
checkresiduals(fit5.hw)
##
## Ljung-Box test
##
## data: Residuals from Damped Holt-Winters' multiplicative method
## Q* = 23.57, df = 7, p-value = 0.001355
##
## Model df: 17. Total lags used: 24
fit.auto.bonds = ets(solar,model="ZZZ",ic="bic")
fit.auto.bonds$method
## [1] "ETS(A,Ad,A)"
fit6 = ets(solar)
summary(fit6)
## ETS(A,Ad,A)
##
## Call:
## ets(y = solar)
##
## Smoothing parameters:
## alpha = 0.9999
## beta = 1e-04
## gamma = 1e-04
## phi = 0.9388
##
## Initial states:
## l = 11.154
## b = 0.7632
## s = -10.4919 -8.137 -3.348 2.5794 8.08 11.1219
## 9.9586 6.9916 1.9573 -1.8565 -7.1607 -9.6946
##
## sigma: 2.3446
##
## AIC AICc BIC
## 5428.422 5429.489 5509.282
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.01091357 2.314163 1.498521 -1.468083 12.44796 0.2461797
## ACF1
## Training set 0.1700724
checkresiduals(fit6)
##
## Ljung-Box test
##
## data: Residuals from ETS(A,Ad,A)
## Q* = 210.76, df = 7, p-value < 2.2e-16
##
## Model df: 17. Total lags used: 24
plot(forecast(fit5.hw$model), ylab="Solar",plot.conf=FALSE, type="l", xlab="Year", main = "Forecasting for next two years Fig 4.6")
PPI <- read_csv("data2.csv")
## Parsed with column specification:
## cols(
## Quarter = col_character(),
## price = col_double(),
## change = col_double()
## )
class(PPI)
## [1] "spec_tbl_df" "tbl_df" "tbl" "data.frame"
head(PPI)
## # A tibble: 6 x 3
## Quarter price change
## <chr> <dbl> <dbl>
## 1 Sep-2003 60.7 14017
## 2 Dec-2003 62.1 12350
## 3 Mar-2004 60.8 17894
## 4 Jun-2004 60.9 9079
## 5 Sep-2004 60.9 16210
## 6 Dec-2004 62.4 13788
Price_ts <- ts(PPI$price,start=c(2003,3),frequency = 4)
Price_ts
## Qtr1 Qtr2 Qtr3 Qtr4
## 2003 60.7 62.1
## 2004 60.8 60.9 60.9 62.4
## 2005 62.5 63.2 63.1 64.0
## 2006 65.4 67.2 68.1 69.5
## 2007 71.0 76.0 79.5 84.7
## 2008 85.7 85.5 83.0 82.3
## 2009 82.5 86.9 92.5 98.6
## 2010 103.3 106.2 104.3 105.7
## 2011 104.7 103.5 101.3 100.0
## 2012 99.4 99.3 98.6 100.4
## 2013 100.8 102.7 105.9 109.7
## 2014 110.7 112.1 113.1 115.2
## 2015 115.9 120.8 124.3 126.3
## 2016 127.3 130.7 132.9 140.0
Change_ts <- ts(PPI$change,start=c(2003,3),frequency = 4)
Change_ts
## Qtr1 Qtr2 Qtr3 Qtr4
## 2003 14017 12350
## 2004 17894 9079 16210 13788
## 2005 21195 10904 16995 16962
## 2006 25004 13059 22327 20372
## 2007 30109 19448 24993 20988
## 2008 33497 23375 30174 26736
## 2009 34387 24262 26940 20375
## 2010 25923 15929 17609 17001
## 2011 24667 17439 27892 27378
## 2012 34569 25773 29453 29174
## 2013 35704 28048 32942 29061
## 2014 37877 26282 33154 31115
## 2015 38857 27872 32948 31683
## 2016 43701 37949 32275 32703
Joint = ts.intersect(Price_ts, Change_ts)
plot(Joint, yax.flip=T, main = "Joint Fig 5.0")
ccf(as.vector(Joint[,1]), as.vector(Joint[,2]),ylab='CCF', main = "Sample CCF between Fig 5.1")
me.dif=ts.intersect(diff(diff(Price_ts,4)),diff(diff(Change_ts,4)))
prewhiten(as.vector(me.dif[,1]),as.vector(me.dif[,2]),ylab='CCF', main = "Sample CFF after prewhitening Fig 5.2")