comparison between two systems for forecasting covid 19 cumulative infected case

cumulative Covid 19 Infection cases In Italy
Makarovskikh Tatyana Anatolyevna “Макаровских Татьяна Анатольевна”
Abotaleb mostafa“Аботалеб Мостафа”
Faculty of Electrical Engineering and Computer Science
Department of system programming
South ural state university, Chelyabinsk, Russian federation
#Import
library(fpp2)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## -- Attaching packages ---------------------------------------------- fpp2 2.4 --
## v ggplot2   3.3.2     v fma       2.4  
## v forecast  8.13      v expsmooth 2.3
## 
library(forecast)
library(ggplot2)
library("readxl")
library(moments)
library(forecast)
require(forecast)  
require(tseries)
## Loading required package: tseries
require(markovchain)
## Loading required package: markovchain
## Package:  markovchain
## Version:  0.8.5-3
## Date:     2020-12-03
## BugReport: https://github.com/spedygiorgio/markovchain/issues
require(data.table)
## Loading required package: data.table
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library(ascii)
library(pander)
## 
## Attaching package: 'pander'
## The following object is masked from 'package:ascii':
## 
##     Pandoc
library(ascii)
require(tseries) # need to install tseries tj test Stationarity in time series 
library(forecast)   # install library forecast    
library(tseries)
##Global vriable##
Full_original_data <- read.csv("data.csv") # path of your data ( time series data)
original_data<-Full_original_data$cases #Cumulative #cases
y_lab <- "Forecasting cumulative Covid 19 Infection cases in Italy"   # input name of data
Actual_date_interval <- c("2020/03/01","2021/05/08")
Forecast_date_interval <- c("2021/05/09","2021/05/30")
validation_data_days <-45
frequency<-"day"
Number_Neural<-3# Number of Neural For model NNAR Model
NNAR_Model<- TRUE     #create new model (TRUE/FALSE)
frequency<-"days"
country.name <- "Italy"
# Data Preparation & calculate some of statistics measures
summary(original_data) # Summary your time series
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0  211633  273778 1107816 2170088 4092747
# calculate standard deviation 
data.frame(kurtosis=kurtosis(original_data))   # calculate Cofficient of kurtosis
##   kurtosis
## 1 2.423727
data.frame(skewness=skewness(original_data))  # calculate Cofficient of skewness
##    skewness
## 1 0.9692781
data.frame(Standard.deviation =sd(original_data))
##   Standard.deviation
## 1            1303697
#processing on data (input data)
rows <- NROW(original_data) # calculate number of rows in time series (number of days)
training_data<-original_data[1:(rows-validation_data_days)] # Training data
testing_data<-original_data[(rows-validation_data_days+1):rows] #testing data
AD<-fulldate<-seq(as.Date(Actual_date_interval[1]),as.Date(Actual_date_interval[2]), frequency)  #input range for actual date
FD<-seq(as.Date(Forecast_date_interval[1]),as.Date(Forecast_date_interval[2]), frequency)  #input range forecasting date
N_forecasting_days<-nrow(data.frame(FD))  #calculate number of days that you want to forecasting
validation_dates<-tail(AD,validation_data_days) # select validation_dates
validation_data_by_name<-weekdays(validation_dates) # put names of validation dates
forecasting_data_by_name<-weekdays(FD)  # put names of Forecasting dates
#NNAR Model 
if(NNAR_Model==TRUE){
  data_series<-ts(training_data)
  model_NNAR<-nnetar(data_series, size = Number_Neural)
  saveRDS(model_NNAR, file = "model_NNAR.RDS")
  my_model <- readRDS("model_NNAR.RDS")
  accuracy(model_NNAR)  # accuracy on training data #Print Model Parameters
  model_NNAR
}
## Series: data_series 
## Model:  NNAR(1,3) 
## Call:   nnetar(y = data_series, size = Number_Neural)
## 
## Average of 20 networks, each of which is
## a 1-3-1 network with 10 weights
## options were - linear output units 
## 
## sigma^2 estimated as 10259590
if(NNAR_Model==FALSE){
  data_series<-ts(training_data)
  #model_NNAR<-nnetar(data_series, size = Number_Numeral)
  model_NNAR <- readRDS("model_NNAR.RDS")
  accuracy(model_NNAR)  # accuracy on training data #Print Model Parameters
  model_NNAR
}

# Testing Data Evaluation
forecasting_NNAR <- forecast(model_NNAR, h=N_forecasting_days+validation_data_days)
validation_forecast<-head(forecasting_NNAR$mean,validation_data_days)
MAPE_Per_Day<-round(  abs(((testing_data-validation_forecast)/testing_data)*100)  ,3)
paste ("MAPE % For ",validation_data_days,frequency,"by using NNAR Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE % For  45 days by using NNAR Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
MAPE_Mean_All<-paste(round(mean(MAPE_Per_Day),3),"% MAPE ",validation_data_days,frequency,y_lab,sep=" ")
MAPE_Mean_All_NNAR<-round(mean(MAPE_Per_Day),3)
MAPE_NNAR<-paste(round(MAPE_Per_Day,3),"%")
MAPE_NNAR_Model<-paste(MAPE_Per_Day ,"%")
paste (" MAPE that's Error of Forecasting for ",validation_data_days," days in NNAR Model for  ==> ",y_lab, sep=" ")
## [1] " MAPE that's Error of Forecasting for  45  days in NNAR Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
paste(MAPE_Mean_All,"%")
## [1] "3.265 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Italy %"
paste ("MAPE that's Error of Forecasting day by day for ",validation_data_days," days in NNAR Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE that's Error of Forecasting day by day for  45  days in NNAR Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(date_NNAR=validation_dates,validation_data_by_name,actual_data=testing_data,forecasting_NNAR=validation_forecast,MAPE_NNAR_Model)), type = "rest")
## 
## +----+------------+-------------------------+-------------+------------------+-----------------+
## |    | date_NNAR  | validation_data_by_name | actual_data | forecasting_NNAR | MAPE_NNAR_Model |
## +====+============+=========================+=============+==================+=================+
## | 1  | 2021-03-25 | Thursday                | 3440862.00  | 3439795.76       | 0.031 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 3464543.00  | 3459488.18       | 0.146 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 3488619.00  | 3478643.13       | 0.286 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 3512453.00  | 3497214.65       | 0.434 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 3532057.00  | 3515161.75       | 0.478 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 3544957.00  | 3532448.87       | 0.353 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 3561012.00  | 3549046.42       | 0.336 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 3584899.00  | 3564930.94       | 0.557 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 3607083.00  | 3580085.33       | 0.748 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 3629000.00  | 3594498.73       | 0.951 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 3650247.00  | 3608166.40       | 1.153 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 3668264.00  | 3621089.38       | 1.286 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 3678944.00  | 3633274.15       | 1.241 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 3686707.00  | 3644732.05       | 1.139 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 3700393.00  | 3655478.82       | 1.214 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 3717602.00  | 3665533.98       | 1.401 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 3736526.00  | 3674920.20       | 1.649 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 3754077.00  | 3683662.78       | 1.876 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 3769814.00  | 3691789.00       | 2.07 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 3779594.00  | 3699327.63       | 2.124 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 3793033.00  | 3706308.41       | 2.286 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 3809193.00  | 3712761.62       | 2.532 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 3826156.00  | 3718717.63       | 2.808 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 3842079.00  | 3724206.64       | 3.068 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 3857443.00  | 3729258.33       | 3.323 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 3870131.00  | 3733901.61       | 3.52 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 3878994.00  | 3738164.50       | 3.631 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 3891063.00  | 3742073.91       | 3.829 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 3904899.00  | 3745655.56       | 4.078 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 3920945.00  | 3748933.91       | 4.387 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 3935703.00  | 3751932.11       | 4.669 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 3949517.00  | 3754671.96       | 4.933 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 3962674.00  | 3757173.94       | 5.186 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 3971114.00  | 3759457.21       | 5.33 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 3981512.00  | 3761539.65       | 5.525 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 3994894.00  | 3763437.88       | 5.794 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4009208.00  | 3765167.33       | 6.087 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4022653.00  | 3766742.29       | 6.362 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4035617.00  | 3768175.97       | 6.627 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4044762.00  | 3769480.54       | 6.806 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4050708.00  | 3770667.23       | 6.913 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4059821.00  | 3771746.33       | 7.096 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4070400.00  | 3772727.33       | 7.313 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4082198.00  | 3773618.91       | 7.559 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4092747.00  | 3774429.03       | 7.778 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_NNAR=tail(forecasting_NNAR$mean,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------+
## |    | FD         | forecating_date | forecasting_by_NNAR |
## +====+============+=================+=====================+
## | 1  | 2021-05-09 | Sunday          | 3775164.97          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 3775833.40          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 3776440.39          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 3776991.51          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 3777491.83          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 3777945.96          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 3778358.12          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 3778732.15          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 3779071.54          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 3779379.48          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 3779658.84          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 3779912.28          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 3780142.17          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 3780350.69          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 3780539.81          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 3780711.34          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 3780866.91          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 3781007.98          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 3781135.91          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 3781251.92          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 3781357.12          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 3781452.50          |
## +----+------------+-----------------+---------------------+
plot(forecasting_NNAR,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) )
lines(x1_test, col='red',lwd=2)

graph1<-autoplot(forecasting_NNAR,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)
graph1

##bats model
# Data Modeling
data_series<-ts(training_data) # make your data to time series
autoplot(data_series ,xlab=paste ("Time in", frequency, sep=" "), ylab = y_lab, main=paste ("Actual Data :", y_lab, sep=" "))

model_bats<-bats(data_series)
accuracy(model_bats)  # accuracy on training data
##                    ME     RMSE      MAE MPE MAPE      MASE      ACF1
## Training set 103.7615 1616.055 875.9063 NaN  Inf 0.1142293 0.1476203
# Print Model Parameters
model_bats
## BATS(1, {2,2}, 1, -)
## 
## Call: bats(y = data_series)
## 
## Parameters
##   Alpha: 0.3435945
##   Beta: 0.3646252
##   Damping Parameter: 1
##   AR coefficients: 1.210798 -0.951168
##   MA coefficients: -0.469538 0.498922
## 
## Seed States:
##           [,1]
## [1,] 163.25953
## [2,] -79.18204
## [3,]   0.00000
## [4,]   0.00000
## [5,]   0.00000
## [6,]   0.00000
## 
## Sigma: 1616.055
## AIC: 9358.486
#ploting BATS Model
plot(model_bats,xlab = paste ("Time in", frequency ,y_lab , sep=" "))

# Testing Data Evaluation
forecasting_bats <- predict(model_bats, h=N_forecasting_days+validation_data_days)
validation_forecast<-head(forecasting_bats$mean,validation_data_days)
MAPE_Per_Day<-round(  abs(((testing_data-validation_forecast)/testing_data)*100)  ,3)
paste ("MAPE % For ",validation_data_days,frequency,"by using bats Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE % For  45 days by using bats Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
MAPE_Mean_All.bats_Model<-round(mean(MAPE_Per_Day),3)
MAPE_Mean_All.bats<-paste(round(mean(MAPE_Per_Day),3),"% MAPE ",validation_data_days,frequency,y_lab,sep=" ")
MAPE_bats<-paste(round(MAPE_Per_Day,3),"%")
MAPE_bats_Model<-paste(MAPE_Per_Day ,"%")
paste (" MAPE that's Error of Forecasting for ",validation_data_days," days in bats Model for  ==> ",y_lab, sep=" ")
## [1] " MAPE that's Error of Forecasting for  45  days in bats Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
paste(MAPE_Mean_All.bats,"%")
## [1] "3.897 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Italy %"
paste ("MAPE that's Error of Forecasting day by day for ",validation_data_days," days in bats Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE that's Error of Forecasting day by day for  45  days in bats Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(date_bats=validation_dates,validation_data_by_name,actual_data=testing_data,forecasting_bats=validation_forecast,MAPE_bats_Model)), type = "rest")
## 
## +----+------------+-------------------------+-------------+------------------+-----------------+
## |    | date_bats  | validation_data_by_name | actual_data | forecasting_bats | MAPE_bats_Model |
## +====+============+=========================+=============+==================+=================+
## | 1  | 2021-03-25 | Thursday                | 3440862.00  | 3444039.09       | 0.092 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 3464543.00  | 3468939.03       | 0.127 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 3488619.00  | 3494346.84       | 0.164 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 3512453.00  | 3518776.50       | 0.18 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 3532057.00  | 3541538.78       | 0.268 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 3544957.00  | 3563212.56       | 0.515 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 3561012.00  | 3585154.36       | 0.678 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 3584899.00  | 3608456.02       | 0.657 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 3607083.00  | 3633149.25       | 0.723 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 3629000.00  | 3658233.95       | 0.806 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 3650247.00  | 3682469.02       | 0.883 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 3668264.00  | 3705302.99       | 1.01 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 3678944.00  | 3727248.67       | 1.313 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 3686707.00  | 3749451.49       | 1.702 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 3700393.00  | 3772810.55       | 1.957 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 3717602.00  | 3797325.01       | 2.144 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 3736526.00  | 3822138.65       | 2.291 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 3754077.00  | 3846215.55       | 2.454 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 3769814.00  | 3869115.83       | 2.634 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 3779594.00  | 3891292.23       | 2.955 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 3793033.00  | 3913711.33       | 3.182 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 3809193.00  | 3937112.80       | 3.358 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 3826156.00  | 3961472.88       | 3.537 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 3842079.00  | 3986059.26       | 3.747 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 3857443.00  | 4010007.81       | 3.955 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 3870131.00  | 4032968.86       | 4.208 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 3878994.00  | 4055340.91       | 4.546 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 3891063.00  | 4077939.08       | 4.803 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 3904899.00  | 4101371.28       | 5.031 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 3920945.00  | 4125598.23       | 5.219 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 3935703.00  | 4149994.18       | 5.445 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 3949517.00  | 4173838.78       | 5.68 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 3962674.00  | 4196855.09       | 5.91 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 3971114.00  | 4219392.91       | 6.252 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 3981512.00  | 4242139.24       | 6.546 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 3994894.00  | 4265593.13       | 6.776 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4009208.00  | 4289705.43       | 6.996 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4022653.00  | 4313941.90       | 7.241 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4035617.00  | 4337702.47       | 7.485 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4044762.00  | 4360768.71       | 7.813 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4050708.00  | 4383446.91       | 8.214 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4059821.00  | 4406315.70       | 8.535 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4070400.00  | 4429784.35       | 8.829 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4082198.00  | 4453798.02       | 9.103 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4092747.00  | 4477901.03       | 9.411 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_bats=tail(forecasting_bats$mean,N_forecasting_days),lower=tail(forecasting_bats$lower,N_forecasting_days),Upper=tail(forecasting_bats$lower,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_bats | lower.80.  | lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+=====================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4501593.81          | 4307040.84 | 4204050.72 | 4307040.84 | 4204050.72 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4524704.90          | 4323925.44 | 4217639.22 | 4323925.44 | 4217639.22 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4547501.89          | 4340456.12 | 4230852.72 | 4340456.12 | 4230852.72 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4570471.83          | 4357077.54 | 4244113.42 | 4357077.54 | 4244113.42 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4593949.97          | 4374097.86 | 4257715.18 | 4374097.86 | 4257715.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4617878.90          | 4391467.28 | 4271612.21 | 4391467.28 | 4271612.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4641870.28          | 4408832.46 | 4285469.69 | 4408832.46 | 4285469.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4665508.49          | 4425813.06 | 4298925.97 | 4425813.06 | 4298925.97 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4688659.68          | 4442285.26 | 4311862.51 | 4442285.26 | 4311862.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4711557.12          | 4458461.98 | 4324481.51 | 4458461.98 | 4324481.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4734610.54          | 4474719.68 | 4337141.77 | 4474719.68 | 4337141.77 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4758094.19          | 4491311.82 | 4350085.76 | 4491311.82 | 4350085.76 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4781950.40          | 4508187.29 | 4363265.86 | 4508187.29 | 4363265.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4805848.47          | 4525043.26 | 4376393.96 | 4525043.26 | 4376393.96 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4829442.87          | 4541561.77 | 4389166.73 | 4541561.77 | 4389166.73 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4852629.76          | 4557646.43 | 4401491.69 | 4557646.43 | 4401491.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4875612.08          | 4573483.72 | 4413546.63 | 4573483.72 | 4413546.63 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4898734.33          | 4589391.79 | 4425635.74 | 4589391.79 | 4425635.74 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4922220.56          | 4605578.67 | 4437958.58 | 4605578.67 | 4437958.58 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4946014.42          | 4621993.74 | 4450467.55 | 4621993.74 | 4450467.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4969834.54          | 4638377.94 | 4462915.42 | 4638377.94 | 4462915.42 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4993393.86          | 4654465.94 | 4475048.33 | 4654465.94 | 4475048.33 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
plot(forecasting_bats)
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) )
lines(x1_test, col='red',lwd=2)

graph1<-autoplot(forecasting_bats,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)
graph1

## TBATS Model
# Data Modeling
data_series<-ts(training_data)
model_TBATS<-forecast:::fitSpecificTBATS(data_series,use.box.cox=FALSE, use.beta=TRUE,  seasonal.periods=c(6),use.damping=FALSE,k.vector=c(2))
accuracy(model_TBATS)  # accuracy on training data
##                    ME     RMSE      MAE MPE MAPE      MASE       ACF1
## Training set 79.71788 1982.715 1163.536 NaN  Inf 0.1517398 0.06066793
# Print Model Parameters
model_TBATS
## TBATS(1, {0,0}, 1, {<6,2>})
## 
## Call: NULL
## 
## Parameters
##   Alpha: 1.364111
##   Beta: 0.5721247
##   Damping Parameter: 1
##   Gamma-1 Values: -0.002494483
##   Gamma-2 Values: 0.00190877
## 
## Seed States:
##            [,1]
## [1,]  200.42506
## [2,]  -95.37015
## [3,]  -86.74606
## [4,]  -65.86513
## [5,] -209.78713
## [6,]   52.58304
## 
## Sigma: 1982.715
## AIC: 9535.291
plot(model_TBATS,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)

# Testing Data Evaluation
forecasting_tbats <- predict(model_TBATS, h=N_forecasting_days+validation_data_days)
validation_forecast<-head(forecasting_tbats$mean,validation_data_days)
MAPE_Per_Day<-round(  abs(((testing_data-validation_forecast)/testing_data)*100)  ,3)
paste ("MAPE % For ",validation_data_days,frequency,"by using TBATS Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE % For  45 days by using TBATS Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
MAPE_Mean_All.TBATS_Model<-round(mean(MAPE_Per_Day),3)
MAPE_Mean_All.TBATS<-paste(round(mean(MAPE_Per_Day),3),"% MAPE ",validation_data_days,frequency,y_lab,sep=" ")
MAPE_TBATS<-paste(round(MAPE_Per_Day,3),"%")
MAPE_TBATS_Model<-paste(MAPE_Per_Day ,"%")
paste (" MAPE that's Error of Forecasting for ",validation_data_days," days in TBATS Model for  ==> ",y_lab, sep=" ")
## [1] " MAPE that's Error of Forecasting for  45  days in TBATS Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
paste(MAPE_Mean_All.TBATS,"%")
## [1] "2.021 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Italy %"
paste ("MAPE that's Error of Forecasting day by day for ",validation_data_days," days in TBATS Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE that's Error of Forecasting day by day for  45  days in TBATS Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(date_TBATS=validation_dates,validation_data_by_name,actual_data=testing_data,forecasting_TBATS=validation_forecast,MAPE_TBATS_Model)), type = "rest")
## 
## +----+------------+-------------------------+-------------+-------------------+------------------+
## |    | date_TBATS | validation_data_by_name | actual_data | forecasting_TBATS | MAPE_TBATS_Model |
## +====+============+=========================+=============+===================+==================+
## | 1  | 2021-03-25 | Thursday                | 3440862.00  | 3437595.95        | 0.095 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 2  | 2021-03-26 | Friday                  | 3464543.00  | 3458405.74        | 0.177 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 3  | 2021-03-27 | Saturday                | 3488619.00  | 3478431.58        | 0.292 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 4  | 2021-03-28 | Sunday                  | 3512453.00  | 3498273.64        | 0.404 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 5  | 2021-03-29 | Monday                  | 3532057.00  | 3518875.70        | 0.373 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 6  | 2021-03-30 | Tuesday                 | 3544957.00  | 3539098.82        | 0.165 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 7  | 2021-03-31 | Wednesday               | 3561012.00  | 3559345.90        | 0.047 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 8  | 2021-04-01 | Thursday                | 3584899.00  | 3580155.70        | 0.132 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 9  | 2021-04-02 | Friday                  | 3607083.00  | 3600181.54        | 0.191 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 10 | 2021-04-03 | Saturday                | 3629000.00  | 3620023.60        | 0.247 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 11 | 2021-04-04 | Sunday                  | 3650247.00  | 3640625.65        | 0.264 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 12 | 2021-04-05 | Monday                  | 3668264.00  | 3660848.77        | 0.202 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 13 | 2021-04-06 | Tuesday                 | 3678944.00  | 3681095.86        | 0.058 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 14 | 2021-04-07 | Wednesday               | 3686707.00  | 3701905.66        | 0.412 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 15 | 2021-04-08 | Thursday                | 3700393.00  | 3721931.50        | 0.582 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 16 | 2021-04-09 | Friday                  | 3717602.00  | 3741773.56        | 0.65 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 17 | 2021-04-10 | Saturday                | 3736526.00  | 3762375.61        | 0.692 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 18 | 2021-04-11 | Sunday                  | 3754077.00  | 3782598.73        | 0.76 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 19 | 2021-04-12 | Monday                  | 3769814.00  | 3802845.82        | 0.876 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 20 | 2021-04-13 | Tuesday                 | 3779594.00  | 3823655.61        | 1.166 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 21 | 2021-04-14 | Wednesday               | 3793033.00  | 3843681.45        | 1.335 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 22 | 2021-04-15 | Thursday                | 3809193.00  | 3863523.52        | 1.426 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 23 | 2021-04-16 | Friday                  | 3826156.00  | 3884125.57        | 1.515 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 24 | 2021-04-17 | Saturday                | 3842079.00  | 3904348.69        | 1.621 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 25 | 2021-04-18 | Sunday                  | 3857443.00  | 3924595.78        | 1.741 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 26 | 2021-04-19 | Monday                  | 3870131.00  | 3945405.57        | 1.945 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 27 | 2021-04-20 | Tuesday                 | 3878994.00  | 3965431.41        | 2.228 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 28 | 2021-04-21 | Wednesday               | 3891063.00  | 3985273.47        | 2.421 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 29 | 2021-04-22 | Thursday                | 3904899.00  | 4005875.53        | 2.586 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 30 | 2021-04-23 | Friday                  | 3920945.00  | 4026098.65        | 2.682 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 31 | 2021-04-24 | Saturday                | 3935703.00  | 4046345.74        | 2.811 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 32 | 2021-04-25 | Sunday                  | 3949517.00  | 4067155.53        | 2.979 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 33 | 2021-04-26 | Monday                  | 3962674.00  | 4087181.37        | 3.142 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 34 | 2021-04-27 | Tuesday                 | 3971114.00  | 4107023.43        | 3.422 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 35 | 2021-04-28 | Wednesday               | 3981512.00  | 4127625.48        | 3.67 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 36 | 2021-04-29 | Thursday                | 3994894.00  | 4147848.61        | 3.829 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 37 | 2021-04-30 | Friday                  | 4009208.00  | 4168095.69        | 3.963 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 38 | 2021-05-01 | Saturday                | 4022653.00  | 4188905.49        | 4.133 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 39 | 2021-05-02 | Sunday                  | 4035617.00  | 4208931.33        | 4.295 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 40 | 2021-05-03 | Monday                  | 4044762.00  | 4228773.39        | 4.549 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 41 | 2021-05-04 | Tuesday                 | 4050708.00  | 4249375.44        | 4.905 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 42 | 2021-05-05 | Wednesday               | 4059821.00  | 4269598.56        | 5.167 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 43 | 2021-05-06 | Thursday                | 4070400.00  | 4289845.65        | 5.391 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 44 | 2021-05-07 | Friday                  | 4082198.00  | 4310655.45        | 5.596 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 45 | 2021-05-08 | Saturday                | 4092747.00  | 4330681.28        | 5.814 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_TBATS=tail(forecasting_tbats$mean,N_forecasting_days),Lower=tail(forecasting_tbats$lower,N_forecasting_days),Upper=tail(forecasting_tbats$upper,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_TBATS | Lower.80.  | Lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+======================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4350523.35           | 4328098.08 | 4316226.86 | 4372948.62 | 4384819.84 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4371125.40           | 4348474.97 | 4336484.56 | 4393775.83 | 4405766.24 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4391348.52           | 4368478.07 | 4356371.18 | 4414218.97 | 4426325.86 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4411595.61           | 4388508.96 | 4376287.63 | 4434682.26 | 4446903.59 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4432405.40           | 4409104.30 | 4396769.44 | 4455706.51 | 4468041.37 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4452431.24           | 4428918.47 | 4416471.56 | 4475944.01 | 4488390.92 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4472273.30           | 4448550.76 | 4435992.80 | 4495995.85 | 4508553.81 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4492875.36           | 4468944.89 | 4456276.86 | 4516805.83 | 4529473.85 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4513098.48           | 4488964.60 | 4476188.90 | 4537232.35 | 4550008.06 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4533345.57           | 4509011.61 | 4496129.99 | 4557679.52 | 4570561.14 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4554155.36           | 4529622.71 | 4516635.91 | 4578688.02 | 4591674.82 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4574181.20           | 4549452.23 | 4536361.50 | 4598910.17 | 4612000.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4594023.26           | 4569099.52 | 4555905.69 | 4618947.00 | 4632140.83 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4614625.32           | 4589508.33 | 4576212.20 | 4639742.30 | 4653038.43 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4634848.44           | 4609542.25 | 4596145.96 | 4660154.63 | 4673550.91 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4655095.52           | 4629603.07 | 4616108.18 | 4680587.98 | 4694082.87 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4675905.32           | 4650227.71 | 4636634.81 | 4701582.92 | 4715175.83 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4695931.16           | 4670070.47 | 4656380.65 | 4721791.85 | 4735481.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4715773.22           | 4689730.74 | 4675944.68 | 4741815.70 | 4755601.76 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4736375.27           | 4710152.27 | 4696270.65 | 4762598.28 | 4776479.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4756598.39           | 4730198.53 | 4716223.29 | 4782998.26 | 4796973.50 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4776845.48           | 4750271.39 | 4736203.92 | 4803419.57 | 4817487.05 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
plot(forecasting_tbats)
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) )
lines(x1_test, col='red',lwd=2)

graph2<-autoplot(forecasting_tbats,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)
graph2

## Holt's linear trend
# Data Modeling
data_series<-ts(training_data)
model_holt<-holt(data_series,h=N_forecasting_days+validation_data_days,lambda = "auto")
accuracy(model_holt)  # accuracy on training data
##                     ME    RMSE      MAE MPE MAPE      MASE      ACF1
## Training set -48.58205 2164.12 1167.205 NaN  Inf 0.1522184 0.2449641
# Print Model Parameters
summary(model_holt$model)
## Holt's method 
## 
## Call:
##  holt(y = data_series, h = N_forecasting_days + validation_data_days,  
## 
##  Call:
##      lambda = "auto") 
## 
##   Box-Cox transformation: lambda= 0.4606 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
##     beta  = 0.7819 
## 
##   Initial states:
##     l = -2.4567 
##     b = -0.6129 
## 
##   sigma:  1.3921
## 
##      AIC     AICc      BIC 
## 3029.553 3029.689 3050.066 
## 
## Training set error measures:
##                     ME    RMSE      MAE MPE MAPE      MASE      ACF1
## Training set -48.58205 2164.12 1167.205 NaN  Inf 0.1522184 0.2449641
# Testing Data Evaluation
forecasting_holt <- predict(model_holt, h=N_forecasting_days+validation_data_days,lambda = "auto")
validation_forecast<-head(forecasting_holt$mean,validation_data_days)
MAPE_Per_Day<-round(  abs(((testing_data-validation_forecast)/testing_data)*100)  ,3)
paste ("MAPE % For ",validation_data_days,frequency,"by using holt Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE % For  45 days by using holt Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
MAPE_Mean_All.Holt_Model<-round(mean(MAPE_Per_Day),3)
MAPE_Mean_All.Holt<-paste(round(mean(MAPE_Per_Day),3),"% MAPE ",validation_data_days,frequency,y_lab,sep=" ")
MAPE_holt<-paste(round(MAPE_Per_Day,3),"%")
MAPE_holt_Model<-paste(MAPE_Per_Day ,"%")
paste (" MAPE that's Error of Forecasting for ",validation_data_days," days in holt Model for  ==> ",y_lab, sep=" ")
## [1] " MAPE that's Error of Forecasting for  45  days in holt Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
paste(MAPE_Mean_All.Holt,"%")
## [1] "2.37 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Italy %"
paste ("MAPE that's Error of Forecasting day by day for ",validation_data_days," days in holt Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE that's Error of Forecasting day by day for  45  days in holt Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(date_holt=validation_dates,validation_data_by_name,actual_data=testing_data,forecasting_holt=validation_forecast,MAPE_holt_Model)), type = "rest")
## 
## +----+------------+-------------------------+-------------+------------------+-----------------+
## |    | date_holt  | validation_data_by_name | actual_data | forecasting_holt | MAPE_holt_Model |
## +====+============+=========================+=============+==================+=================+
## | 1  | 2021-03-25 | Thursday                | 3440862.00  | 3439527.01       | 0.039 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 3464543.00  | 3459499.86       | 0.146 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 3488619.00  | 3479535.11       | 0.26 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 3512453.00  | 3499632.79       | 0.365 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 3532057.00  | 3519792.91       | 0.347 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 3544957.00  | 3540015.51       | 0.139 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 3561012.00  | 3560300.61       | 0.02 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 3584899.00  | 3580648.25       | 0.119 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 3607083.00  | 3601058.45       | 0.167 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 3629000.00  | 3621531.24       | 0.206 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 3650247.00  | 3642066.65       | 0.224 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 3668264.00  | 3662664.71       | 0.153 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 3678944.00  | 3683325.44       | 0.119 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 3686707.00  | 3704048.87       | 0.47 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 3700393.00  | 3724835.03       | 0.661 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 3717602.00  | 3745683.95       | 0.755 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 3736526.00  | 3766595.65       | 0.805 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 3754077.00  | 3787570.17       | 0.892 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 3769814.00  | 3808607.52       | 1.029 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 3779594.00  | 3829707.74       | 1.326 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 3793033.00  | 3850870.86       | 1.525 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 3809193.00  | 3872096.90       | 1.651 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 3826156.00  | 3893385.88       | 1.757 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 3842079.00  | 3914737.85       | 1.891 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 3857443.00  | 3936152.82       | 2.04 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 3870131.00  | 3957630.81       | 2.261 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 3878994.00  | 3979171.87       | 2.583 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 3891063.00  | 4000776.01       | 2.82 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 3904899.00  | 4022443.26       | 3.01 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 3920945.00  | 4044173.65       | 3.143 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 3935703.00  | 4065967.21       | 3.31 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 3949517.00  | 4087823.96       | 3.502 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 3962674.00  | 4109743.92       | 3.711 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 3971114.00  | 4131727.13       | 4.045 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 3981512.00  | 4153773.62       | 4.327 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 3994894.00  | 4175883.40       | 4.531 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4009208.00  | 4198056.51       | 4.71 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4022653.00  | 4220292.96       | 4.913 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4035617.00  | 4242592.80       | 5.129 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4044762.00  | 4264956.04       | 5.444 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4050708.00  | 4287382.71       | 5.843 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4059821.00  | 4309872.84       | 6.159 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4070400.00  | 4332426.45       | 6.437 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4082198.00  | 4355043.56       | 6.684 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4092747.00  | 4377724.22       | 6.963 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_holt=tail(forecasting_holt$mean,N_forecasting_days),Lower=tail(forecasting_holt$lower,N_forecasting_days),Upper=tail(forecasting_holt$upper,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_holt | Lower.80.  | Lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+=====================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4400468.43          | 3472343.36 | 3028660.50 | 5448119.71 | 6051796.60 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4423276.23          | 3464373.91 | 3007515.25 | 5509586.75 | 6136986.92 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4446147.65          | 3456120.33 | 2986034.34 | 5571806.30 | 6223437.44 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4469082.70          | 3447586.78 | 2964226.81 | 5634781.64 | 6311156.37 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4492081.42          | 3438777.35 | 2942101.61 | 5698516.14 | 6400152.09 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4515143.83          | 3429696.07 | 2919667.56 | 5763013.22 | 6490433.08 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4538269.95          | 3420346.89 | 2896933.39 | 5828276.39 | 6582007.94 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4561459.81          | 3410733.73 | 2873907.75 | 5894309.22 | 6674885.37 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4584713.45          | 3400860.45 | 2850599.20 | 5961115.33 | 6769074.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4608030.87          | 3390730.83 | 2827016.18 | 6028698.42 | 6864583.33 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4631412.11          | 3380348.64 | 2803167.10 | 6097062.24 | 6961421.79 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4654857.20          | 3369717.57 | 2779060.25 | 6166210.59 | 7059598.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4678366.16          | 3358841.30 | 2754703.87 | 6236147.33 | 7159123.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4701939.01          | 3347723.43 | 2730106.11 | 6306876.37 | 7260004.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4725575.78          | 3336367.54 | 2705275.08 | 6378401.66 | 7362252.38 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4749276.49          | 3324777.18 | 2680218.80 | 6450727.20 | 7465875.83 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4773041.18          | 3312955.85 | 2654945.24 | 6523857.04 | 7570884.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4796869.86          | 3300907.02 | 2629462.29 | 6597795.26 | 7677288.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4820762.56          | 3288634.12 | 2603777.80 | 6672546.01 | 7785096.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4844719.31          | 3276140.55 | 2577899.57 | 6748113.44 | 7894318.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4868740.13          | 3263429.70 | 2551835.32 | 6824501.77 | 8004964.99 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4892825.04          | 3250504.89 | 2525592.75 | 6901715.24 | 8117045.37 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
plot(forecasting_holt)
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) )
lines(x1_test, col='red',lwd=2)

graph3<-autoplot(forecasting_holt,xlab = paste ("Time in", frequency ,y_lab , sep=" "),  ylab=y_lab)
graph3

#Auto arima model
##################
paste ("tests For Check Stationarity in series  ==> ",y_lab, sep=" ")
## [1] "tests For Check Stationarity in series  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
kpss.test(data_series) # applay kpss test
## Warning in kpss.test(data_series): p-value smaller than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  data_series
## KPSS Level = 5.9493, Truncation lag parameter = 5, p-value = 0.01
pp.test(data_series)   # applay pp test
## Warning in pp.test(data_series): p-value greater than printed p-value
## 
##  Phillips-Perron Unit Root Test
## 
## data:  data_series
## Dickey-Fuller Z(alpha) = 0.93102, Truncation lag parameter = 5, p-value
## = 0.99
## alternative hypothesis: stationary
adf.test(data_series)  # applay adf test
## 
##  Augmented Dickey-Fuller Test
## 
## data:  data_series
## Dickey-Fuller = -2.561, Lag order = 7, p-value = 0.3406
## alternative hypothesis: stationary
ndiffs(data_series)    # Doing first diffrencing on data
## [1] 2
#Taking the first difference
diff1_x1<-diff(data_series)
autoplot(diff1_x1, xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab,main = "1nd differenced series")

##Testing the stationary of the first differenced series
paste ("tests For Check Stationarity in series after taking first differences in  ==> ",y_lab, sep=" ")
## [1] "tests For Check Stationarity in series after taking first differences in  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
kpss.test(diff1_x1)   # applay kpss test after taking first differences
## Warning in kpss.test(diff1_x1): p-value smaller than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  diff1_x1
## KPSS Level = 4.2577, Truncation lag parameter = 5, p-value = 0.01
pp.test(diff1_x1)     # applay pp test after taking first differences
## 
##  Phillips-Perron Unit Root Test
## 
## data:  diff1_x1
## Dickey-Fuller Z(alpha) = -9.6341, Truncation lag parameter = 5, p-value
## = 0.5717
## alternative hypothesis: stationary
adf.test(diff1_x1)    # applay adf test after taking first differences
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff1_x1
## Dickey-Fuller = -2.1001, Lag order = 7, p-value = 0.5354
## alternative hypothesis: stationary
#Taking the second difference
diff2_x1=diff(diff1_x1)
autoplot(diff2_x1, xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab ,main = "2nd differenced series")

##Testing the stationary of the first differenced series
paste ("tests For Check Stationarity in series after taking Second differences in",y_lab, sep=" ")
## [1] "tests For Check Stationarity in series after taking Second differences in Forecasting cumulative Covid 19 Infection cases in Italy"
kpss.test(diff2_x1)   # applay kpss test after taking Second differences
## Warning in kpss.test(diff2_x1): p-value greater than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  diff2_x1
## KPSS Level = 0.078691, Truncation lag parameter = 5, p-value = 0.1
pp.test(diff2_x1)     # applay pp test after taking Second differences
## Warning in pp.test(diff2_x1): p-value smaller than printed p-value
## 
##  Phillips-Perron Unit Root Test
## 
## data:  diff2_x1
## Dickey-Fuller Z(alpha) = -254.11, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
adf.test(diff2_x1)    # applay adf test after taking Second differences
## Warning in adf.test(diff2_x1): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff2_x1
## Dickey-Fuller = -5.0311, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
####Fitting an ARIMA Model
#1. Using auto arima function
model1 <- auto.arima(data_series,stepwise=FALSE, approximation=FALSE, trace=T, test = c("kpss", "adf", "pp"))  #applaying auto arima
## 
##  ARIMA(0,2,0)                    : 8066.968
##  ARIMA(0,2,1)                    : 8064.516
##  ARIMA(0,2,2)                    : 8038.38
##  ARIMA(0,2,3)                    : 8020.346
##  ARIMA(0,2,4)                    : 7995.467
##  ARIMA(0,2,5)                    : 7996.653
##  ARIMA(1,2,0)                    : 8065.72
##  ARIMA(1,2,1)                    : 8040.893
##  ARIMA(1,2,2)                    : 8027.737
##  ARIMA(1,2,3)                    : 8021.992
##  ARIMA(1,2,4)                    : 7997.173
##  ARIMA(2,2,0)                    : 8055.067
##  ARIMA(2,2,1)                    : 8006.225
##  ARIMA(2,2,2)                    : 7857.392
##  ARIMA(2,2,3)                    : 7859.238
##  ARIMA(3,2,0)                    : 8020.335
##  ARIMA(3,2,1)                    : 7974.749
##  ARIMA(3,2,2)                    : Inf
##  ARIMA(4,2,0)                    : 7951.995
##  ARIMA(4,2,1)                    : 7938.679
##  ARIMA(5,2,0)                    : 7923.852
## 
## 
## 
##  Best model: ARIMA(2,2,2)
model1 # show the result of autoarima 
## Series: data_series 
## ARIMA(2,2,2) 
## 
## Coefficients:
##          ar1      ar2      ma1     ma2
##       1.2505  -0.8822  -1.5269  0.8733
## s.e.  0.0255   0.0249   0.0376  0.0286
## 
## sigma^2 estimated as 2673854:  log likelihood=-3923.63
## AIC=7857.26   AICc=7857.39   BIC=7877.75
#Make changes in the source of auto arima to run the best model
arima.string <- function (object, padding = FALSE) 
{
  order <- object$arma[c(1, 6, 2, 3, 7, 4, 5)]
  m <- order[7]
  result <- paste("ARIMA(", order[1], ",", order[2], ",", 
                  order[3], ")", sep = "")
  if (m > 1 && sum(order[4:6]) > 0) {
    result <- paste(result, "(", order[4], ",", order[5], 
                    ",", order[6], ")[", m, "]", sep = "")
  }
  if (padding && m > 1 && sum(order[4:6]) == 0) {
    result <- paste(result, "         ", sep = "")
    if (m <= 9) {
      result <- paste(result, " ", sep = "")
    }
    else if (m <= 99) {
      result <- paste(result, "  ", sep = "")
    }
    else {
      result <- paste(result, "   ", sep = "")
    }
  }
  if (!is.null(object$xreg)) {
    if (NCOL(object$xreg) == 1 && is.element("drift", names(object$coef))) {
      result <- paste(result, "with drift        ")
    }
    else {
      result <- paste("Regression with", result, "errors")
    }
  }
  else {
    if (is.element("constant", names(object$coef)) || is.element("intercept", 
                                                                 names(object$coef))) {
      result <- paste(result, "with non-zero mean")
    }
    else if (order[2] == 0 && order[5] == 0) {
      result <- paste(result, "with zero mean    ")
    }
    else {
      result <- paste(result, "                  ")
    }
  }
  if (!padding) {
    result <- gsub("[ ]*$", "", result)
  }
  return(result)
}


bestmodel <- arima.string(model1, padding = TRUE)
bestmodel <- substring(bestmodel,7,11)
bestmodel <- gsub(" ", "", bestmodel)
bestmodel <- gsub(")", "", bestmodel)
bestmodel <- strsplit(bestmodel, ",")[[1]]
bestmodel <- c(strtoi(bestmodel[1]),strtoi(bestmodel[2]),strtoi(bestmodel[3]))
bestmodel
## [1] 2 2 2
strtoi(bestmodel[3])
## [1] 2
#2. Using ACF and PACF Function
#par(mfrow=c(1,2))  # Code for making two plot in one graph 
acf(diff2_x1,xlab = paste ("Time in", frequency ,y_lab , sep=" ") , ylab=y_lab, main=paste("ACF-2nd differenced series ",y_lab, sep=" ",lag.max=20))    # plot ACF "auto correlation function after taking second diffrences

pacf(diff2_x1,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab,main=paste("PACF-2nd differenced series ",y_lab, sep=" ",lag.max=20))   # plot PACF " Partial auto correlation function after taking second diffrences

x1_model1= arima(data_series, order=c(bestmodel)) # Run Best model of auto arima  for forecasting
x1_model1  # Show result of best model of auto arima 
## 
## Call:
## arima(x = data_series, order = c(bestmodel))
## 
## Coefficients:
##          ar1      ar2      ma1     ma2
##       1.2505  -0.8822  -1.5269  0.8733
## s.e.  0.0255   0.0249   0.0376  0.0286
## 
## sigma^2 estimated as 2649820:  log likelihood = -3923.63,  aic = 7857.26
paste ("accuracy of autoarima Model For  ==> ",y_lab, sep=" ")
## [1] "accuracy of autoarima Model For  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
accuracy(x1_model1)  # aacuracy of best model from auto arima
##                    ME     RMSE      MAE       MPE     MAPE      MASE
## Training set 90.14275 1624.181 883.8675 0.8132793 1.873187 0.1152676
##                     ACF1
## Training set -0.02067537
x1_model1$x          # show result of best model from auto arima 
## NULL
checkresiduals(x1_model1,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)  # checkresiduals from best model from using auto arima 

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(2,2,2)
## Q* = 130.18, df = 6, p-value < 2.2e-16
## 
## Model df: 4.   Total lags used: 10
paste("Box-Ljung test , Ljung-Box test For Modelling for   ==> ",y_lab, sep=" ")
## [1] "Box-Ljung test , Ljung-Box test For Modelling for   ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
Box.test(x1_model1$residuals^2, lag=20, type="Ljung-Box")   # Do test for resdulas by using Box-Ljung test , Ljung-Box test For Modelling
## 
##  Box-Ljung test
## 
## data:  x1_model1$residuals^2
## X-squared = 760.36, df = 20, p-value < 2.2e-16
jarque.bera.test(x1_model1$residuals)  # Do test jarque.bera.test 
## 
##  Jarque Bera Test
## 
## data:  x1_model1$residuals
## X-squared = 423.47, df = 2, p-value < 2.2e-16
#Actual Vs Fitted
plot(data_series, col='red',lwd=2, main="Actual vs Fitted Plot", xlab='Time in (days)', ylab=y_lab) # plot actual and Fitted model 
lines(fitted(x1_model1), col='black')

#Test data
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) ) # make testing data in time series and start from rows-6
forecasting_auto_arima <- forecast(x1_model1, h=N_forecasting_days+validation_data_days)
validation_forecast<-head(forecasting_auto_arima$mean,validation_data_days)
MAPE_Per_Day<-round(abs(((testing_data-validation_forecast)/testing_data)*100)  ,3)
paste ("MAPE % For ",validation_data_days,frequency,"by using bats Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE % For  45 days by using bats Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
MAPE_Mean_All.ARIMA_Model<-round(mean(MAPE_Per_Day),3)
MAPE_Mean_All.ARIMA<-paste(round(mean(MAPE_Per_Day),3),"% MAPE ",validation_data_days,frequency,y_lab,sep=" ")
MAPE_auto_arima<-paste(round(MAPE_Per_Day,3),"%")
MAPE_auto.arima_Model<-paste(MAPE_Per_Day ,"%")
paste (" MAPE that's Error of Forecasting for ",validation_data_days," days in bats Model for  ==> ",y_lab, sep=" ")
## [1] " MAPE that's Error of Forecasting for  45  days in bats Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
paste(MAPE_Mean_All.ARIMA,"%")
## [1] "3.066 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Italy %"
paste ("MAPE that's Error of Forecasting day by day for ",validation_data_days," days in bats Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE that's Error of Forecasting day by day for  45  days in bats Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(date_auto.arima=validation_dates,validation_data_by_name,actual_data=testing_data,forecasting_auto.arima=validation_forecast,MAPE_auto.arima_Model)), type = "rest")
## 
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## |    | date_auto.arima | validation_data_by_name | actual_data | forecasting_auto.arima | MAPE_auto.arima_Model |
## +====+=================+=========================+=============+========================+=======================+
## | 1  | 2021-03-25      | Thursday                | 3440862.00  | 3439524.21             | 0.039 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 2  | 2021-03-26      | Friday                  | 3464543.00  | 3461846.24             | 0.078 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 3  | 2021-03-27      | Saturday                | 3488619.00  | 3486155.23             | 0.071 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 4  | 2021-03-28      | Sunday                  | 3512453.00  | 3510819.40             | 0.047 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 5  | 2021-03-29      | Monday                  | 3532057.00  | 3534174.88             | 0.06 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 6  | 2021-03-30      | Tuesday                 | 3544957.00  | 3555580.56             | 0.3 %                 |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 7  | 2021-03-31      | Wednesday               | 3561012.00  | 3575702.59             | 0.413 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 8  | 2021-04-01      | Thursday                | 3584899.00  | 3595939.51             | 0.308 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 9  | 2021-04-02      | Friday                  | 3607083.00  | 3617452.52             | 0.287 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 10 | 2021-04-03      | Saturday                | 3629000.00  | 3640459.87             | 0.316 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 11 | 2021-04-04      | Sunday                  | 3650247.00  | 3664210.10             | 0.383 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 12 | 2021-04-05      | Monday                  | 3668264.00  | 3687571.00             | 0.526 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 13 | 2021-04-06      | Tuesday                 | 3678944.00  | 3709789.71             | 0.838 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 14 | 2021-04-07      | Wednesday               | 3686707.00  | 3730923.62             | 1.199 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 15 | 2021-04-08      | Thursday                | 3700393.00  | 3751708.63             | 1.387 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 16 | 2021-04-09      | Friday                  | 3717602.00  | 3773014.35             | 1.491 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 17 | 2021-04-10      | Saturday                | 3736526.00  | 3795278.98             | 1.572 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 18 | 2021-04-11      | Sunday                  | 3754077.00  | 3818283.32             | 1.71 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 19 | 2021-04-12      | Monday                  | 3769814.00  | 3841366.75             | 1.898 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 20 | 2021-04-13      | Tuesday                 | 3779594.00  | 3863896.48             | 2.23 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 21 | 2021-04-14      | Wednesday               | 3793033.00  | 3885664.09             | 2.442 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 22 | 2021-04-15      | Thursday                | 3809193.00  | 3906967.15             | 2.567 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 23 | 2021-04-16      | Friday                  | 3826156.00  | 3928361.62             | 2.671 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 24 | 2021-04-17      | Saturday                | 3842079.00  | 3950280.23             | 2.816 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 25 | 2021-04-18      | Sunday                  | 3857443.00  | 3972773.60             | 2.99 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 26 | 2021-04-19      | Monday                  | 3870131.00  | 3995523.31             | 3.24 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 27 | 2021-04-20      | Tuesday                 | 3878994.00  | 4018086.52             | 3.586 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 28 | 2021-04-21      | Wednesday               | 3891063.00  | 4040190.39             | 3.833 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 29 | 2021-04-22      | Thursday                | 3904899.00  | 4061884.39             | 4.02 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 30 | 2021-04-23      | Friday                  | 3920945.00  | 4083471.08             | 4.145 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 31 | 2021-04-24      | Saturday                | 3935703.00  | 4105285.18             | 4.309 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 32 | 2021-04-25      | Sunday                  | 3949517.00  | 4127478.28             | 4.506 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 33 | 2021-04-26      | Monday                  | 3962674.00  | 4149944.72             | 4.726 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 34 | 2021-04-27      | Tuesday                 | 3971114.00  | 4172418.60             | 5.069 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 35 | 2021-04-28      | Wednesday               | 3981512.00  | 4194660.65             | 5.353 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 36 | 2021-04-29      | Thursday                | 3994894.00  | 4216606.26             | 5.55 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 37 | 2021-04-30      | Friday                  | 4009208.00  | 4238385.67             | 5.716 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 38 | 2021-05-01      | Saturday                | 4022653.00  | 4260218.79             | 5.906 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 39 | 2021-05-02      | Sunday                  | 4035617.00  | 4282265.67             | 6.112 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 40 | 2021-05-03      | Monday                  | 4044762.00  | 4304532.49             | 6.422 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 41 | 2021-05-04      | Tuesday                 | 4050708.00  | 4326885.74             | 6.818 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 42 | 2021-05-05      | Wednesday               | 4059821.00  | 4349153.05             | 7.127 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 43 | 2021-05-06      | Thursday                | 4070400.00  | 4371236.66             | 7.391 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 44 | 2021-05-07      | Friday                  | 4082198.00  | 4393166.35             | 7.618 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 45 | 2021-05-08      | Saturday                | 4092747.00  | 4415065.65             | 7.875 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_auto.arima=tail(forecasting_auto_arima$mean,N_forecasting_days),Lower=tail(forecasting_auto_arima$lower,N_forecasting_days),Upper=tail(forecasting_auto_arima$upper,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_auto.arima | Lower.80.  | Lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+===========================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4437062.72                | 4226416.93 | 4114907.78 | 4647708.52 | 4759217.67 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4459208.86                | 4241742.12 | 4126622.18 | 4676675.59 | 4791795.53 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4481455.15                | 4257104.14 | 4138339.89 | 4705806.15 | 4824570.40 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4503695.17                | 4272401.09 | 4149961.40 | 4734989.26 | 4857428.95 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4525839.02                | 4287539.39 | 4161391.20 | 4764138.64 | 4890286.84 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4547868.11                | 4302492.51 | 4172598.51 | 4793243.70 | 4923137.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4569838.56                | 4317310.24 | 4183629.82 | 4822366.88 | 4956047.29 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4591836.91                | 4332078.62 | 4194570.89 | 4851595.20 | 4989102.93 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4613921.89                | 4346861.63 | 4205488.48 | 4880982.14 | 5022355.30 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4636090.57                | 4361663.71 | 4216390.91 | 4910517.42 | 5055790.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4658287.50                | 4376434.35 | 4227230.31 | 4940140.65 | 5089344.69 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4680445.92                | 4391106.93 | 4237940.13 | 4969784.90 | 5122951.71 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4702531.25                | 4405643.15 | 4248480.09 | 4999419.34 | 5156582.41 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4724559.17                | 4420054.29 | 4258859.14 | 5029064.06 | 5190259.21 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4746579.78                | 4434388.54 | 4269124.48 | 5058771.02 | 5224035.07 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4768641.88                | 4448696.55 | 4279327.72 | 5088587.21 | 5257956.03 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4790762.32                | 4462999.40 | 4289492.18 | 5118525.25 | 5292032.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4812919.12                | 4477279.08 | 4299601.98 | 5148559.16 | 5326236.26 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4835069.90                | 4491494.83 | 4309617.18 | 5178644.96 | 5360522.62 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4857181.09                | 4505611.91 | 4319502.42 | 5208750.27 | 5394859.76 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4879248.09                | 4519623.15 | 4329249.21 | 5238873.02 | 5429246.96 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4901294.74                | 4533550.57 | 4338878.57 | 5269038.90 | 5463710.90 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
plot(forecasting_auto_arima)
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) )
lines(x1_test, col='red',lwd=2)

graph4<-autoplot(forecasting_auto_arima,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)
graph4

MAPE_Mean_All.ARIMA
## [1] "3.066 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Italy"
## Ensembling (Average)
weight.model<-0.90#  optimization the weights ( weight average)
re_NNAR<-forecasting_NNAR$mean
re_BATS<-forecasting_bats$mean
re_TBATS<-forecasting_tbats$mean
re_holt<-forecasting_holt$mean
re_autoarima<-forecasting_auto_arima$mean
re_bestmodel<-min(MAPE_Mean_All_NNAR,MAPE_Mean_All.bats_Model,MAPE_Mean_All.TBATS_Model,MAPE_Mean_All.Holt_Model,MAPE_Mean_All.ARIMA_Model)
y1<-if(re_bestmodel >= MAPE_Mean_All.bats_Model) {re_BATS*weight.model
} else {
  (re_BATS*(1-weight.model))/4
}

y2<-if(re_bestmodel >= MAPE_Mean_All.TBATS_Model) {re_TBATS*weight.model
} else {
  (re_TBATS*(1-weight.model))/4
}

y3<-if(re_bestmodel >= MAPE_Mean_All.Holt_Model) {re_holt*weight.model
} else {
  (re_holt*(1-weight.model))/4
}
y4<-if(re_bestmodel >= MAPE_Mean_All.ARIMA_Model) {re_autoarima*weight.model
} else {
  (re_autoarima*(1-weight.model))/4
}
y5<-if(re_bestmodel >= MAPE_Mean_All_NNAR) {re_NNAR*weight.model
} else {
  (re_NNAR*(1-weight.model))/4
}
Ensembling.Average<-(y1+y2+y3+y4+y5)
# Testing Data Evaluation
validation_forecast<-head(Ensembling.Average,validation_data_days)
MAPE_Per_Day<-round(abs(((testing_data-validation_forecast)/testing_data)*100)  ,3)
paste ("MAPE % For ",validation_data_days,frequency,"by using Ensembling (Average) for  ==> ",y_lab, sep=" ")
## [1] "MAPE % For  45 days by using Ensembling (Average) for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
MAPE_Mean_EnsemblingAverage<-round(mean(MAPE_Per_Day),3)
MAPE_Mean_Ensembling<-paste(round(mean(MAPE_Per_Day),3),"% MAPE ",validation_data_days,frequency,y_lab,sep=" ")
MAPE_Ensembling<-paste(round(MAPE_Per_Day,3),"%")
MAPE_Ensembling_Model<-paste(MAPE_Per_Day ,"%")
paste (" MAPE that's Error of Forecasting for ",validation_data_days," days in Ensembling Model for  ==> ",y_lab, sep=" ")
## [1] " MAPE that's Error of Forecasting for  45  days in Ensembling Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
paste(MAPE_Mean_EnsemblingAverage,"%")
## [1] "1.969 %"
paste ("MAPE that's Error of Forecasting day by day for ",validation_data_days," days in Ensembling Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE that's Error of Forecasting day by day for  45  days in Ensembling Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(date_Ensembling=validation_dates,validation_data_by_name,actual_data=testing_data,Ensembling=validation_forecast,MAPE_Ensembling)), type = "rest")
## 
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## |    | date_Ensembling | validation_data_by_name | actual_data | Ensembling | MAPE_Ensembling |
## +====+=================+=========================+=============+============+=================+
## | 1  | 2021-03-25      | Thursday                | 3440862.00  | 3437908.50 | 0.086 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 2  | 2021-03-26      | Friday                  | 3464543.00  | 3458809.50 | 0.165 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 3  | 2021-03-27      | Saturday                | 3488619.00  | 3479055.43 | 0.274 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 4  | 2021-03-28      | Sunday                  | 3512453.00  | 3499107.36 | 0.38 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 5  | 2021-03-29      | Monday                  | 3532057.00  | 3519754.83 | 0.348 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 6  | 2021-03-30      | Tuesday                 | 3544957.00  | 3539970.37 | 0.141 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 7  | 2021-03-31      | Wednesday               | 3561012.00  | 3560166.41 | 0.024 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 8  | 2021-04-01      | Thursday                | 3584899.00  | 3580889.50 | 0.112 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 9  | 2021-04-02      | Friday                  | 3607083.00  | 3600957.02 | 0.17 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 10 | 2021-04-03      | Saturday                | 3629000.00  | 3620889.34 | 0.223 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 11 | 2021-04-04      | Sunday                  | 3650247.00  | 3641485.89 | 0.24 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 12 | 2021-04-05      | Monday                  | 3668264.00  | 3661679.60 | 0.179 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 13 | 2021-04-06      | Tuesday                 | 3678944.00  | 3681827.23 | 0.078 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 14 | 2021-04-07      | Wednesday               | 3686707.00  | 3702443.99 | 0.427 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 15 | 2021-04-08      | Thursday                | 3700393.00  | 3722359.17 | 0.594 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 16 | 2021-04-09      | Friday                  | 3717602.00  | 3742135.13 | 0.66 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 17 | 2021-04-10      | Saturday                | 3736526.00  | 3762611.39 | 0.698 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 18 | 2021-04-11      | Sunday                  | 3754077.00  | 3782732.15 | 0.763 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 19 | 2021-04-12      | Monday                  | 3769814.00  | 3802833.22 | 0.876 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 20 | 2021-04-13      | Tuesday                 | 3779594.00  | 3823395.66 | 1.159 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 21 | 2021-04-14      | Wednesday               | 3793033.00  | 3843227.18 | 1.323 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 22 | 2021-04-15      | Thursday                | 3809193.00  | 3862894.63 | 1.41 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 23 | 2021-04-16      | Friday                  | 3826156.00  | 3883261.46 | 1.493 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 24 | 2021-04-17      | Saturday                | 3842079.00  | 3903295.92 | 1.593 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 25 | 2021-04-18      | Sunday                  | 3857443.00  | 3923341.01 | 1.708 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 26 | 2021-04-19      | Monday                  | 3870131.00  | 3943865.63 | 1.905 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 27 | 2021-04-20      | Tuesday                 | 3878994.00  | 3963657.36 | 2.183 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 28 | 2021-04-21      | Wednesday               | 3891063.00  | 3983270.61 | 2.37 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 29 | 2021-04-22      | Thursday                | 3904899.00  | 4003571.84 | 2.527 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 30 | 2021-04-23      | Friday                  | 3920945.00  | 4023543.21 | 2.617 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 31 | 2021-04-24      | Saturday                | 3935703.00  | 4043540.63 | 2.74 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 32 | 2021-04-25      | Sunday                  | 3949517.00  | 4064035.30 | 2.9 %           |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 33 | 2021-04-26      | Monday                  | 3962674.00  | 4083806.17 | 3.057 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 34 | 2021-04-27      | Tuesday                 | 3971114.00  | 4103395.98 | 3.331 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 35 | 2021-04-28      | Wednesday               | 3981512.00  | 4123665.76 | 3.57 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 36 | 2021-04-29      | Thursday                | 3994894.00  | 4143601.76 | 3.722 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 37 | 2021-04-30      | Friday                  | 4009208.00  | 4163569.00 | 3.85 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 38 | 2021-05-01      | Saturday                | 4022653.00  | 4184044.84 | 4.012 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 39 | 2021-05-02      | Sunday                  | 4035617.00  | 4203806.62 | 4.168 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 40 | 2021-05-03      | Monday                  | 4044762.00  | 4223389.49 | 4.416 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 41 | 2021-05-04      | Tuesday                 | 4050708.00  | 4243647.46 | 4.763 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 42 | 2021-05-05      | Wednesday               | 4059821.00  | 4263565.91 | 5.019 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 43 | 2021-05-06      | Thursday                | 4070400.00  | 4283515.46 | 5.236 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 44 | 2021-05-07      | Friday                  | 4082198.00  | 4303980.57 | 5.433 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 45 | 2021-05-08      | Saturday                | 4092747.00  | 4323741.15 | 5.644 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_Ensembling=tail(Ensembling.Average,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------------+
## |    | FD         | forecating_date | forecasting_by_Ensembling |
## +====+============+=================+===========================+
## | 1  | 2021-05-09 | Sunday          | 4343328.26                |
## +----+------------+-----------------+---------------------------+
## | 2  | 2021-05-10 | Monday          | 4363588.44                |
## +----+------------+-----------------+---------------------------+
## | 3  | 2021-05-11 | Tuesday         | 4383502.30                |
## +----+------------+-----------------+---------------------------+
## | 4  | 2021-05-12 | Wednesday       | 4403442.08                |
## +----+------------+-----------------+---------------------------+
## | 5  | 2021-05-13 | Thursday        | 4423898.92                |
## +----+------------+-----------------+---------------------------+
## | 6  | 2021-05-14 | Friday          | 4443659.04                |
## +----+------------+-----------------+---------------------------+
## | 7  | 2021-05-15 | Saturday        | 4463254.40                |
## +----+------------+-----------------+---------------------------+
## | 8  | 2021-05-16 | Sunday          | 4483526.26                |
## +----+------------+-----------------+---------------------------+
## | 9  | 2021-05-17 | Monday          | 4503447.80                |
## +----+------------+-----------------+---------------------------+
## | 10 | 2021-05-18 | Tuesday         | 4523387.46                |
## +----+------------+-----------------+---------------------------+
## | 11 | 2021-05-19 | Wednesday       | 4543839.05                |
## +----+------------+-----------------+---------------------------+
## | 12 | 2021-05-20 | Thursday        | 4563595.82                |
## +----+------------+-----------------+---------------------------+
## | 13 | 2021-05-21 | Friday          | 4583195.69                |
## +----+------------+-----------------+---------------------------+
## | 14 | 2021-05-22 | Saturday        | 4603480.22                |
## +----+------------+-----------------+---------------------------+
## | 15 | 2021-05-23 | Sunday          | 4623417.05                |
## +----+------------+-----------------+---------------------------+
## | 16 | 2021-05-24 | Monday          | 4643367.46                |
## +----+------------+-----------------+---------------------------+
## | 17 | 2021-05-25 | Tuesday         | 4663821.85                |
## +----+------------+-----------------+---------------------------+
## | 18 | 2021-05-26 | Wednesday       | 4683576.32                |
## +----+------------+-----------------+---------------------------+
## | 19 | 2021-05-27 | Thursday        | 4703175.62                |
## +----+------------+-----------------+---------------------------+
## | 20 | 2021-05-28 | Friday          | 4723466.91                |
## +----+------------+-----------------+---------------------------+
## | 21 | 2021-05-29 | Saturday        | 4743418.05                |
## +----+------------+-----------------+---------------------------+
## | 22 | 2021-05-30 | Sunday          | 4763385.09                |
## +----+------------+-----------------+---------------------------+
graph5<-autoplot(Ensembling.Average,xlab = paste ("Time in", frequency ,y_lab,"by using Ensembling models" , sep=" "), ylab=y_lab)
graph5

# Table for MAPE For counry
best_recommended_model <- min(MAPE_Mean_All_NNAR,MAPE_Mean_All.bats_Model,MAPE_Mean_All.TBATS_Model,MAPE_Mean_All.Holt_Model,MAPE_Mean_All.ARIMA_Model,MAPE_Mean_EnsemblingAverage)
paste("System Choose Least Error ==> ( MAPE %) of Forecasting  by using bats model and BATS Model, Holt's Linear Models , and autoarima for  ==> ", y_lab , sep=" ")
## [1] "System Choose Least Error ==> ( MAPE %) of Forecasting  by using bats model and BATS Model, Holt's Linear Models , and autoarima for  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
best_recommended_model
## [1] 1.969
x1<-if(best_recommended_model >= MAPE_Mean_All.bats_Model) {paste("BATS Model")}
x2<-if(best_recommended_model >= MAPE_Mean_All.TBATS_Model) {paste("TBATS Model")}
x3<-if(best_recommended_model >= MAPE_Mean_All.Holt_Model) {paste("Holt Model")}
x4<-if(best_recommended_model >= MAPE_Mean_All.ARIMA_Model) {paste("ARIMA Model")}
x5<-if(best_recommended_model >= MAPE_Mean_All_NNAR) {paste("NNAR Model")}
x6<-if(best_recommended_model >= MAPE_Mean_EnsemblingAverage) {paste("Ensembling")}
panderOptions('table.split.table', Inf)
paste("Forecasting by using BATS Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using BATS Model  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_bats=tail(forecasting_bats$mean,N_forecasting_days),lower=tail(forecasting_bats$lower,N_forecasting_days),Upper=tail(forecasting_bats$lower,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_bats | lower.80.  | lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+=====================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4501593.81          | 4307040.84 | 4204050.72 | 4307040.84 | 4204050.72 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4524704.90          | 4323925.44 | 4217639.22 | 4323925.44 | 4217639.22 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4547501.89          | 4340456.12 | 4230852.72 | 4340456.12 | 4230852.72 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4570471.83          | 4357077.54 | 4244113.42 | 4357077.54 | 4244113.42 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4593949.97          | 4374097.86 | 4257715.18 | 4374097.86 | 4257715.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4617878.90          | 4391467.28 | 4271612.21 | 4391467.28 | 4271612.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4641870.28          | 4408832.46 | 4285469.69 | 4408832.46 | 4285469.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4665508.49          | 4425813.06 | 4298925.97 | 4425813.06 | 4298925.97 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4688659.68          | 4442285.26 | 4311862.51 | 4442285.26 | 4311862.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4711557.12          | 4458461.98 | 4324481.51 | 4458461.98 | 4324481.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4734610.54          | 4474719.68 | 4337141.77 | 4474719.68 | 4337141.77 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4758094.19          | 4491311.82 | 4350085.76 | 4491311.82 | 4350085.76 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4781950.40          | 4508187.29 | 4363265.86 | 4508187.29 | 4363265.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4805848.47          | 4525043.26 | 4376393.96 | 4525043.26 | 4376393.96 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4829442.87          | 4541561.77 | 4389166.73 | 4541561.77 | 4389166.73 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4852629.76          | 4557646.43 | 4401491.69 | 4557646.43 | 4401491.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4875612.08          | 4573483.72 | 4413546.63 | 4573483.72 | 4413546.63 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4898734.33          | 4589391.79 | 4425635.74 | 4589391.79 | 4425635.74 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4922220.56          | 4605578.67 | 4437958.58 | 4605578.67 | 4437958.58 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4946014.42          | 4621993.74 | 4450467.55 | 4621993.74 | 4450467.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4969834.54          | 4638377.94 | 4462915.42 | 4638377.94 | 4462915.42 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4993393.86          | 4654465.94 | 4475048.33 | 4654465.94 | 4475048.33 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using TBATS Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using TBATS Model  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_TBATS=tail(forecasting_tbats$mean,N_forecasting_days),Lower=tail(forecasting_tbats$lower,N_forecasting_days),Upper=tail(forecasting_tbats$upper,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_TBATS | Lower.80.  | Lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+======================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4350523.35           | 4328098.08 | 4316226.86 | 4372948.62 | 4384819.84 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4371125.40           | 4348474.97 | 4336484.56 | 4393775.83 | 4405766.24 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4391348.52           | 4368478.07 | 4356371.18 | 4414218.97 | 4426325.86 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4411595.61           | 4388508.96 | 4376287.63 | 4434682.26 | 4446903.59 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4432405.40           | 4409104.30 | 4396769.44 | 4455706.51 | 4468041.37 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4452431.24           | 4428918.47 | 4416471.56 | 4475944.01 | 4488390.92 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4472273.30           | 4448550.76 | 4435992.80 | 4495995.85 | 4508553.81 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4492875.36           | 4468944.89 | 4456276.86 | 4516805.83 | 4529473.85 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4513098.48           | 4488964.60 | 4476188.90 | 4537232.35 | 4550008.06 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4533345.57           | 4509011.61 | 4496129.99 | 4557679.52 | 4570561.14 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4554155.36           | 4529622.71 | 4516635.91 | 4578688.02 | 4591674.82 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4574181.20           | 4549452.23 | 4536361.50 | 4598910.17 | 4612000.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4594023.26           | 4569099.52 | 4555905.69 | 4618947.00 | 4632140.83 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4614625.32           | 4589508.33 | 4576212.20 | 4639742.30 | 4653038.43 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4634848.44           | 4609542.25 | 4596145.96 | 4660154.63 | 4673550.91 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4655095.52           | 4629603.07 | 4616108.18 | 4680587.98 | 4694082.87 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4675905.32           | 4650227.71 | 4636634.81 | 4701582.92 | 4715175.83 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4695931.16           | 4670070.47 | 4656380.65 | 4721791.85 | 4735481.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4715773.22           | 4689730.74 | 4675944.68 | 4741815.70 | 4755601.76 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4736375.27           | 4710152.27 | 4696270.65 | 4762598.28 | 4776479.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4756598.39           | 4730198.53 | 4716223.29 | 4782998.26 | 4796973.50 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4776845.48           | 4750271.39 | 4736203.92 | 4803419.57 | 4817487.05 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
paste("Forecasting by using Holt's Linear Trend Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using Holt's Linear Trend Model  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_holt=tail(forecasting_holt$mean,N_forecasting_days),Lower=tail(forecasting_holt$lower,N_forecasting_days),Upper=tail(forecasting_holt$upper,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_holt | Lower.80.  | Lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+=====================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4400468.43          | 3472343.36 | 3028660.50 | 5448119.71 | 6051796.60 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4423276.23          | 3464373.91 | 3007515.25 | 5509586.75 | 6136986.92 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4446147.65          | 3456120.33 | 2986034.34 | 5571806.30 | 6223437.44 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4469082.70          | 3447586.78 | 2964226.81 | 5634781.64 | 6311156.37 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4492081.42          | 3438777.35 | 2942101.61 | 5698516.14 | 6400152.09 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4515143.83          | 3429696.07 | 2919667.56 | 5763013.22 | 6490433.08 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4538269.95          | 3420346.89 | 2896933.39 | 5828276.39 | 6582007.94 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4561459.81          | 3410733.73 | 2873907.75 | 5894309.22 | 6674885.37 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4584713.45          | 3400860.45 | 2850599.20 | 5961115.33 | 6769074.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4608030.87          | 3390730.83 | 2827016.18 | 6028698.42 | 6864583.33 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4631412.11          | 3380348.64 | 2803167.10 | 6097062.24 | 6961421.79 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4654857.20          | 3369717.57 | 2779060.25 | 6166210.59 | 7059598.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4678366.16          | 3358841.30 | 2754703.87 | 6236147.33 | 7159123.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4701939.01          | 3347723.43 | 2730106.11 | 6306876.37 | 7260004.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4725575.78          | 3336367.54 | 2705275.08 | 6378401.66 | 7362252.38 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4749276.49          | 3324777.18 | 2680218.80 | 6450727.20 | 7465875.83 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4773041.18          | 3312955.85 | 2654945.24 | 6523857.04 | 7570884.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4796869.86          | 3300907.02 | 2629462.29 | 6597795.26 | 7677288.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4820762.56          | 3288634.12 | 2603777.80 | 6672546.01 | 7785096.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4844719.31          | 3276140.55 | 2577899.57 | 6748113.44 | 7894318.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4868740.13          | 3263429.70 | 2551835.32 | 6824501.77 | 8004964.99 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4892825.04          | 3250504.89 | 2525592.75 | 6901715.24 | 8117045.37 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using ARIMA Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using ARIMA Model  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_auto.arima=tail(forecasting_auto_arima$mean,N_forecasting_days),Lower=tail(forecasting_auto_arima$lower,N_forecasting_days),Upper=tail(forecasting_auto_arima$upper,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## |    | FD         | forecating_date | forecasting_by_auto.arima | Lower.80.  | Lower.95.  | Upper.80.  | Upper.95.  |
## +====+============+=================+===========================+============+============+============+============+
## | 1  | 2021-05-09 | Sunday          | 4437062.72                | 4226416.93 | 4114907.78 | 4647708.52 | 4759217.67 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4459208.86                | 4241742.12 | 4126622.18 | 4676675.59 | 4791795.53 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4481455.15                | 4257104.14 | 4138339.89 | 4705806.15 | 4824570.40 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4503695.17                | 4272401.09 | 4149961.40 | 4734989.26 | 4857428.95 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4525839.02                | 4287539.39 | 4161391.20 | 4764138.64 | 4890286.84 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4547868.11                | 4302492.51 | 4172598.51 | 4793243.70 | 4923137.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4569838.56                | 4317310.24 | 4183629.82 | 4822366.88 | 4956047.29 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4591836.91                | 4332078.62 | 4194570.89 | 4851595.20 | 4989102.93 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4613921.89                | 4346861.63 | 4205488.48 | 4880982.14 | 5022355.30 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4636090.57                | 4361663.71 | 4216390.91 | 4910517.42 | 5055790.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4658287.50                | 4376434.35 | 4227230.31 | 4940140.65 | 5089344.69 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4680445.92                | 4391106.93 | 4237940.13 | 4969784.90 | 5122951.71 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4702531.25                | 4405643.15 | 4248480.09 | 4999419.34 | 5156582.41 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4724559.17                | 4420054.29 | 4258859.14 | 5029064.06 | 5190259.21 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4746579.78                | 4434388.54 | 4269124.48 | 5058771.02 | 5224035.07 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4768641.88                | 4448696.55 | 4279327.72 | 5088587.21 | 5257956.03 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4790762.32                | 4462999.40 | 4289492.18 | 5118525.25 | 5292032.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4812919.12                | 4477279.08 | 4299601.98 | 5148559.16 | 5326236.26 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4835069.90                | 4491494.83 | 4309617.18 | 5178644.96 | 5360522.62 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4857181.09                | 4505611.91 | 4319502.42 | 5208750.27 | 5394859.76 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4879248.09                | 4519623.15 | 4329249.21 | 5238873.02 | 5429246.96 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4901294.74                | 4533550.57 | 4338878.57 | 5269038.90 | 5463710.90 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
paste("Forecasting by using NNAR Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using NNAR Model  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting_by_NNAR=tail(forecasting_NNAR$mean,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+---------------------+
## |    | FD         | forecating_date | forecasting_by_NNAR |
## +====+============+=================+=====================+
## | 1  | 2021-05-09 | Sunday          | 3775164.97          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 3775833.40          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 3776440.39          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 3776991.51          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 3777491.83          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 3777945.96          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 3778358.12          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 3778732.15          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 3779071.54          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 3779379.48          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 3779658.84          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 3779912.28          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 3780142.17          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 3780350.69          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 3780539.81          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 3780711.34          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 3780866.91          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 3781007.98          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 3781135.91          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 3781251.92          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 3781357.12          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 3781452.50          |
## +----+------------+-----------------+---------------------+
paste("Forecasting by using Ensembling Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using Ensembling Model  ==>  Forecasting cumulative Covid 19 Infection cases in Italy"
print(ascii(data.frame(FD,forecating_date=forecasting_data_by_name,forecasting.Ensembling=tail(Ensembling.Average,N_forecasting_days))), type = "rest")
## 
## +----+------------+-----------------+------------------------+
## |    | FD         | forecating_date | forecasting.Ensembling |
## +====+============+=================+========================+
## | 1  | 2021-05-09 | Sunday          | 4343328.26             |
## +----+------------+-----------------+------------------------+
## | 2  | 2021-05-10 | Monday          | 4363588.44             |
## +----+------------+-----------------+------------------------+
## | 3  | 2021-05-11 | Tuesday         | 4383502.30             |
## +----+------------+-----------------+------------------------+
## | 4  | 2021-05-12 | Wednesday       | 4403442.08             |
## +----+------------+-----------------+------------------------+
## | 5  | 2021-05-13 | Thursday        | 4423898.92             |
## +----+------------+-----------------+------------------------+
## | 6  | 2021-05-14 | Friday          | 4443659.04             |
## +----+------------+-----------------+------------------------+
## | 7  | 2021-05-15 | Saturday        | 4463254.40             |
## +----+------------+-----------------+------------------------+
## | 8  | 2021-05-16 | Sunday          | 4483526.26             |
## +----+------------+-----------------+------------------------+
## | 9  | 2021-05-17 | Monday          | 4503447.80             |
## +----+------------+-----------------+------------------------+
## | 10 | 2021-05-18 | Tuesday         | 4523387.46             |
## +----+------------+-----------------+------------------------+
## | 11 | 2021-05-19 | Wednesday       | 4543839.05             |
## +----+------------+-----------------+------------------------+
## | 12 | 2021-05-20 | Thursday        | 4563595.82             |
## +----+------------+-----------------+------------------------+
## | 13 | 2021-05-21 | Friday          | 4583195.69             |
## +----+------------+-----------------+------------------------+
## | 14 | 2021-05-22 | Saturday        | 4603480.22             |
## +----+------------+-----------------+------------------------+
## | 15 | 2021-05-23 | Sunday          | 4623417.05             |
## +----+------------+-----------------+------------------------+
## | 16 | 2021-05-24 | Monday          | 4643367.46             |
## +----+------------+-----------------+------------------------+
## | 17 | 2021-05-25 | Tuesday         | 4663821.85             |
## +----+------------+-----------------+------------------------+
## | 18 | 2021-05-26 | Wednesday       | 4683576.32             |
## +----+------------+-----------------+------------------------+
## | 19 | 2021-05-27 | Thursday        | 4703175.62             |
## +----+------------+-----------------+------------------------+
## | 20 | 2021-05-28 | Friday          | 4723466.91             |
## +----+------------+-----------------+------------------------+
## | 21 | 2021-05-29 | Saturday        | 4743418.05             |
## +----+------------+-----------------+------------------------+
## | 22 | 2021-05-30 | Sunday          | 4763385.09             |
## +----+------------+-----------------+------------------------+
result<-c(x1,x2,x3,x4,x5,x6)
table.error<-data.frame(country.name,NNAR.model=MAPE_Mean_All_NNAR, BATS.Model=MAPE_Mean_All.bats_Model,TBATS.Model=MAPE_Mean_All.TBATS_Model,Holt.Model=MAPE_Mean_All.Holt_Model,ARIMA.Model=MAPE_Mean_All.ARIMA_Model,Ensemblingt=MAPE_Mean_EnsemblingAverage,Best.Model=result)
print(ascii(table(table.error)), type = "rest")
## 
## +---+--------------+------------+------------+-------------+------------+-------------+-------------+------------+------+
## |   | country.name | NNAR.model | BATS.Model | TBATS.Model | Holt.Model | ARIMA.Model | Ensemblingt | Best.Model | Freq |
## +===+==============+============+============+=============+============+=============+=============+============+======+
## | 1 | Italy        | 3.265      | 3.897      | 2.021       | 2.37       | 3.066       | 1.969       | Ensembling | 1.00 |
## +---+--------------+------------+------------+-------------+------------+-------------+-------------+------------+------+
MAPE.Value<-c(MAPE_Mean_All_NNAR,MAPE_Mean_All.bats_Model,MAPE_Mean_All.TBATS_Model,MAPE_Mean_All.Holt_Model,MAPE_Mean_All.ARIMA_Model,MAPE_Mean_EnsemblingAverage)
Model<-c("NNAR.model","BATS.Model","TBATS.Model","Holt.Model","ARIMA.Model","Ensembling.weight")
channel_data<-data.frame(Model,MAPE.Value)
# Normally, the entire expression below would be assigned to an object, but we're
# going bare bones here.
ggplot(channel_data, aes(x = Model, y = MAPE.Value)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = MAPE.Value)) +  # x AND y INHERITED. WE JUST NEED TO SPECIFY "label"
  coord_flip() +
  scale_y_continuous(expand = c(0, 0))

message("System finished Modelling and Forecasting  by using BATS, TBATS, Holt's Linear Trend,ARIMA Model, and Ensembling Model ==>",y_lab, sep=" ")
## System finished Modelling and Forecasting  by using BATS, TBATS, Holt's Linear Trend,ARIMA Model, and Ensembling Model ==>Forecasting cumulative Covid 19 Infection cases in Italy
message(" Thank you for using our System For Modelling and Forecasting ==> ",y_lab, sep=" ")
##  Thank you for using our System For Modelling and Forecasting ==> Forecasting cumulative Covid 19 Infection cases in Italy