comparison between two systems for forecasting covid 19 cumulative infected case

cumulative Covid 19 Infection cases In France
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 France"   # 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 <- "France"
# Data Preparation & calculate some of statistics measures
summary(original_data) # Summary your time series
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0  130108  287695 1414088 2620276 5655548
# calculate standard deviation 
data.frame(kurtosis=kurtosis(original_data))   # calculate Cofficient of kurtosis
##   kurtosis
## 1 2.618052
data.frame(skewness=skewness(original_data))  # calculate Cofficient of skewness
##    skewness
## 1 0.9819582
data.frame(Standard.deviation =sd(original_data))
##   Standard.deviation
## 1            1710849
#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 37204516
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 France"
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 France"
paste(MAPE_Mean_All,"%")
## [1] "9.37 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in France %"
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 France"
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                | 4306105.00  | 4296621.06       | 0.22 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 4351506.00  | 4319803.54       | 0.729 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 4393375.00  | 4342215.27       | 1.164 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 4435187.00  | 4363814.37       | 1.609 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 4472201.00  | 4384565.69       | 1.96 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 4481295.00  | 4404441.20       | 1.715 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 4510870.00  | 4423420.14       | 1.939 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 4569698.00  | 4441489.02       | 2.806 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 4620357.00  | 4458641.49       | 3.5 %           |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 4665877.00  | 4474878.01       | 4.094 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 4679794.00  | 4490205.47       | 4.051 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 4746588.00  | 4504636.60       | 5.097 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 4758923.00  | 4518189.46       | 5.059 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 4807569.00  | 4530886.67       | 5.755 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 4838354.00  | 4542754.85       | 6.109 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 4861992.00  | 4553823.84       | 6.338 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 4901955.00  | 4564126.08       | 6.892 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 4945238.00  | 4573695.96       | 7.513 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 4980133.00  | 4582569.23       | 7.983 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 4987689.00  | 4590782.42       | 7.958 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 5026645.00  | 4598372.39       | 8.52 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 5069999.00  | 4605375.89       | 9.164 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 5107935.00  | 4611829.21       | 9.712 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 5144295.00  | 4617767.84       | 10.235 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 5178513.00  | 4623226.24       | 10.723 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 5207857.00  | 4628237.67       | 11.13 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 5214493.00  | 4632833.98       | 11.155 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 5257046.00  | 4637045.56       | 11.794 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 5291414.00  | 4640901.24       | 12.294 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 5325448.00  | 4644428.26       | 12.788 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 5357640.00  | 4647652.24       | 13.252 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 5388524.00  | 4650597.22       | 13.694 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 5412989.00  | 4653285.68       | 14.035 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 5417903.00  | 4655738.56       | 14.068 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 5447883.00  | 4657975.34       | 14.499 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 5479327.00  | 4660014.09       | 14.953 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 5505700.00  | 4661871.52       | 15.326 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 5529820.00  | 4663563.10       | 15.665 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 5553806.00  | 4665103.07       | 16.002 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 5563694.00  | 4666504.56       | 16.126 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 5567300.00  | 4667779.63       | 16.157 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 5590416.00  | 4668939.38       | 16.483 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 5616180.00  | 4669993.96       | 16.848 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 5637744.00  | 4670952.69       | 17.149 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 5655548.00  | 4671824.11       | 17.394 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 4672616.02          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 4673335.54          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 4673989.20          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 4674582.93          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 4675122.17          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 4675611.85          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 4676056.49          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 4676460.18          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 4676826.67          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 4677159.36          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 4677461.34          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 4677735.43          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 4677984.19          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 4678209.95          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 4678414.83          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 4678600.74          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 4678769.45          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 4678922.52          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 4679061.42          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 4679187.44          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 4679301.78          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 4679405.52          |
## +----+------------+-----------------+---------------------+
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 233.5392 5645.514 2977.452 NaN  Inf 0.3106847 -0.01656129
# Print Model Parameters
model_bats
## BATS(1, {0,0}, 1, -)
## 
## Call: bats(y = data_series)
## 
## Parameters
##   Alpha: 1.288904
##   Beta: 0.2815286
##   Damping Parameter: 1
## 
## Seed States:
##          [,1]
## [1,] 94.11346
## [2,] 17.07223
## 
## Sigma: 5645.514
## AIC: 10458.77
#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 France"
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 France"
paste(MAPE_Mean_All.bats,"%")
## [1] "2.291 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in France %"
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 France"
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                | 4306105.00  | 4298968.33       | 0.166 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 4351506.00  | 4328374.75       | 0.532 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 4393375.00  | 4357781.16       | 0.81 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 4435187.00  | 4387187.58       | 1.082 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 4472201.00  | 4416593.99       | 1.243 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 4481295.00  | 4446000.41       | 0.788 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 4510870.00  | 4475406.82       | 0.786 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 4569698.00  | 4504813.24       | 1.42 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 4620357.00  | 4534219.66       | 1.864 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 4665877.00  | 4563626.07       | 2.191 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 4679794.00  | 4593032.49       | 1.854 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 4746588.00  | 4622438.90       | 2.616 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 4758923.00  | 4651845.32       | 2.25 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 4807569.00  | 4681251.73       | 2.627 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 4838354.00  | 4710658.15       | 2.639 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 4861992.00  | 4740064.56       | 2.508 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 4901955.00  | 4769470.98       | 2.703 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 4945238.00  | 4798877.39       | 2.96 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 4980133.00  | 4828283.81       | 3.049 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 4987689.00  | 4857690.22       | 2.606 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 5026645.00  | 4887096.64       | 2.776 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 5069999.00  | 4916503.06       | 3.028 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 5107935.00  | 4945909.47       | 3.172 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 5144295.00  | 4975315.89       | 3.285 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 5178513.00  | 5004722.30       | 3.356 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 5207857.00  | 5034128.72       | 3.336 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 5214493.00  | 5063535.13       | 2.895 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 5257046.00  | 5092941.55       | 3.122 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 5291414.00  | 5122347.96       | 3.195 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 5325448.00  | 5151754.38       | 3.262 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 5357640.00  | 5181160.79       | 3.294 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 5388524.00  | 5210567.21       | 3.303 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 5412989.00  | 5239973.62       | 3.196 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 5417903.00  | 5269380.04       | 2.741 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 5447883.00  | 5298786.45       | 2.737 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 5479327.00  | 5328192.87       | 2.758 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 5505700.00  | 5357599.29       | 2.69 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 5529820.00  | 5387005.70       | 2.583 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 5553806.00  | 5416412.12       | 2.474 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 5563694.00  | 5445818.53       | 2.119 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 5567300.00  | 5475224.95       | 1.654 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 5590416.00  | 5504631.36       | 1.534 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 5616180.00  | 5534037.78       | 1.463 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 5637744.00  | 5563444.19       | 1.318 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 5655548.00  | 5592850.61       | 1.109 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 5622257.02          | 5205680.75 | 4985158.59 | 5205680.75 | 4985158.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 5651663.44          | 5222537.44 | 4995371.86 | 5222537.44 | 4995371.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 5681069.85          | 5239270.94 | 5005396.73 | 5239270.94 | 5005396.73 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 5710476.27          | 5255882.43 | 5015234.98 | 5255882.43 | 5015234.98 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 5739882.69          | 5272373.04 | 5024888.38 | 5272373.04 | 5024888.38 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 5769289.10          | 5288743.89 | 5034358.62 | 5288743.89 | 5034358.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 5798695.52          | 5304996.06 | 5043647.36 | 5304996.06 | 5043647.36 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 5828101.93          | 5321130.62 | 5052756.22 | 5321130.62 | 5052756.22 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 5857508.35          | 5337148.57 | 5061686.75 | 5337148.57 | 5061686.75 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 5886914.76          | 5353050.94 | 5070440.50 | 5353050.94 | 5070440.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 5916321.18          | 5368838.68 | 5079018.95 | 5368838.68 | 5079018.95 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 5945727.59          | 5384512.76 | 5087423.57 | 5384512.76 | 5087423.57 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 5975134.01          | 5400074.09 | 5095655.76 | 5400074.09 | 5095655.76 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 6004540.42          | 5415523.60 | 5103716.93 | 5415523.60 | 5103716.93 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 6033946.84          | 5430862.15 | 5111608.41 | 5430862.15 | 5111608.41 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 6063353.25          | 5446090.63 | 5119331.53 | 5446090.63 | 5119331.53 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 6092759.67          | 5461209.86 | 5126887.59 | 5461209.86 | 5126887.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 6122166.09          | 5476220.68 | 5134277.85 | 5476220.68 | 5134277.85 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 6151572.50          | 5491123.90 | 5141503.53 | 5491123.90 | 5141503.53 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 6180978.92          | 5505920.30 | 5148565.86 | 5505920.30 | 5148565.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 6210385.33          | 5520610.66 | 5155466.00 | 5520610.66 | 5155466.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 6239791.75          | 5535195.73 | 5162205.13 | 5535195.73 | 5162205.13 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
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 232.1378 5614.593 3089.737 NaN  Inf 0.3224012 -0.01652168
# Print Model Parameters
model_TBATS
## TBATS(1, {0,0}, 1, {<6,2>})
## 
## Call: NULL
## 
## Parameters
##   Alpha: 1.290922
##   Beta: 0.2829251
##   Damping Parameter: 1
##   Gamma-1 Values: -0.000896665
##   Gamma-2 Values: 0.002517207
## 
## Seed States:
##             [,1]
## [1,]  160.074320
## [2,]   -9.155408
## [3,] -118.783393
## [4,] -151.336371
## [5,] -344.857365
## [6,] -193.177994
## 
## Sigma: 5614.593
## AIC: 10465.86
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 France"
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 France"
paste(MAPE_Mean_All.TBATS,"%")
## [1] "2.32 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in France %"
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 France"
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                | 4306105.00  | 4298314.77        | 0.181 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 2  | 2021-03-26 | Friday                  | 4351506.00  | 4328381.67        | 0.531 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 3  | 2021-03-27 | Saturday                | 4393375.00  | 4358141.53        | 0.802 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 4  | 2021-03-28 | Sunday                  | 4435187.00  | 4386226.89        | 1.104 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 5  | 2021-03-29 | Monday                  | 4472201.00  | 4415711.52        | 1.263 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 6  | 2021-03-30 | Tuesday                 | 4481295.00  | 4445605.48        | 0.796 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 7  | 2021-03-31 | Wednesday               | 4510870.00  | 4474407.22        | 0.808 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 8  | 2021-04-01 | Thursday                | 4569698.00  | 4504474.12        | 1.427 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 9  | 2021-04-02 | Friday                  | 4620357.00  | 4534233.98        | 1.864 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 10 | 2021-04-03 | Saturday                | 4665877.00  | 4562319.34        | 2.219 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 11 | 2021-04-04 | Sunday                  | 4679794.00  | 4591803.97        | 1.88 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 12 | 2021-04-05 | Monday                  | 4746588.00  | 4621697.93        | 2.631 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 13 | 2021-04-06 | Tuesday                 | 4758923.00  | 4650499.67        | 2.278 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 14 | 2021-04-07 | Wednesday               | 4807569.00  | 4680566.57        | 2.642 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 15 | 2021-04-08 | Thursday                | 4838354.00  | 4710326.43        | 2.646 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 16 | 2021-04-09 | Friday                  | 4861992.00  | 4738411.79        | 2.542 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 17 | 2021-04-10 | Saturday                | 4901955.00  | 4767896.42        | 2.735 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 18 | 2021-04-11 | Sunday                  | 4945238.00  | 4797790.38        | 2.982 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 19 | 2021-04-12 | Monday                  | 4980133.00  | 4826592.12        | 3.083 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 20 | 2021-04-13 | Tuesday                 | 4987689.00  | 4856659.02        | 2.627 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 21 | 2021-04-14 | Wednesday               | 5026645.00  | 4886418.88        | 2.79 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 22 | 2021-04-15 | Thursday                | 5069999.00  | 4914504.24        | 3.067 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 23 | 2021-04-16 | Friday                  | 5107935.00  | 4943988.87        | 3.21 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 24 | 2021-04-17 | Saturday                | 5144295.00  | 4973882.83        | 3.313 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 25 | 2021-04-18 | Sunday                  | 5178513.00  | 5002684.57        | 3.395 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 26 | 2021-04-19 | Monday                  | 5207857.00  | 5032751.47        | 3.362 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 27 | 2021-04-20 | Tuesday                 | 5214493.00  | 5062511.33        | 2.915 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 28 | 2021-04-21 | Wednesday               | 5257046.00  | 5090596.69        | 3.166 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 29 | 2021-04-22 | Thursday                | 5291414.00  | 5120081.32        | 3.238 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 30 | 2021-04-23 | Friday                  | 5325448.00  | 5149975.28        | 3.295 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 31 | 2021-04-24 | Saturday                | 5357640.00  | 5178777.02        | 3.338 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 32 | 2021-04-25 | Sunday                  | 5388524.00  | 5208843.92        | 3.334 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 33 | 2021-04-26 | Monday                  | 5412989.00  | 5238603.78        | 3.222 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 34 | 2021-04-27 | Tuesday                 | 5417903.00  | 5266689.14        | 2.791 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 35 | 2021-04-28 | Wednesday               | 5447883.00  | 5296173.77        | 2.785 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 36 | 2021-04-29 | Thursday                | 5479327.00  | 5326067.73        | 2.797 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 37 | 2021-04-30 | Friday                  | 5505700.00  | 5354869.47        | 2.74 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 38 | 2021-05-01 | Saturday                | 5529820.00  | 5384936.37        | 2.62 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 39 | 2021-05-02 | Sunday                  | 5553806.00  | 5414696.23        | 2.505 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 40 | 2021-05-03 | Monday                  | 5563694.00  | 5442781.59        | 2.173 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 41 | 2021-05-04 | Tuesday                 | 5567300.00  | 5472266.22        | 1.707 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 42 | 2021-05-05 | Wednesday               | 5590416.00  | 5502160.18        | 1.579 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 43 | 2021-05-06 | Thursday                | 5616180.00  | 5530961.92        | 1.517 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 44 | 2021-05-07 | Friday                  | 5637744.00  | 5561028.82        | 1.361 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 45 | 2021-05-08 | Saturday                | 5655548.00  | 5590788.68        | 1.145 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
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          | 5618874.04           | 5557131.93 | 5524447.64 | 5680616.14 | 5713300.43 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 5648358.67           | 5585961.68 | 5552930.71 | 5710755.65 | 5743786.62 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 5678252.63           | 5615215.06 | 5581844.98 | 5741290.21 | 5774660.29 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 5707054.37           | 5643384.46 | 5609679.65 | 5770724.28 | 5804429.09 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 5737121.27           | 5672820.63 | 5638781.92 | 5801421.92 | 5835460.62 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 5766881.13           | 5701957.91 | 5667589.63 | 5831804.35 | 5866172.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 5794966.49           | 5729426.60 | 5694731.88 | 5860506.37 | 5895201.09 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 5824451.12           | 5758299.19 | 5723280.48 | 5890603.04 | 5925621.75 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 5854345.08           | 5787593.78 | 5752257.78 | 5921096.38 | 5956432.39 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 5883146.82           | 5815803.18 | 5780153.61 | 5950490.46 | 5986140.03 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 5913213.72           | 5845278.55 | 5809315.84 | 5981148.89 | 6017111.60 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 5942973.58           | 5874453.90 | 5838181.77 | 6011493.26 | 6047765.38 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 5971058.94           | 5901959.69 | 5865380.76 | 6040158.18 | 6076737.11 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 6000543.57           | 5930868.52 | 5893984.78 | 6070218.61 | 6107102.35 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 6030437.53           | 5960198.07 | 5923015.55 | 6100676.99 | 6137859.52 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 6059239.27           | 5988441.51 | 5950963.44 | 6130037.03 | 6167515.10 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 6089306.17           | 6017950.35 | 5980176.86 | 6160661.99 | 6198435.48 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 6119066.03           | 6047158.29 | 6009092.64 | 6190973.76 | 6229039.42 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 6147151.38           | 6074695.94 | 6036340.35 | 6219606.83 | 6257962.42 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 6176636.02           | 6103635.97 | 6064992.07 | 6249636.06 | 6288279.96 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 6206529.98           | 6132995.70 | 6094069.00 | 6280064.27 | 6318990.96 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 6235331.72           | 6161268.60 | 6122061.95 | 6309394.84 | 6348601.49 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 -105.5575 5961.603 3088.36 NaN  Inf 0.3222575 0.1966511
# 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.3856 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
##     beta  = 0.3264 
## 
##   Initial states:
##     l = -3.2597 
##     b = -0.2384 
## 
##   sigma:  1.1205
## 
##      AIC     AICc      BIC 
## 2835.533 2835.669 2856.045 
## 
## Training set error measures:
##                     ME     RMSE     MAE MPE MAPE      MASE      ACF1
## Training set -105.5575 5961.603 3088.36 NaN  Inf 0.3222575 0.1966511
# 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 France"
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 France"
paste(MAPE_Mean_All.Holt,"%")
## [1] "1.229 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in France %"
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 France"
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                | 4306105.00  | 4303684.84       | 0.056 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 4351506.00  | 4334790.13       | 0.384 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 4393375.00  | 4366033.16       | 0.622 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 4435187.00  | 4397414.17       | 0.852 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 4472201.00  | 4428933.37       | 0.967 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 4481295.00  | 4460591.00       | 0.462 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 4510870.00  | 4492387.27       | 0.41 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 4569698.00  | 4524322.41       | 0.993 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 4620357.00  | 4556396.66       | 1.384 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 4665877.00  | 4588610.23       | 1.656 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 4679794.00  | 4620963.35       | 1.257 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 4746588.00  | 4653456.24       | 1.962 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 4758923.00  | 4686089.13       | 1.53 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 4807569.00  | 4718862.24       | 1.845 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 4838354.00  | 4751775.79       | 1.789 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 4861992.00  | 4784830.02       | 1.587 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 4901955.00  | 4818025.13       | 1.712 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 4945238.00  | 4851361.36       | 1.898 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 4980133.00  | 4884838.93       | 1.913 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 4987689.00  | 4918458.06       | 1.388 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 5026645.00  | 4952218.98       | 1.481 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 5069999.00  | 4986121.89       | 1.654 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 5107935.00  | 5020167.04       | 1.718 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 5144295.00  | 5054354.63       | 1.748 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 5178513.00  | 5088684.89       | 1.735 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 5207857.00  | 5123158.05       | 1.626 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 5214493.00  | 5157774.31       | 1.088 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 5257046.00  | 5192533.91       | 1.227 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 5291414.00  | 5227437.06       | 1.209 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 5325448.00  | 5262483.98       | 1.182 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 5357640.00  | 5297674.90       | 1.119 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 5388524.00  | 5333010.03       | 1.03 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 5412989.00  | 5368489.59       | 0.822 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 5417903.00  | 5404113.81       | 0.255 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 5447883.00  | 5439882.89       | 0.147 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 5479327.00  | 5475797.06       | 0.064 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 5505700.00  | 5511856.55       | 0.112 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 5529820.00  | 5548061.55       | 0.33 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 5553806.00  | 5584412.31       | 0.551 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 5563694.00  | 5620909.02       | 1.028 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 5567300.00  | 5657551.92       | 1.621 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 5590416.00  | 5694341.21       | 1.859 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 5616180.00  | 5731277.12       | 2.049 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 5637744.00  | 5768359.86       | 2.317 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 5655548.00  | 5805589.65       | 2.653 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 5842966.71          | 4616723.83 | 4038013.60 | 7251200.18 | 8073503.07  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 2  | 2021-05-10 | Monday          | 5880491.25          | 4613779.02 | 4018096.16 | 7340953.90 | 8195964.50  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 3  | 2021-05-11 | Tuesday         | 5918163.48          | 4610477.39 | 3997737.63 | 7431866.94 | 8320347.38  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 4  | 2021-05-12 | Wednesday       | 5955983.63          | 4606822.95 | 3976947.60 | 7523947.30 | 8446669.57  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 5  | 2021-05-13 | Thursday        | 5993951.91          | 4602819.67 | 3955735.56 | 7617203.06 | 8574949.11  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 6  | 2021-05-14 | Friday          | 6032068.54          | 4598471.45 | 3934110.88 | 7711642.44 | 8705204.26  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 7  | 2021-05-15 | Saturday        | 6070333.72          | 4593782.14 | 3912082.86 | 7807273.74 | 8837453.49  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 8  | 2021-05-16 | Sunday          | 6108747.68          | 4588755.55 | 3889660.69 | 7904105.37 | 8971715.47  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 9  | 2021-05-17 | Monday          | 6147310.63          | 4583395.43 | 3866853.49 | 8002145.82 | 9108009.07  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 10 | 2021-05-18 | Tuesday         | 6186022.79          | 4577705.48 | 3843670.29 | 8101403.70 | 9246353.34  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 11 | 2021-05-19 | Wednesday       | 6224884.37          | 4571689.39 | 3820120.04 | 8201887.69 | 9386767.53  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 12 | 2021-05-20 | Thursday        | 6263895.58          | 4565350.76 | 3796211.60 | 8303606.57 | 9529271.08  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 13 | 2021-05-21 | Friday          | 6303056.64          | 4558693.21 | 3771953.79 | 8406569.19 | 9673883.60  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 14 | 2021-05-22 | Saturday        | 6342367.76          | 4551720.26 | 3747355.32 | 8510784.51 | 9820624.87  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 15 | 2021-05-23 | Sunday          | 6381829.16          | 4544435.46 | 3722424.85 | 8616261.55 | 9969514.87  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 16 | 2021-05-24 | Monday          | 6421441.04          | 4536842.28 | 3697170.99 | 8723009.42 | 10120573.75 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 17 | 2021-05-25 | Tuesday         | 6461203.63          | 4528944.18 | 3671602.26 | 8831037.32 | 10273821.80 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 18 | 2021-05-26 | Wednesday       | 6501117.13          | 4520744.60 | 3645727.12 | 8940354.50 | 10429279.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 19 | 2021-05-27 | Thursday        | 6541181.76          | 4512246.92 | 3619553.99 | 9050970.30 | 10586967.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 20 | 2021-05-28 | Friday          | 6581397.73          | 4503454.52 | 3593091.21 | 9162894.14 | 10746906.61 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 21 | 2021-05-29 | Saturday        | 6621765.26          | 4494370.76 | 3566347.06 | 9276135.50 | 10909117.78 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 22 | 2021-05-30 | Sunday          | 6662284.55          | 4484998.94 | 3539329.79 | 9390703.95 | 11073622.15 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
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 France"
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 = 6.2506, 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.55251, 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 = -1.1108, Lag order = 7, p-value = 0.9205
## 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 France"
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.4963, Truncation lag parameter = 5, p-value = 0.01
pp.test(diff1_x1)     # applay pp test after taking first differences
## Warning in pp.test(diff1_x1): p-value smaller than printed p-value
## 
##  Phillips-Perron Unit Root Test
## 
## data:  diff1_x1
## Dickey-Fuller Z(alpha) = -91.204, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
adf.test(diff1_x1)    # applay adf test after taking first differences
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff1_x1
## Dickey-Fuller = -1.9997, Lag order = 7, p-value = 0.5779
## 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 France"
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.020907, 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) = -392.27, 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 = -8.9684, 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)                    : 9072.473
##  ARIMA(0,2,1)                    : 8996.876
##  ARIMA(0,2,2)                    : 8959.9
##  ARIMA(0,2,3)                    : 8960.289
##  ARIMA(0,2,4)                    : 8955.005
##  ARIMA(0,2,5)                    : 8934.262
##  ARIMA(1,2,0)                    : 9051.528
##  ARIMA(1,2,1)                    : 8970.142
##  ARIMA(1,2,2)                    : 8960.529
##  ARIMA(1,2,3)                    : 8959.941
##  ARIMA(1,2,4)                    : 8926.156
##  ARIMA(2,2,0)                    : 9012.95
##  ARIMA(2,2,1)                    : 8957.784
##  ARIMA(2,2,2)                    : Inf
##  ARIMA(2,2,3)                    : 8922.909
##  ARIMA(3,2,0)                    : 9002.024
##  ARIMA(3,2,1)                    : 8957.501
##  ARIMA(3,2,2)                    : Inf
##  ARIMA(4,2,0)                    : 8980.252
##  ARIMA(4,2,1)                    : 8943.549
##  ARIMA(5,2,0)                    : 8950.501
## 
## 
## 
##  Best model: ARIMA(2,2,3)
model1 # show the result of autoarima 
## Series: data_series 
## ARIMA(2,2,3) 
## 
## Coefficients:
##          ar1      ar2      ma1     ma2     ma3
##       1.1076  -0.3667  -1.6487  0.6203  0.1407
## s.e.  0.1229   0.1167   0.1307  0.2338  0.1112
## 
## sigma^2 estimated as 29297132:  log likelihood=-4455.36
## AIC=8922.72   AICc=8922.91   BIC=8947.31
#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 3
strtoi(bestmodel[3])
## [1] 3
#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     ma3
##       1.1076  -0.3667  -1.6487  0.6203  0.1407
## s.e.  0.1229   0.1167   0.1307  0.2338  0.1112
## 
## sigma^2 estimated as 28967951:  log likelihood = -4455.36,  aic = 8922.72
paste ("accuracy of autoarima Model For  ==> ",y_lab, sep=" ")
## [1] "accuracy of autoarima Model For  ==>  Forecasting cumulative Covid 19 Infection cases in France"
accuracy(x1_model1)  # aacuracy of best model from auto arima
##                    ME     RMSE      MAE       MPE     MAPE      MASE
## Training set 183.0749 5370.134 2783.803 0.8889177 2.064387 0.2904783
##                      ACF1
## Training set -0.004684419
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,3)
## Q* = 68.002, df = 5, p-value = 2.668e-13
## 
## Model df: 5.   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 France"
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 = 518.7, 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 = 1441.9, 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 France"
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 France"
paste(MAPE_Mean_All.ARIMA,"%")
## [1] "0.909 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in France %"
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 France"
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                | 4306105.00  | 4302788.93             | 0.077 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 2  | 2021-03-26      | Friday                  | 4351506.00  | 4338307.41             | 0.303 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 3  | 2021-03-27      | Saturday                | 4393375.00  | 4375811.31             | 0.4 %                 |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 4  | 2021-03-28      | Sunday                  | 4435187.00  | 4413517.41             | 0.489 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 5  | 2021-03-29      | Monday                  | 4472201.00  | 4450719.43             | 0.48 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 6  | 2021-03-30      | Tuesday                 | 4481295.00  | 4487289.00             | 0.134 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 7  | 2021-03-31      | Wednesday               | 4510870.00  | 4523342.94             | 0.277 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 8  | 2021-04-01      | Thursday                | 4569698.00  | 4559057.67             | 0.233 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 9  | 2021-04-02      | Friday                  | 4620357.00  | 4594585.78             | 0.558 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 10 | 2021-04-03      | Saturday                | 4665877.00  | 4630031.59             | 0.768 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 11 | 2021-04-04      | Sunday                  | 4679794.00  | 4665454.65             | 0.306 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 12 | 2021-04-05      | Monday                  | 4746588.00  | 4700882.72             | 0.963 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 13 | 2021-04-06      | Tuesday                 | 4758923.00  | 4736324.66             | 0.475 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 14 | 2021-04-07      | Wednesday               | 4807569.00  | 4771780.14             | 0.744 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 15 | 2021-04-08      | Thursday                | 4838354.00  | 4807245.52             | 0.643 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 16 | 2021-04-09      | Friday                  | 4861992.00  | 4842716.91             | 0.396 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 17 | 2021-04-10      | Saturday                | 4901955.00  | 4878191.31             | 0.485 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 18 | 2021-04-11      | Sunday                  | 4945238.00  | 4913666.86             | 0.638 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 19 | 2021-04-12      | Monday                  | 4980133.00  | 4949142.56             | 0.622 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 20 | 2021-04-13      | Tuesday                 | 4987689.00  | 4984618.02             | 0.062 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 21 | 2021-04-14      | Wednesday               | 5026645.00  | 5020093.16             | 0.13 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 22 | 2021-04-15      | Thursday                | 5069999.00  | 5055568.02             | 0.285 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 23 | 2021-04-16      | Friday                  | 5107935.00  | 5091042.69             | 0.331 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 24 | 2021-04-17      | Saturday                | 5144295.00  | 5126517.27             | 0.346 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 25 | 2021-04-18      | Sunday                  | 5178513.00  | 5161991.80             | 0.319 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 26 | 2021-04-19      | Monday                  | 5207857.00  | 5197466.31             | 0.2 %                 |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 27 | 2021-04-20      | Tuesday                 | 5214493.00  | 5232940.83             | 0.354 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 28 | 2021-04-21      | Wednesday               | 5257046.00  | 5268415.35             | 0.216 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 29 | 2021-04-22      | Thursday                | 5291414.00  | 5303889.88             | 0.236 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 30 | 2021-04-23      | Friday                  | 5325448.00  | 5339364.42             | 0.261 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 31 | 2021-04-24      | Saturday                | 5357640.00  | 5374838.96             | 0.321 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 32 | 2021-04-25      | Sunday                  | 5388524.00  | 5410313.50             | 0.404 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 33 | 2021-04-26      | Monday                  | 5412989.00  | 5445788.04             | 0.606 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 34 | 2021-04-27      | Tuesday                 | 5417903.00  | 5481262.58             | 1.169 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 35 | 2021-04-28      | Wednesday               | 5447883.00  | 5516737.12             | 1.264 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 36 | 2021-04-29      | Thursday                | 5479327.00  | 5552211.66             | 1.33 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 37 | 2021-04-30      | Friday                  | 5505700.00  | 5587686.20             | 1.489 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 38 | 2021-05-01      | Saturday                | 5529820.00  | 5623160.75             | 1.688 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 39 | 2021-05-02      | Sunday                  | 5553806.00  | 5658635.29             | 1.888 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 40 | 2021-05-03      | Monday                  | 5563694.00  | 5694109.83             | 2.344 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 41 | 2021-05-04      | Tuesday                 | 5567300.00  | 5729584.37             | 2.915 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 42 | 2021-05-05      | Wednesday               | 5590416.00  | 5765058.91             | 3.124 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 43 | 2021-05-06      | Thursday                | 5616180.00  | 5800533.45             | 3.283 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 44 | 2021-05-07      | Friday                  | 5637744.00  | 5836007.99             | 3.517 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 45 | 2021-05-08      | Saturday                | 5655548.00  | 5871482.53             | 3.818 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
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          | 5906957.07                | 5386724.44 | 5111329.92 | 6427189.71 | 6702584.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 5942431.61                | 5404756.47 | 5120128.45 | 6480106.76 | 6764734.78 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 5977906.16                | 5422596.88 | 5128633.91 | 6533215.43 | 6827178.40 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 6013380.70                | 5440247.75 | 5136849.50 | 6586513.64 | 6889911.89 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 6048855.24                | 5457711.11 | 5144778.31 | 6639999.37 | 6952932.16 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 6084329.78                | 5474988.90 | 5152423.33 | 6693670.65 | 7016236.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 6119804.32                | 5492083.03 | 5159787.45 | 6747525.61 | 7079821.19 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 6155278.86                | 5508995.33 | 5166873.50 | 6801562.39 | 7143684.22 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 6190753.40                | 5525727.58 | 5173684.18 | 6855779.22 | 7207822.62 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 6226227.94                | 5542281.52 | 5180222.16 | 6910174.36 | 7272233.73 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 6261702.48                | 5558658.82 | 5186489.99 | 6964746.14 | 7336914.98 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 6297177.02                | 5574861.12 | 5192490.18 | 7019492.93 | 7401863.87 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 6332651.56                | 5590890.00 | 5198225.15 | 7074413.13 | 7467077.98 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 6368126.11                | 5606747.02 | 5203697.27 | 7129505.19 | 7532554.94 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 6403600.65                | 5622433.66 | 5208908.84 | 7184767.63 | 7598292.45 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 6439075.19                | 5637951.41 | 5213862.10 | 7240198.96 | 7664288.27 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 6474549.73                | 5653301.68 | 5218559.23 | 7295797.77 | 7730540.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 6510024.27                | 5668485.87 | 5223002.35 | 7351562.67 | 7797046.19 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 6545498.81                | 5683505.33 | 5227193.55 | 7407492.29 | 7863804.07 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 6580973.35                | 5698361.39 | 5231134.84 | 7463585.31 | 7930811.86 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 6616447.89                | 5713055.34 | 5234828.21 | 7519840.45 | 7998067.57 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 6651922.43                | 5727588.44 | 5238275.58 | 7576256.43 | 8065569.29 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
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] "0.909 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in France"
## 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 France"
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 France"
paste(MAPE_Mean_EnsemblingAverage,"%")
## [1] "0.825 %"
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 France"
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                | 4306105.00  | 4302449.76 | 0.085 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 2  | 2021-03-26      | Friday                  | 4351506.00  | 4337260.42 | 0.327 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 3  | 2021-03-27      | Saturday                | 4393375.00  | 4373834.46 | 0.445 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 4  | 2021-03-28      | Sunday                  | 4435187.00  | 4410531.74 | 0.556 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 5  | 2021-03-29      | Monday                  | 4472201.00  | 4446792.60 | 0.568 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 6  | 2021-03-30      | Tuesday                 | 4481295.00  | 4482476.06 | 0.026 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 7  | 2021-03-31      | Wednesday               | 4510870.00  | 4517649.18 | 0.15 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 8  | 2021-04-01      | Thursday                | 4569698.00  | 4552529.37 | 0.376 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 9  | 2021-04-02      | Friday                  | 4620357.00  | 4587214.50 | 0.717 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 10 | 2021-04-03      | Saturday                | 4665877.00  | 4621764.27 | 0.945 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 11 | 2021-04-04      | Sunday                  | 4679794.00  | 4656309.32 | 0.502 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 12 | 2021-04-05      | Monday                  | 4746588.00  | 4690850.19 | 1.174 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 13 | 2021-04-06      | Tuesday                 | 4758923.00  | 4725357.79 | 0.705 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 14 | 2021-04-07      | Wednesday               | 4807569.00  | 4759891.31 | 0.992 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 15 | 2021-04-08      | Thursday                | 4838354.00  | 4794408.85 | 0.908 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 16 | 2021-04-09      | Friday                  | 4861992.00  | 4828873.47 | 0.681 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 17 | 2021-04-10      | Saturday                | 4901955.00  | 4863360.14 | 0.787 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 18 | 2021-04-11      | Sunday                  | 4945238.00  | 4897843.30 | 0.958 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 19 | 2021-04-12      | Monday                  | 4980133.00  | 4932285.41 | 0.961 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 20 | 2021-04-13      | Tuesday                 | 4987689.00  | 4966745.96 | 0.42 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 21 | 2021-04-14      | Wednesday               | 5026645.00  | 5001186.51 | 0.506 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 22 | 2021-04-15      | Thursday                | 5069999.00  | 5035573.84 | 0.679 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 23 | 2021-04-16      | Friday                  | 5107935.00  | 5069985.79 | 0.743 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 24 | 2021-04-17      | Saturday                | 5144295.00  | 5104398.57 | 0.776 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 25 | 2021-04-18      | Sunday                  | 5178513.00  | 5138775.57 | 0.767 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 26 | 2021-04-19      | Monday                  | 5207857.00  | 5173176.58 | 0.666 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 27 | 2021-04-20      | Tuesday                 | 5214493.00  | 5207563.11 | 0.133 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 28 | 2021-04-21      | Wednesday               | 5257046.00  | 5241901.76 | 0.288 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 29 | 2021-04-22      | Thursday                | 5291414.00  | 5276270.08 | 0.286 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 30 | 2021-04-23      | Friday                  | 5325448.00  | 5310644.02 | 0.278 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 31 | 2021-04-24      | Saturday                | 5357640.00  | 5344986.69 | 0.236 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 32 | 2021-04-25      | Sunday                  | 5388524.00  | 5379357.61 | 0.17 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 33 | 2021-04-26      | Monday                  | 5412989.00  | 5413718.05 | 0.013 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 34 | 2021-04-27      | Tuesday                 | 5417903.00  | 5448034.36 | 0.556 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 35 | 2021-04-28      | Wednesday               | 5447883.00  | 5482383.87 | 0.633 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 36 | 2021-04-29      | Thursday                | 5479327.00  | 5516742.29 | 0.683 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 37 | 2021-04-30      | Friday                  | 5505700.00  | 5551072.51 | 0.824 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 38 | 2021-05-01      | Saturday                | 5529820.00  | 5585433.84 | 1.006 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 39 | 2021-05-02      | Sunday                  | 5553806.00  | 5619787.35 | 1.188 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 40 | 2021-05-03      | Monday                  | 5563694.00  | 5654099.19 | 1.625 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 41 | 2021-05-04      | Tuesday                 | 5567300.00  | 5688446.50 | 2.176 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 42 | 2021-05-05      | Wednesday               | 5590416.00  | 5722804.82 | 2.368 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 43 | 2021-05-06      | Thursday                | 5616180.00  | 5757136.88 | 2.51 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 44 | 2021-05-07      | Friday                  | 5637744.00  | 5791501.83 | 2.727 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 45 | 2021-05-08      | Saturday                | 5655548.00  | 5825860.61 | 3.011 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
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          | 5860179.21                |
## +----+------------+-----------------+---------------------------+
## | 2  | 2021-05-10 | Monday          | 5894534.68                |
## +----+------------+-----------------+---------------------------+
## | 3  | 2021-05-11 | Tuesday         | 5928902.42                |
## +----+------------+-----------------+---------------------------+
## | 4  | 2021-05-12 | Wednesday       | 5963245.06                |
## +----+------------+-----------------+---------------------------+
## | 5  | 2021-05-13 | Thursday        | 5997621.66                |
## +----+------------+-----------------+---------------------------+
## | 6  | 2021-05-14 | Friday          | 6031993.07                |
## +----+------------+-----------------+---------------------------+
## | 7  | 2021-05-15 | Saturday        | 6066325.19                |
## +----+------------+-----------------+---------------------------+
## | 8  | 2021-05-16 | Sunday          | 6100695.00                |
## +----+------------+-----------------+---------------------------+
## | 9  | 2021-05-17 | Monday          | 6135077.83                |
## +----+------------+-----------------+---------------------------+
## | 10 | 2021-05-18 | Tuesday         | 6169436.24                |
## +----+------------+-----------------+---------------------------+
## | 11 | 2021-05-19 | Wednesday       | 6203829.25                |
## +----+------------+-----------------+---------------------------+
## | 12 | 2021-05-20 | Thursday        | 6238217.63                |
## +----+------------+-----------------+---------------------------+
## | 13 | 2021-05-21 | Friday          | 6272567.25                |
## +----+------------+-----------------+---------------------------+
## | 14 | 2021-05-22 | Saturday        | 6306955.04                |
## +----+------------+-----------------+---------------------------+
## | 15 | 2021-05-23 | Sunday          | 6341356.29                |
## +----+------------+-----------------+---------------------------+
## | 16 | 2021-05-24 | Monday          | 6375733.53                |
## +----+------------+-----------------+---------------------------+
## | 17 | 2021-05-25 | Tuesday         | 6410145.73                |
## +----+------------+-----------------+---------------------------+
## | 18 | 2021-05-26 | Wednesday       | 6444553.64                |
## +----+------------+-----------------+---------------------------+
## | 19 | 2021-05-27 | Thursday        | 6478923.11                |
## +----+------------+-----------------+---------------------------+
## | 20 | 2021-05-28 | Friday          | 6513331.02                |
## +----+------------+-----------------+---------------------------+
## | 21 | 2021-05-29 | Saturday        | 6547752.66                |
## +----+------------+-----------------+---------------------------+
## | 22 | 2021-05-30 | Sunday          | 6582150.53                |
## +----+------------+-----------------+---------------------------+
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 France"
best_recommended_model
## [1] 0.825
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 France"
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          | 5622257.02          | 5205680.75 | 4985158.59 | 5205680.75 | 4985158.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 5651663.44          | 5222537.44 | 4995371.86 | 5222537.44 | 4995371.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 5681069.85          | 5239270.94 | 5005396.73 | 5239270.94 | 5005396.73 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 5710476.27          | 5255882.43 | 5015234.98 | 5255882.43 | 5015234.98 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 5739882.69          | 5272373.04 | 5024888.38 | 5272373.04 | 5024888.38 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 5769289.10          | 5288743.89 | 5034358.62 | 5288743.89 | 5034358.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 5798695.52          | 5304996.06 | 5043647.36 | 5304996.06 | 5043647.36 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 5828101.93          | 5321130.62 | 5052756.22 | 5321130.62 | 5052756.22 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 5857508.35          | 5337148.57 | 5061686.75 | 5337148.57 | 5061686.75 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 5886914.76          | 5353050.94 | 5070440.50 | 5353050.94 | 5070440.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 5916321.18          | 5368838.68 | 5079018.95 | 5368838.68 | 5079018.95 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 5945727.59          | 5384512.76 | 5087423.57 | 5384512.76 | 5087423.57 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 5975134.01          | 5400074.09 | 5095655.76 | 5400074.09 | 5095655.76 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 6004540.42          | 5415523.60 | 5103716.93 | 5415523.60 | 5103716.93 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 6033946.84          | 5430862.15 | 5111608.41 | 5430862.15 | 5111608.41 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 6063353.25          | 5446090.63 | 5119331.53 | 5446090.63 | 5119331.53 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 6092759.67          | 5461209.86 | 5126887.59 | 5461209.86 | 5126887.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 6122166.09          | 5476220.68 | 5134277.85 | 5476220.68 | 5134277.85 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 6151572.50          | 5491123.90 | 5141503.53 | 5491123.90 | 5141503.53 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 6180978.92          | 5505920.30 | 5148565.86 | 5505920.30 | 5148565.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 6210385.33          | 5520610.66 | 5155466.00 | 5520610.66 | 5155466.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 6239791.75          | 5535195.73 | 5162205.13 | 5535195.73 | 5162205.13 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using TBATS Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using TBATS Model  ==>  Forecasting cumulative Covid 19 Infection cases in France"
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          | 5618874.04           | 5557131.93 | 5524447.64 | 5680616.14 | 5713300.43 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 5648358.67           | 5585961.68 | 5552930.71 | 5710755.65 | 5743786.62 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 5678252.63           | 5615215.06 | 5581844.98 | 5741290.21 | 5774660.29 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 5707054.37           | 5643384.46 | 5609679.65 | 5770724.28 | 5804429.09 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 5737121.27           | 5672820.63 | 5638781.92 | 5801421.92 | 5835460.62 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 5766881.13           | 5701957.91 | 5667589.63 | 5831804.35 | 5866172.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 5794966.49           | 5729426.60 | 5694731.88 | 5860506.37 | 5895201.09 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 5824451.12           | 5758299.19 | 5723280.48 | 5890603.04 | 5925621.75 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 5854345.08           | 5787593.78 | 5752257.78 | 5921096.38 | 5956432.39 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 5883146.82           | 5815803.18 | 5780153.61 | 5950490.46 | 5986140.03 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 5913213.72           | 5845278.55 | 5809315.84 | 5981148.89 | 6017111.60 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 5942973.58           | 5874453.90 | 5838181.77 | 6011493.26 | 6047765.38 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 5971058.94           | 5901959.69 | 5865380.76 | 6040158.18 | 6076737.11 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 6000543.57           | 5930868.52 | 5893984.78 | 6070218.61 | 6107102.35 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 6030437.53           | 5960198.07 | 5923015.55 | 6100676.99 | 6137859.52 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 6059239.27           | 5988441.51 | 5950963.44 | 6130037.03 | 6167515.10 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 6089306.17           | 6017950.35 | 5980176.86 | 6160661.99 | 6198435.48 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 6119066.03           | 6047158.29 | 6009092.64 | 6190973.76 | 6229039.42 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 6147151.38           | 6074695.94 | 6036340.35 | 6219606.83 | 6257962.42 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 6176636.02           | 6103635.97 | 6064992.07 | 6249636.06 | 6288279.96 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 6206529.98           | 6132995.70 | 6094069.00 | 6280064.27 | 6318990.96 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 6235331.72           | 6161268.60 | 6122061.95 | 6309394.84 | 6348601.49 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 France"
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          | 5842966.71          | 4616723.83 | 4038013.60 | 7251200.18 | 8073503.07  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 2  | 2021-05-10 | Monday          | 5880491.25          | 4613779.02 | 4018096.16 | 7340953.90 | 8195964.50  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 3  | 2021-05-11 | Tuesday         | 5918163.48          | 4610477.39 | 3997737.63 | 7431866.94 | 8320347.38  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 4  | 2021-05-12 | Wednesday       | 5955983.63          | 4606822.95 | 3976947.60 | 7523947.30 | 8446669.57  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 5  | 2021-05-13 | Thursday        | 5993951.91          | 4602819.67 | 3955735.56 | 7617203.06 | 8574949.11  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 6  | 2021-05-14 | Friday          | 6032068.54          | 4598471.45 | 3934110.88 | 7711642.44 | 8705204.26  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 7  | 2021-05-15 | Saturday        | 6070333.72          | 4593782.14 | 3912082.86 | 7807273.74 | 8837453.49  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 8  | 2021-05-16 | Sunday          | 6108747.68          | 4588755.55 | 3889660.69 | 7904105.37 | 8971715.47  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 9  | 2021-05-17 | Monday          | 6147310.63          | 4583395.43 | 3866853.49 | 8002145.82 | 9108009.07  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 10 | 2021-05-18 | Tuesday         | 6186022.79          | 4577705.48 | 3843670.29 | 8101403.70 | 9246353.34  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 11 | 2021-05-19 | Wednesday       | 6224884.37          | 4571689.39 | 3820120.04 | 8201887.69 | 9386767.53  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 12 | 2021-05-20 | Thursday        | 6263895.58          | 4565350.76 | 3796211.60 | 8303606.57 | 9529271.08  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 13 | 2021-05-21 | Friday          | 6303056.64          | 4558693.21 | 3771953.79 | 8406569.19 | 9673883.60  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 14 | 2021-05-22 | Saturday        | 6342367.76          | 4551720.26 | 3747355.32 | 8510784.51 | 9820624.87  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 15 | 2021-05-23 | Sunday          | 6381829.16          | 4544435.46 | 3722424.85 | 8616261.55 | 9969514.87  |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 16 | 2021-05-24 | Monday          | 6421441.04          | 4536842.28 | 3697170.99 | 8723009.42 | 10120573.75 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 17 | 2021-05-25 | Tuesday         | 6461203.63          | 4528944.18 | 3671602.26 | 8831037.32 | 10273821.80 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 18 | 2021-05-26 | Wednesday       | 6501117.13          | 4520744.60 | 3645727.12 | 8940354.50 | 10429279.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 19 | 2021-05-27 | Thursday        | 6541181.76          | 4512246.92 | 3619553.99 | 9050970.30 | 10586967.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 20 | 2021-05-28 | Friday          | 6581397.73          | 4503454.52 | 3593091.21 | 9162894.14 | 10746906.61 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 21 | 2021-05-29 | Saturday        | 6621765.26          | 4494370.76 | 3566347.06 | 9276135.50 | 10909117.78 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
## | 22 | 2021-05-30 | Sunday          | 6662284.55          | 4484998.94 | 3539329.79 | 9390703.95 | 11073622.15 |
## +----+------------+-----------------+---------------------+------------+------------+------------+-------------+
paste("Forecasting by using ARIMA Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using ARIMA Model  ==>  Forecasting cumulative Covid 19 Infection cases in France"
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          | 5906957.07                | 5386724.44 | 5111329.92 | 6427189.71 | 6702584.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 5942431.61                | 5404756.47 | 5120128.45 | 6480106.76 | 6764734.78 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 5977906.16                | 5422596.88 | 5128633.91 | 6533215.43 | 6827178.40 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 6013380.70                | 5440247.75 | 5136849.50 | 6586513.64 | 6889911.89 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 6048855.24                | 5457711.11 | 5144778.31 | 6639999.37 | 6952932.16 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 6084329.78                | 5474988.90 | 5152423.33 | 6693670.65 | 7016236.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 6119804.32                | 5492083.03 | 5159787.45 | 6747525.61 | 7079821.19 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 6155278.86                | 5508995.33 | 5166873.50 | 6801562.39 | 7143684.22 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 6190753.40                | 5525727.58 | 5173684.18 | 6855779.22 | 7207822.62 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 6226227.94                | 5542281.52 | 5180222.16 | 6910174.36 | 7272233.73 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 6261702.48                | 5558658.82 | 5186489.99 | 6964746.14 | 7336914.98 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 6297177.02                | 5574861.12 | 5192490.18 | 7019492.93 | 7401863.87 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 6332651.56                | 5590890.00 | 5198225.15 | 7074413.13 | 7467077.98 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 6368126.11                | 5606747.02 | 5203697.27 | 7129505.19 | 7532554.94 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 6403600.65                | 5622433.66 | 5208908.84 | 7184767.63 | 7598292.45 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 6439075.19                | 5637951.41 | 5213862.10 | 7240198.96 | 7664288.27 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 6474549.73                | 5653301.68 | 5218559.23 | 7295797.77 | 7730540.23 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 6510024.27                | 5668485.87 | 5223002.35 | 7351562.67 | 7797046.19 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 6545498.81                | 5683505.33 | 5227193.55 | 7407492.29 | 7863804.07 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 6580973.35                | 5698361.39 | 5231134.84 | 7463585.31 | 7930811.86 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 6616447.89                | 5713055.34 | 5234828.21 | 7519840.45 | 7998067.57 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 6651922.43                | 5727588.44 | 5238275.58 | 7576256.43 | 8065569.29 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
paste("Forecasting by using NNAR Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using NNAR Model  ==>  Forecasting cumulative Covid 19 Infection cases in France"
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          | 4672616.02          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 4673335.54          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 4673989.20          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 4674582.93          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 4675122.17          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 4675611.85          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 4676056.49          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 4676460.18          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 4676826.67          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 4677159.36          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 4677461.34          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 4677735.43          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 4677984.19          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 4678209.95          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 4678414.83          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 4678600.74          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 4678769.45          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 4678922.52          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 4679061.42          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 4679187.44          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 4679301.78          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 4679405.52          |
## +----+------------+-----------------+---------------------+
paste("Forecasting by using Ensembling Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using Ensembling Model  ==>  Forecasting cumulative Covid 19 Infection cases in France"
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          | 5860179.21             |
## +----+------------+-----------------+------------------------+
## | 2  | 2021-05-10 | Monday          | 5894534.68             |
## +----+------------+-----------------+------------------------+
## | 3  | 2021-05-11 | Tuesday         | 5928902.42             |
## +----+------------+-----------------+------------------------+
## | 4  | 2021-05-12 | Wednesday       | 5963245.06             |
## +----+------------+-----------------+------------------------+
## | 5  | 2021-05-13 | Thursday        | 5997621.66             |
## +----+------------+-----------------+------------------------+
## | 6  | 2021-05-14 | Friday          | 6031993.07             |
## +----+------------+-----------------+------------------------+
## | 7  | 2021-05-15 | Saturday        | 6066325.19             |
## +----+------------+-----------------+------------------------+
## | 8  | 2021-05-16 | Sunday          | 6100695.00             |
## +----+------------+-----------------+------------------------+
## | 9  | 2021-05-17 | Monday          | 6135077.83             |
## +----+------------+-----------------+------------------------+
## | 10 | 2021-05-18 | Tuesday         | 6169436.24             |
## +----+------------+-----------------+------------------------+
## | 11 | 2021-05-19 | Wednesday       | 6203829.25             |
## +----+------------+-----------------+------------------------+
## | 12 | 2021-05-20 | Thursday        | 6238217.63             |
## +----+------------+-----------------+------------------------+
## | 13 | 2021-05-21 | Friday          | 6272567.25             |
## +----+------------+-----------------+------------------------+
## | 14 | 2021-05-22 | Saturday        | 6306955.04             |
## +----+------------+-----------------+------------------------+
## | 15 | 2021-05-23 | Sunday          | 6341356.29             |
## +----+------------+-----------------+------------------------+
## | 16 | 2021-05-24 | Monday          | 6375733.53             |
## +----+------------+-----------------+------------------------+
## | 17 | 2021-05-25 | Tuesday         | 6410145.73             |
## +----+------------+-----------------+------------------------+
## | 18 | 2021-05-26 | Wednesday       | 6444553.64             |
## +----+------------+-----------------+------------------------+
## | 19 | 2021-05-27 | Thursday        | 6478923.11             |
## +----+------------+-----------------+------------------------+
## | 20 | 2021-05-28 | Friday          | 6513331.02             |
## +----+------------+-----------------+------------------------+
## | 21 | 2021-05-29 | Saturday        | 6547752.66             |
## +----+------------+-----------------+------------------------+
## | 22 | 2021-05-30 | Sunday          | 6582150.53             |
## +----+------------+-----------------+------------------------+
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 | France       | 9.37       | 2.291      | 2.32        | 1.229      | 0.909       | 0.825       | 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 France
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 France