Assignment 2 Forecasting

TASK 1

In this task we will compare all Distributed lag models,Dynamic lag models and exponential smoothing and corresponding state-space models to check the best fitting model to the series and best fit is checked using the accuracy(MASE) of model and then make the forecast of next 2 years.

Importing dataset for Task 1

Solar_data <- read_csv("/Users/shubhamchougule/Downloads/data1 (1).csv")
## Parsed with column specification:
## cols(
##   solar = col_double(),
##   ppt = col_double()
## )
#Checking the dataset
head(Solar_data)
## # 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
#Checking the class of dataset
class(Solar_data)
## [1] "spec_tbl_df" "tbl_df"      "tbl"         "data.frame"

Changing the dataset to time series

#Converting dataset to time series starting from Jan 1960
Solar<-ts(Solar_data$solar,start = 1960,frequency = 12)

PPT<-ts(Solar_data$ppt,start = 1960,frequency = 12)

Checking the existence of nonstationarity in series

For making the prediction we need to make the dataset stationary so that each point should be independent of one another. And stationarity of a series is checked using ACF and PACF plots also by conducting an ADF test. Non-stationarity can be removed by applying transformation and differencing to the series. Series can be well understood when it is decomposed using a different techniques.

Plot the time series dataset

#Plotting  Solar  series and check
plot(Solar,ylab="Monthly Average Solar Radiations",xlab="YEAR",main="Solar Radiations")

  • In solar series we do not see any trend.
  • We see seasonality in the series.
  • No intervention point is observed.
  • Moving average can be seen.
  • Changing varince can be seen.
#Plotting  precipitation series and check
plot(PPT,ylab="Monthly precipitation series measured",xlab="YEAR",main="Precipitation Series")

  • In precipitation series we do not see any trend.
  • We see seasonality in the series.
  • No intervention point is observed.
  • Moving average can be seen.
  • Changing varince can be seen.

ACF and PACF plots

#ACF and PACF plots
par(mfrow=c(2,2))
acf(Solar,main="ACF of Horizontal solar radiation")
acf(PPT,main="ACF of Precipitation series")
pacf(Solar,main="PACF of Horizontal solar radiation")
pacf(PPT,main="PACF of Precipitation series")

  • ACF plot of Solar radiation shows seasonal pattern and PACF plot shows significant lags.
  • ACF plot of Precipitation series shows seasonal pattern and PACF plot shows significant lags.

ADF test

Non-stationary can be check by adf test.

Assumptions are as follows

NULL hypothesis:

H0:Non-stationary

Alternative hypothesis:

HA:stationary

#ADF test for Solar Series
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

Augmented Dickey-Fuller Test states that solar series is stationary as we get p-value less than 5% hence rejecting null hypothesis.

#ADF test for PPT series
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

Augmented Dickey-Fuller Test states that precipitation series is stationary as we get p-value less than 5% hence rejecting null hypothesis.

Decomposition

The individual effect of the existing components and past effects can be analyzed by using the decomposition technique. For decomposition, we will use the X12-ARIMA decomposition method as we will check STL decomposition.

#Decomposition function giving output decomposed series, SI ratio plot and STL plot.

decompose <- function(x){
  DECOM = x12(x)
  plot(DECOM, sa=TRUE , trend=TRUE , forecast = TRUE)
  
  plotSeasFac(DECOM)
  
  stldec=stl(x, t.window=15, s.window="periodic", robust=TRUE)
  plot(stldec)
}

#decomposition
decompose(Solar)

  • We can observe seasonally adjusted series does not follows original series in the same pattern. which states that there is seasonal effect affecting the series. The trend looks following the original series hence can say that trend has no effect on the series. We can also see the forecast.

  • We See that seasonal factors are clustered around the mean for most of the months.

  • STL first graph shows the original series, the seasonal pattern are same says seasonality. The trend graph shows no any upward or downward fall and hence do not see a trend.

Distributed Lag Model

To check amoung the Distributed Lag Model which best fits the data based on the AIC and MASE scores. The model we are going to fit are ;

  1. Finite Distributed-Lag Model,
  2. Polynomial Distributed Lags
  3. Koyck Distributed Lag Model
  4. Autoregressive Distributed Lag Mode

Finite Distributed-Lag Model

#selection of "q" value on basis of AIC and BIC for fitting of DLM model
for(i in 1:10){
  model1 = dlm( x = as.vector(PPT) , y = as.vector(Solar), q = i )
  cat("q = ", i, "AIC = ", AIC(model1$model), "BIC = ", BIC(model1$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

Lowest value of AIC and BIC is observed when q=10 hence using this vales for DLM model.

model1<- dlm(x = as.vector(PPT) , y = as.vector(Solar), q = 10)
summary(model1)
## 
## 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(model1$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
  • The summary express that one of the lag is significant.
  • Adj R-squared value is very low
  • In Breusch-Godfrey test we see value is less than 5% states that there is a serial correlation. * From the ACF plot we conclude that residuals are highly significant.Hence violate general assumptions.
vif(model1$model)#states multicollinerity
##      x.t      x.1      x.2      x.3      x.4      x.5      x.6      x.7 
## 4.244594 7.665259 7.910115 7.952633 7.957841 7.941836 7.911213 7.901898 
##      x.8      x.9     x.10 
## 7.847965 7.653512 4.228221

We see all the values are less than 10 hence there does not exist multicollinerity.

Polynomial Distributed Lag Model

model2 = polyDlm(x = as.vector(PPT) , y = as.vector(Solar) , q = 2 , k = 2 , show.beta = TRUE)
## Estimates and t-tests for beta coefficients:
##        Estimate Std. Error t value  P(>|t|)
## beta.0   -12.90       1.76   -7.37 5.32e-13
## beta.1    -2.59       2.56   -1.01 3.12e-01
## beta.2     5.83       1.75    3.33 9.06e-04
summary(model2)
## 
## Call:
## "Y ~ (Intercept) + X.t"
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -17.481  -5.773  -0.921   4.576  31.726 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  22.3441     0.6374  35.054  < 2e-16 ***
## z.t0        -12.9460     1.7577  -7.366 5.33e-13 ***
## z.t1         11.3215     8.0564   1.405    0.160    
## z.t2         -0.9659     4.0021  -0.241    0.809    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.65 on 654 degrees of freedom
## Multiple R-squared:  0.2253, Adjusted R-squared:  0.2217 
## F-statistic: 63.39 on 3 and 654 DF,  p-value: < 2.2e-16
checkresiduals(model2$model)

## 
##  Breusch-Godfrey test for serial correlation of order up to 10
## 
## data:  Residuals
## LM test = 577.49, df = 10, p-value < 2.2e-16
  • The summary express that one of the lag is significant.
  • Adj R-squared value is very low
  • In Breusch-Godfrey test we see value is less than 5% states that there is a serial correlation. * From the ACF plot we conclude that residuals are highly significant.Hence violate general assumptions.
vif(model2$model)
##      z.t0      z.t1      z.t2 
##  23.71744 583.13654 412.20072

Above all the values are higher than 10 and there exist of multicollinerity.

Koyck Distributed Lag Model

model3 = koyckDlm(x = as.vector(PPT) , y = as.vector(Solar))
summary(model3,diagnostics=TRUE)
## 
## 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 
## 
## Diagnostic tests:
##                  df1 df2 statistic       p-value
## Weak instruments   1 656  710.7209 1.191744e-106
## Wu-Hausman         1 655  146.8017  1.248856e-30
## 
##                              alpha     beta       phi
## Geometric coefficients:  -154.0203 5.346844 0.9854613
checkresiduals(model3$model)

  • The summary express that all of the lags are significant.
  • Adj R-squared value also good.
  • In Breusch-Godfrey test we see value is less than 5% states that there is a serial correlation. * From the ACF plot we conclude that residuals are highly significant.Hence violate general assumptions.

We will check the multicollinerity.

vif(model3$model)
##      Y.1      X.t 
## 1.605001 1.605001

Here we have values less than 10 confirming of no multicollinerity.

Autorregressive Distributed Lag Model

#Checking p and q vales on basis fo AIC and BIC 
for (i in 1:10){
  for(j in 1:10){
    model4 = ardlDlm(x = as.vector(PPT) , y = as.vector(Solar), p = i , q = j )
    cat("p = ", i, "q = ", j, "AIC = ", AIC(model4$model), "BIC = ", BIC(model4$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 =  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 =  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 =  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 =  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 =  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 =  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 =  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 =  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 =  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

We choose p=1 and q=5 because for this p and q values AIC and BIC are the least using same in the model.

model4 = ardlDlm(x = as.vector(PPT) , y = as.vector(Solar), p = 9 , q = 7 )
summary(model4)
## 
## Time series regression with "ts" data:
## Start = 10, End = 660
## 
## Call:
## dynlm(formula = as.formula(model.text), data = data, start = 1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -13.2222  -1.2151  -0.1015   0.9864  18.0325 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.54522    0.47727   3.238 0.001268 ** 
## X.t          0.03524    0.53121   0.066 0.947126    
## X.1          0.52602    0.72140   0.729 0.466169    
## X.2          0.93915    0.72929   1.288 0.198300    
## X.3          0.88547    0.73212   1.209 0.226938    
## X.4         -1.07437    0.73290  -1.466 0.143168    
## X.5          0.05236    0.73419   0.071 0.943168    
## X.6         -2.22446    0.73342  -3.033 0.002520 ** 
## X.7          2.42465    0.73506   3.299 0.001026 ** 
## X.8          0.79521    0.73160   1.087 0.277480    
## X.9         -2.14299    0.52580  -4.076 5.17e-05 ***
## Y.1          1.14197    0.03892  29.345  < 2e-16 ***
## Y.2          0.09977    0.05946   1.678 0.093864 .  
## Y.3         -0.24990    0.05843  -4.277 2.19e-05 ***
## Y.4         -0.18084    0.05849  -3.092 0.002077 ** 
## Y.5         -0.18410    0.05821  -3.163 0.001637 ** 
## Y.6          0.13933    0.05869   2.374 0.017889 *  
## Y.7          0.14187    0.03884   3.652 0.000281 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.337 on 633 degrees of freedom
## Multiple R-squared:  0.9451, Adjusted R-squared:  0.9436 
## F-statistic: 640.5 on 17 and 633 DF,  p-value: < 2.2e-16
checkresiduals(model4$model)

## 
##  Breusch-Godfrey test for serial correlation of order up to 21
## 
## data:  Residuals
## LM test = 86.329, df = 21, p-value = 6.885e-10
  • The summary express that almost all of the lags are significant.
  • Adj R-squared value is very high.
  • In Breusch-Godfrey test we see value is less than 5% states that there is a serial correlation. * From the ACF plot we conclude that residuals are not highly significant.Hence see histogram is normalized.

We will check the multicollinerity.

vif(model4$model)
##       X.t L(X.t, 1) L(X.t, 2) L(X.t, 3) L(X.t, 4) L(X.t, 5) L(X.t, 6) L(X.t, 7) 
##  4.192098  7.760879  7.946151  8.013082  8.016774  8.024377  7.990709  8.031374 
## L(X.t, 8) L(X.t, 9) L(y.t, 1) L(y.t, 2) L(y.t, 3) L(y.t, 4) L(y.t, 5) L(y.t, 6) 
##  7.975689  4.151762 17.405503 40.570447 39.180158 39.291729 38.935939 39.584029 
## L(y.t, 7) 
## 17.352708

Here we have some values are less than 10 some are greater than 10 confirming of some existance of multicollinerity in the series.

Comparision of DLM models

DLM models based on the MASE value. Lower the MASE value better the forecast. From the values we see that Autorregressive Distributed Lag Model has the lowest MASE value and hence could be used for prediction.

mas =MASE(model1, model2, model3, model4)
mas
##          n      MASE
## model1 650 1.5779955
## model2 658 1.6759667
## model3 659 1.0324829
## model4 651 0.4038376

Dynamic Lag Models

Dynamic Lag models are created using Y lag, step function,Intevention point, trend and seasonality. Best model is selected by adding and removing different points. Best model with lowest AIC and accuracy(MASE) values will be selected.

From the observations we can see that * Almost all of the models lags are significant. * Have high Adj. R-square value. * Most of models AIC lags are significant. * Histogram is normalized.

#Considerations for Dynlm models
Y.t=Solar
X.t=PPT
#Model 1
dynlm1 =dynlm(Y.t~ L(Y.t , k = 1 )+ trend(Y.t)+ season(Y.t))
summary(dynlm1)
## 
## Time series regression with "ts" data:
## Start = 1960(2), End = 2014(12)
## 
## Call:
## dynlm(formula = Y.t ~ L(Y.t, k = 1) + trend(Y.t) + season(Y.t))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.8501 -0.9906 -0.1119  0.8325 16.8276 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     1.2105921  0.3640843   3.325 0.000934 ***
## L(Y.t, k = 1)   0.9323820  0.0142258  65.542  < 2e-16 ***
## trend(Y.t)     -0.0006813  0.0056406  -0.121 0.903905    
## season(Y.t)Feb  1.9262673  0.4397952   4.380 1.39e-05 ***
## season(Y.t)Mar  4.8864291  0.4420720  11.053  < 2e-16 ***
## season(Y.t)Apr  3.7894322  0.4563152   8.304 5.90e-16 ***
## season(Y.t)May  5.1503064  0.4741868  10.861  < 2e-16 ***
## season(Y.t)Jun  3.3685316  0.5051379   6.669 5.56e-11 ***
## season(Y.t)Jul  1.6296826  0.5265113   3.095 0.002052 ** 
## season(Y.t)Aug -2.1600321  0.5340317  -4.045 5.87e-05 ***
## season(Y.t)Sep -4.7002552  0.5116903  -9.186  < 2e-16 ***
## season(Y.t)Oct -5.8121501  0.4778130 -12.164  < 2e-16 ***
## season(Y.t)Nov -5.0968011  0.4512694 -11.294  < 2e-16 ***
## season(Y.t)Dec -2.8325126  0.4408651  -6.425 2.56e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.295 on 645 degrees of freedom
## Multiple R-squared:  0.9463, Adjusted R-squared:  0.9452 
## F-statistic: 874.6 on 13 and 645 DF,  p-value: < 2.2e-16
checkresiduals(dynlm1)

## 
##  Breusch-Godfrey test for serial correlation of order up to 24
## 
## data:  Residuals
## LM test = 132.86, df = 24, p-value < 2.2e-16
dynlm2=dynlm(Y.t~ L(Y.t , k = 2)+X.t+ trend(Y.t)+ season(Y.t))
summary(dynlm2)
## 
## Time series regression with "ts" data:
## Start = 1960(3), End = 2014(12)
## 
## Call:
## dynlm(formula = Y.t ~ L(Y.t, k = 2) + X.t + trend(Y.t) + season(Y.t))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.1731  -1.5067  -0.2347   1.2121  16.5670 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     0.182851   0.660844   0.277  0.78210    
## L(Y.t, k = 2)   0.840701   0.021317  39.438  < 2e-16 ***
## X.t            -0.307827   0.497183  -0.619  0.53604    
## trend(Y.t)     -0.001325   0.008470  -0.156  0.87575    
## season(Y.t)Feb  4.511375   0.664449   6.790 2.56e-11 ***
## season(Y.t)Mar  9.252790   0.661321  13.991  < 2e-16 ***
## season(Y.t)Apr 10.985633   0.660987  16.620  < 2e-16 ***
## season(Y.t)May 11.444854   0.679797  16.836  < 2e-16 ***
## season(Y.t)Jun 10.976631   0.724089  15.159  < 2e-16 ***
## season(Y.t)Jul  7.679590   0.781420   9.828  < 2e-16 ***
## season(Y.t)Aug  2.343898   0.811719   2.888  0.00401 ** 
## season(Y.t)Sep -3.679474   0.809213  -4.547 6.50e-06 ***
## season(Y.t)Oct -7.154745   0.748818  -9.555  < 2e-16 ***
## season(Y.t)Nov -7.569350   0.697556 -10.851  < 2e-16 ***
## season(Y.t)Dec -4.765167   0.668226  -7.131 2.69e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.435 on 643 degrees of freedom
## Multiple R-squared:  0.8799, Adjusted R-squared:  0.8772 
## F-statistic: 336.4 on 14 and 643 DF,  p-value: < 2.2e-16
checkresiduals(dynlm2)

## 
##  Breusch-Godfrey test for serial correlation of order up to 24
## 
## data:  Residuals
## LM test = 421.48, df = 24, p-value < 2.2e-16
dynlm3 =dynlm(Y.t~ L(Y.t , k = 1 )+X.t+ season(Y.t))
summary(dynlm3)
## 
## Time series regression with "ts" data:
## Start = 1960(2), End = 2014(12)
## 
## Call:
## dynlm(formula = Y.t ~ L(Y.t, k = 1) + X.t + season(Y.t))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.7834 -1.0052 -0.0964  0.8024 16.8758 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     1.36184    0.40650   3.350 0.000855 ***
## L(Y.t, k = 1)   0.93192    0.01423  65.471  < 2e-16 ***
## X.t            -0.23642    0.33142  -0.713 0.475877    
## season(Y.t)Feb  1.90792    0.44040   4.332 1.71e-05 ***
## season(Y.t)Mar  4.86290    0.44315  10.973  < 2e-16 ***
## season(Y.t)Apr  3.76530    0.45742   8.232 1.02e-15 ***
## season(Y.t)May  5.10305    0.47866  10.661  < 2e-16 ***
## season(Y.t)Jun  3.27202    0.52284   6.258 7.10e-10 ***
## season(Y.t)Jul  1.50367    0.55526   2.708 0.006947 ** 
## season(Y.t)Aug -2.29117    0.56467  -4.058 5.57e-05 ***
## season(Y.t)Sep -4.81495    0.53621  -8.980  < 2e-16 ***
## season(Y.t)Oct -5.86148    0.48261 -12.145  < 2e-16 ***
## season(Y.t)Nov -5.10509    0.45124 -11.313  < 2e-16 ***
## season(Y.t)Dec -2.80858    0.44199  -6.354 3.96e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.294 on 645 degrees of freedom
## Multiple R-squared:  0.9464, Adjusted R-squared:  0.9453 
## F-statistic: 875.3 on 13 and 645 DF,  p-value: < 2.2e-16
checkresiduals(dynlm3)

## 
##  Breusch-Godfrey test for serial correlation of order up to 24
## 
## data:  Residuals
## LM test = 134.42, df = 24, p-value < 2.2e-16
dynlm4=dynlm(Y.t~ L(Y.t , k = 1 )+X.t+trend(Y.t))
summary(dynlm4)
## 
## Time series regression with "ts" data:
## Start = 1960(2), End = 2014(12)
## 
## Call:
## dynlm(formula = Y.t ~ L(Y.t, k = 1) + X.t + trend(Y.t))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.4925 -3.7427  0.2951  3.4114 16.6215 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    2.476695   0.634917   3.901 0.000106 ***
## L(Y.t, k = 1)  0.881095   0.020313  43.376  < 2e-16 ***
## X.t           -0.572126   0.563644  -1.015 0.310458    
## trend(Y.t)    -0.003331   0.010958  -0.304 0.761238    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.456 on 655 degrees of freedom
## Multiple R-squared:  0.7945, Adjusted R-squared:  0.7936 
## F-statistic: 844.3 on 3 and 655 DF,  p-value: < 2.2e-16
checkresiduals(dynlm4)

## 
##  Breusch-Godfrey test for serial correlation of order up to 24
## 
## data:  Residuals
## LM test = 493.18, df = 24, p-value < 2.2e-16
dynlm5 =dynlm(Y.t~ L(Y.t , k = 1 )+L(Y.t , k = 2) +X.t +season(Y.t))
summary(dynlm5)
## 
## Time series regression with "ts" data:
## Start = 1960(3), End = 2014(12)
## 
## Call:
## dynlm(formula = Y.t ~ L(Y.t, k = 1) + L(Y.t, k = 2) + X.t + season(Y.t))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -13.1353  -0.9959  -0.0915   0.8252  17.0059 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     1.97079    0.41260   4.777 2.21e-06 ***
## L(Y.t, k = 1)   1.13172    0.03849  29.400  < 2e-16 ***
## L(Y.t, k = 2)  -0.21447    0.03850  -5.571 3.72e-08 ***
## X.t            -0.24527    0.32442  -0.756  0.44990    
## season(Y.t)Feb  1.29901    0.44752   2.903  0.00383 ** 
## season(Y.t)Mar  3.86196    0.46925   8.230 1.04e-15 ***
## season(Y.t)Apr  2.24539    0.52418   4.284 2.12e-05 ***
## season(Y.t)May  3.95247    0.51194   7.721 4.45e-14 ***
## season(Y.t)Jun  1.95757    0.56368   3.473  0.00055 ***
## season(Y.t)Jul  0.68494    0.56305   1.216  0.22425    
## season(Y.t)Aug -2.68154    0.55699  -4.814 1.84e-06 ***
## season(Y.t)Sep -4.42079    0.52910  -8.355 4.02e-16 ***
## season(Y.t)Oct -5.03914    0.49435 -10.194  < 2e-16 ***
## season(Y.t)Nov -4.20687    0.46974  -8.956  < 2e-16 ***
## season(Y.t)Dec -2.22125    0.44494  -4.992 7.70e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.244 on 643 degrees of freedom
## Multiple R-squared:  0.9488, Adjusted R-squared:  0.9476 
## F-statistic: 850.2 on 14 and 643 DF,  p-value: < 2.2e-16
checkresiduals(dynlm5)

## 
##  Breusch-Godfrey test for serial correlation of order up to 24
## 
## data:  Residuals
## LM test = 109.78, df = 24, p-value = 6.162e-13
dynlm6 =dynlm(Y.t~ L(Y.t , k = 1 )+ L(Y.t , k = 2 )+L(Y.t , k = 3 )+X.t +season(Y.t))
summary(dynlm6)
## 
## Time series regression with "ts" data:
## Start = 1960(4), End = 2014(12)
## 
## Call:
## dynlm(formula = Y.t ~ L(Y.t, k = 1) + L(Y.t, k = 2) + L(Y.t, 
##     k = 3) + X.t + season(Y.t))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.8910  -0.9667  -0.1398   0.8091  17.1517 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     3.54381    0.44657   7.936 9.37e-15 ***
## L(Y.t, k = 1)   1.06952    0.03780  28.293  < 2e-16 ***
## L(Y.t, k = 2)   0.11225    0.05653   1.986   0.0475 *  
## L(Y.t, k = 3)  -0.28856    0.03784  -7.626 8.78e-14 ***
## X.t            -0.33681    0.31173  -1.080   0.2803    
## season(Y.t)Feb  0.66860    0.43705   1.530   0.1266    
## season(Y.t)Mar  2.51605    0.48637   5.173 3.08e-07 ***
## season(Y.t)Apr  0.57076    0.54877   1.040   0.2987    
## season(Y.t)May  1.50248    0.58710   2.559   0.0107 *  
## season(Y.t)Jun  0.07092    0.59503   0.119   0.9052    
## season(Y.t)Jul -1.54179    0.61454  -2.509   0.0124 *  
## season(Y.t)Aug -4.34971    0.57777  -7.528 1.75e-13 ***
## season(Y.t)Sep -5.74108    0.53646 -10.702  < 2e-16 ***
## season(Y.t)Oct -5.43685    0.47694 -11.399  < 2e-16 ***
## season(Y.t)Nov -4.08468    0.45070  -9.063  < 2e-16 ***
## season(Y.t)Dec -1.94202    0.42823  -4.535 6.88e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.151 on 641 degrees of freedom
## Multiple R-squared:  0.953,  Adjusted R-squared:  0.9519 
## F-statistic: 866.3 on 15 and 641 DF,  p-value: < 2.2e-16
checkresiduals(dynlm6)

## 
##  Breusch-Godfrey test for serial correlation of order up to 24
## 
## data:  Residuals
## LM test = 58.344, df = 24, p-value = 0.000109

Comparision of Dynamic lag models

Comparision is done based on AIC and MASE value.

aic =AIC(dynlm1, dynlm2, dynlm3, dynlm4, dynlm5,dynlm6)
cbind(Model=c("Dynlm1","Dynlm2","Dynlm3","Dynlm4","Dynlm5","Dynlm6"),
      MASE=c(accuracy(dynlm1)[6],accuracy(dynlm2)[6],accuracy(dynlm3)[6],accuracy(dynlm4)[6],
             accuracy(dynlm5)[6],accuracy(dynlm6)[6]),aic)
##         Model      MASE df      AIC
## dynlm1 Dynlm1 0.3743356 15 2981.018
## dynlm2 Dynlm2 0.5868963 16 3508.219
## dynlm3 Dynlm3 0.3739879 15 2980.514
## dynlm4 Dynlm4 0.9717761  5 3845.485
## dynlm5 Dynlm5 0.3632657 16 2947.658
## dynlm6 Dynlm6 0.3520468 17 2888.991

From the resulting values, we can see that  dynlm6 has the lowest AIC and MASE values hence dynlm6 is used for forecasting.

Exponential Smoothing Method

1.Seasonality=Additive,damped=False 2.Seasonality=Additive,damped=True 3.Seasonality=multiplicative,damped=False 4.Seasonality=multiplicative,damped=True 5.Seasonality=multiplicative,damped=False,Exponential =True

#Holt’s-Winter model 1
hw1 <- hw(Solar,seasonal="additive",h=5*frequency(Solar))
summary(hw1)
## 
## 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      ACF1
## Training set -0.1179476 2.328736 1.504489 -2.230359 12.68101 0.24716 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(hw1)

## 
##  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
#Holt’s-Winter model 2
hw2 <- hw(Solar,seasonal="multiplicative", h=5*frequency(Solar))
summary(hw2)
## 
## Forecast method: Holt-Winters' multiplicative method
## 
## Model Information:
## Holt-Winters' multiplicative method 
## 
## Call:
##  hw(y = Solar, h = 5 * 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.61033488    2.75534413   8.465326    1.2440033   9.976666
## Feb 2015     6.51280609    2.03809262  10.987520   -0.3306776  13.356290
## Mar 2015     8.78611971    1.33667747  16.235562   -2.6068190  20.179058
## Apr 2015    10.19278453   -0.02672876  20.412298   -5.4366123  25.822181
## May 2015    12.51259660   -1.96157245  26.986766   -9.6237347  34.648928
## Jun 2015    14.06160944   -4.41048190  32.533701  -14.1890164  42.312235
## Jul 2015    14.50208797   -6.89909775  35.903274  -18.2282011  47.232377
## Aug 2015    12.94562026   -8.35024040  34.241481  -19.6235881  45.514829
## Sep 2015    10.35221007   -8.52365174  29.228072  -18.5159294  39.220350
## Oct 2015     7.41827945   -7.51119146  22.347750  -15.4143760  30.250935
## Nov 2015     4.98972975   -6.05900058  16.038460  -11.9078451  21.887305
## Dec 2015     3.87177644   -5.53876625  13.282319  -10.5204066  18.263960
## Jan 2016     4.19940009   -7.01753622  15.416336  -12.9554236  21.354224
## Feb 2016     4.83889159   -9.30305408  18.980837  -16.7893479  26.467131
## Mar 2016     6.47717405  -14.21845674  27.172805  -25.1740619  38.128410
## Apr 2016     7.45263289  -18.56883703  33.474103  -32.3437711  47.249037
## May 2016     9.06974859  -25.52978297  43.669280  -43.8456686  61.985166
## Jun 2016    10.09948524  -31.99838423  52.197355  -54.2836502  74.482621
## Jul 2016    10.31519859  -36.68017471  57.310572  -61.5580226  82.188420
## Aug 2016     9.11376538  -36.29212001  54.519651  -60.3285438  78.556075
## Sep 2016     7.20870003  -32.09306283  46.510463  -52.8981594  67.315559
## Oct 2016     5.10586905  -25.38360449  35.595343  -41.5237568  51.735495
## Nov 2016     3.39194526  -18.81647619  25.600367  -30.5729044  37.356795
## Dec 2016     2.59725607  -16.07148862  21.266001  -25.9541251  31.148637
## Jan 2017     2.78373153  -19.21776020  24.785223  -30.8646464  36.432109
## Feb 2017     3.15936030  -24.33037133  30.649092  -38.8825562  45.201277
## Mar 2017     4.16047976  -35.76625931  44.087219  -56.9021982  65.223158
## Apr 2017     4.70328433  -45.18192233  54.588491  -71.5895556  80.996124
## May 2017     5.61534367  -60.36391809  71.594605  -95.2912295 106.521917
## Jun 2017     6.12405932  -73.79768601  86.045805 -116.1057024 128.353821
## Jul 2017     6.11425109  -82.77279348  95.001296 -129.8267526 142.055255
## Aug 2017     5.26904280  -80.34316326  90.881249 -125.6635275 136.201613
## Sep 2017     4.05463246  -69.85419810  77.963463 -108.9791696 117.088435
## Oct 2017     2.78569137  -54.42552114  59.996904  -84.7113076  90.282690
## Nov 2017     1.78879320  -39.80734935  43.384936  -61.8270171  65.404604
## Dec 2017     1.31845355  -33.59456540  36.231473  -52.0764012  54.713308
## Jan 2018     1.36330608  -39.72863165  42.455244  -61.4813895  64.208002
## Feb 2018     1.47418475  -49.81449186  52.762861  -76.9650772  79.913447
## Mar 2018     1.83599894  -72.59270008  76.264698 -111.9928734 115.664871
## Apr 2018     1.94469388  -90.98201645  94.871404 -140.1744454 144.063833
## May 2018     2.14932535 -120.68632438 124.984975 -185.7115895 190.010240
## Jun 2018     2.13526664 -146.58736982 150.857903 -225.3163779 229.586911
## Jul 2018     1.89917673 -163.44351234 167.241866 -250.9706448 254.768998
## Aug 2018     1.41138961 -157.79092639 160.613706 -242.0675417 244.890321
## Sep 2018     0.88995573 -136.51563431 138.295546 -209.2537599 211.033671
## Oct 2018     0.45770844 -105.88461019 106.800027 -162.1788332 163.094250
## Nov 2018     0.18024733  -77.12580421  77.486299 -118.0491559 118.409651
## Dec 2018     0.03534794  -64.84280988  64.913506  -99.1872320  99.257928
## Jan 2019    -0.06189953  -76.41489903  76.291100 -116.8337354 116.709936
## Feb 2019    -0.21666264  -95.51037879  95.077054 -145.9558249 145.522500
## Mar 2019    -0.49630645 -138.77793993 137.785327 -211.9798149 210.987202
## Apr 2019    -0.82318361 -173.46750956 171.821142 -264.8598951 263.213528
## May 2019    -1.32836314 -229.53530386 226.878578 -350.3407610 347.684035
## Jun 2019    -1.86695811 -278.16514909 274.431233 -424.4285763 420.694660
## Jul 2019    -2.33009351 -309.50479272 304.844606 -472.1132561 467.453069
## Aug 2019    -2.45925738 -298.22745626 293.308942 -454.7976831 449.879168
## Sep 2019    -2.28538200 -257.56121126 252.990447 -392.6960724 388.125308
## Oct 2019    -1.87811787 -199.44569116 195.689455 -304.0316469 300.275411
## Nov 2019    -1.43371871 -145.05801838 142.190581 -221.0881300 218.220693
## Dec 2019    -1.25208177 -121.78846690 119.284303 -185.5965748 183.092411
checkresiduals(hw2)

## 
##  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
#Holt’s-Winter model 3
hw3 <- hw(Solar,seasonal="additive",damped = TRUE, h=5*frequency(Solar))
summary(hw3)
## 
## 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(hw3)

## 
##  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
#Holt’s-Winter model 4
hw4 <- hw(Solar,seasonal="multiplicative",damped = TRUE, h=5*frequency(Solar))
summary(hw4)
## 
## 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(hw4)

## 
##  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
#Holt’s-Winter model 5
hw5 <- hw(Solar,seasonal="multiplicative",exponential = TRUE, h=5*frequency(Solar))
summary(hw5)
## 
## 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     ACF1
## Training set 0.06388152 2.208727 1.412454 -1.303792 11.28449 0.2320404 0.153871
## 
## Forecasts:
##          Point Forecast      Lo 80     Hi 80       Lo 95    Hi 95
## Jan 2015       5.797870 3.01983746  8.528547 1.470742117 10.13384
## Feb 2015       7.513359 3.35093186 11.958387 1.669164907 15.05970
## Mar 2015      10.758212 4.34904221 18.297449 2.347809834 24.17894
## Apr 2015      12.694087 4.65323658 22.808540 2.347735124 31.90351
## May 2015      15.340074 4.81477307 28.540756 2.321491741 40.93178
## Jun 2015      17.239431 5.01664783 33.079309 2.453263277 48.88778
## Jul 2015      18.004700 4.82553668 35.341362 2.243021374 55.18168
## Aug 2015      16.206596 4.02605236 32.604057 1.920948848 51.48505
## Sep 2015      13.011256 2.97147232 26.579891 1.292371882 44.98912
## Oct 2015       9.215869 1.95215295 19.034742 0.838474570 31.74227
## Nov 2015       6.214762 1.19746333 12.892833 0.512640464 23.19036
## Dec 2015       4.565667 0.85024036  9.492378 0.348075549 16.87388
## Jan 2016       5.220661 0.83692446 11.235257 0.336724552 20.37616
## Feb 2016       6.765364 1.02974380 14.394190 0.411886002 26.79793
## Mar 2016       9.687175 1.33247389 21.053024 0.506153874 40.56392
## Apr 2016      11.430324 1.53184698 24.613082 0.632220799 47.93269
## May 2016      13.812889 1.62284016 30.816119 0.643394316 61.43697
## Jun 2016      15.523155 1.80159659 34.459063 0.658967237 69.58234
## Jul 2016      16.212237 1.74468503 37.192598 0.682006550 74.79569
## Aug 2016      14.593143 1.43983772 32.651159 0.518788411 71.34345
## Sep 2016      11.715916 1.09106830 26.703472 0.370476001 59.50976
## Oct 2016       8.298381 0.70151135 19.033768 0.211330837 43.55793
## Nov 2016       5.596049 0.45540410 13.253214 0.153663969 30.99148
## Dec 2016       4.111130 0.30766290  9.563693 0.092324269 23.14326
## Jan 2017       4.700916 0.32795798 11.333354 0.105886969 26.25831
## Feb 2017       6.091836 0.37812454 14.774991 0.119789578 36.84959
## Mar 2017       8.722765 0.52468787 20.642138 0.163705449 51.79812
## Apr 2017      10.292374 0.58847686 23.634147 0.169517718 61.38132
## May 2017      12.437743 0.65022471 29.005789 0.164804185 77.67039
## Jun 2017      13.977742 0.68648273 32.448641 0.192749452 86.11528
## Jul 2017      14.598223 0.70112662 33.777933 0.185905463 96.49645
## Aug 2017      13.140319 0.55528477 30.785062 0.156924491 82.45802
## Sep 2017      10.549535 0.43434155 24.481567 0.115703477 70.57232
## Oct 2017       7.472233 0.28964367 17.518987 0.078300908 51.17181
## Nov 2017       5.038933 0.18937631 11.965186 0.045185455 34.23835
## Dec 2017       3.701845 0.12535643  8.689323 0.031861801 24.38203
## Jan 2018       4.232915 0.13714207  9.727921 0.034886237 29.65742
## Feb 2018       5.485362 0.16591746 12.492215 0.045352775 38.90172
## Mar 2018       7.854368 0.22507169 18.415839 0.065025499 55.82959
## Apr 2018       9.267714 0.24633782 21.212573 0.064730761 64.75081
## May 2018      11.199499 0.27552782 25.972435 0.074885645 82.41732
## Jun 2018      12.586184 0.31189185 30.443198 0.076849065 88.66050
## Jul 2018      13.144893 0.31699650 30.783235 0.081303478 94.05588
## Aug 2018      11.832130 0.25088341 27.587627 0.063639693 83.65822
## Sep 2018       9.499273 0.19244843 22.384007 0.049840255 66.73504
## Oct 2018       6.728333 0.13023870 15.584172 0.030674417 49.53922
## Nov 2018       4.537281 0.08535751 10.241058 0.018211279 34.95690
## Dec 2018       3.333307 0.05760253  7.435154 0.014534413 24.76757
## Jan 2019       3.811506 0.06237475  8.345845 0.013607209 29.06785
## Feb 2019       4.939265 0.07983718 10.612912 0.018573250 35.71379
## Mar 2019       7.072424 0.10239469 14.918407 0.023220528 51.75997
## Apr 2019       8.345064 0.11734104 17.562713 0.025365127 64.11096
## May 2019      10.084530 0.12903708 21.939933 0.030918208 74.26760
## Jun 2019      11.333163 0.14366914 23.447829 0.029811663 83.28289
## Jul 2019      11.836249 0.13756828 24.364695 0.032376565 93.12558
## Aug 2019      10.654179 0.11786073 22.658772 0.025664233 78.10276
## Sep 2019       8.553570 0.08645611 17.294352 0.019388425 65.34651
## Oct 2019       6.058491 0.05976678 12.283953 0.012785440 45.32868
## Nov 2019       4.085570 0.03774909  7.939158 0.007373460 31.17401
## Dec 2019       3.001459 0.02612405  5.906397 0.005672383 21.76737
checkresiduals(hw5)

## 
##  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
cbind(Model=c("HW1","HW2","HW3","HW4","HW5"),
      MASE=c(accuracy(hw1)[6],accuracy(hw2)[6],accuracy(hw3)[6],
             accuracy(hw4)[6],accuracy(hw5)[6]))
##      Model MASE               
## [1,] "HW1" "0.247160046952369"
## [2,] "HW2" "0.223307745945573"
## [3,] "HW3" "0.246179687973231"
## [4,] "HW4" "0.203561894680514"
## [5,] "HW5" "0.23204037862927"

By comparing Holt’s-Winter models we can say that:

Hence HW4 is the best fitting model of the Holt’s-Winter method.

State-space model

The state-space model considers error, trend, and seasonality of the series denoted by (E, T, S). Here we will check automatically which model best fits by using the following code.

ssm1 = ets(Solar,model ="ZZZ")
ssm1$method
## [1] "ETS(A,Ad,A)"

We see that “ETS(A,Ad,A)” best fits the series then checking the summary of “ETS(A,Ad,A)”.

  • RMSE is 2.324
  • AIC and BIC are 5428.422 & 5509.282.
  • MASE is 0.246
summary(ssm1)     
## ETS(A,Ad,A) 
## 
## Call:
##  ets(y = Solar, model = "ZZZ") 
## 
##   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

Forecasting of 2 years

#forecasting dataset
data.x <- read_csv("/Users/shubhamchougule/Downloads/data.x.csv")
## Parsed with column specification:
## cols(
##   x = col_double()
## )
forecast_ts=ts(data.x)

dlmfore = forecast(model4, x = as.vector(forecast_ts) , h = 24)$forecasts
hwforecast=hw4$mean


etsforecast = as.vector(forecast(ssm1,h=24)$mean)

#Dynlm model forecasting
q = 24
n = nrow(dynlm6$model)
landings.frc = array(NA , (n + q))
landings.frc[1:n] = Y.t[1:length(Y.t)]

for (i in 1:q){
  months = array(0,11)
  months[(i-1)%%12] = 1
  data.new = c(1,landings.frc[n-1+i],landings.frc[n-2+i],landings.frc[n-3+i],1,months)
  landings.frc[n+i] = as.vector(dynlm6$coefficients) %*% data.new
}
dlm = c(Solar,dlmfore)
ets = c(Solar,etsforecast)
hw=c(Solar,hwforecast)
dynlm_forecast=ts(landings.frc[(n+1):(n+q)],start=c(2014,1),frequency = 12)

Dataforecast = ts.intersect(
  ts(dlm,start=c(1960,1),frequency = 12),
  ts(landings.frc[(n+1):(n+q)],start=c(2015,1),frequency = 12),
  ts(hw,start=c(1960,1),frequency = 12),
  ts(ets,start=c(1960,1),frequency = 12)
  
)

ts.plot(Dataforecast,xlim=c(2015,2017),ylim=c(-30,70),
        plot.type = c("single"),  gpars= list(col=c("red","blue","gray","green")),
        main = "Forecasting of next 2 years of Solar Radiations")

legend("bottomleft", col=c("red","blue","gray","green"), lty=1, cex=.65,c("DLM","DYNLM","HW","ETS"))

Conclusion

Based on the MASE value, we can say that HW6 of Holts winter method in Exponential smoothening techniques is the best fitting model to the solar series after comparing different models of the dynamic lag model, distributed lag model, exponential smoothing, and corresponding state-space models.

Task 2

Here we will investigate if there is correlation between quarterly Residential Property Price Index (PPI) in Melbourne and quarterly population change over the previous quarter in Victoria these two series is spurious or not.

#Importing the dataset
task2 <- read_csv("/Users/shubhamchougule/Downloads/data2.csv")
## Parsed with column specification:
## cols(
##   Quarter = col_character(),
##   price = col_double(),
##   change = col_double()
## )
head(task2)
## # 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
#Converting dataset to timeseries 
task=ts(task2,start = c(2003,3),frequency=4)
price = task[,2]
change = task[,3]
#intersecting both time series
price.joint=ts.intersect(price,change)
plot(price.joint,yax.flip=T)

We see that both the series have a upward trend showing moderately correlated.

Check cross correlation

ccf(as.vector(price.joint[,1]),as.vector(price.joint[,2]),
    ylab='CCF', main = "Sample CCF between")

We see that lags are highly significant there is no significant evidence for the existence of a spurious correlation and hence to make the series stationary we need to apply differencing. Applying prewhitening.

me.dif=ts.intersect(diff(diff(price,4)),diff(diff(change,4)))

prewhiten(as.vector(me.dif[,1]),as.vector(me.dif[,2]),
          ylab='CCF',main="Sample CFF after prewhitening ")

After prewhitening we can see that there are no lags in the plot saying no correlation between price and population change.