comparison between two systems for forecasting covid 19 cumulative infected case

cumulative Covid 19 Infection cases In Poland
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 Poland"   # 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<- FALSE     #create new model (TRUE/FALSE)
frequency<-"days"
country.name <- "Poland"
# Data Preparation & calculate some of statistics measures
summary(original_data) # Summary your time series
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0   13928   69475  649461 1334098 2829196
# calculate standard deviation 
data.frame(kurtosis=kurtosis(original_data))   # calculate Cofficient of kurtosis
##   kurtosis
## 1 2.874348
data.frame(skewness=skewness(original_data))  # calculate Cofficient of skewness
##   skewness
## 1 1.102134
data.frame(Standard.deviation =sd(original_data))
##   Standard.deviation
## 1           874962.9
#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
}
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
}
## 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 5925916
# 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 Poland"
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 Poland"
paste(MAPE_Mean_All,"%")
## [1] "2.897 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Poland %"
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 Poland"
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                | 2154821.00  | 2146550.26       | 0.384 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 2189966.00  | 2173014.64       | 0.774 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 2221725.00  | 2199951.58       | 0.98 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 2250991.00  | 2227223.73       | 1.056 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 2267964.00  | 2254669.71       | 0.586 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 2288826.00  | 2282106.60       | 0.294 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 2321717.00  | 2309334.20       | 0.533 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 2356970.00  | 2336141.25       | 0.884 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 2387511.00  | 2362313.16       | 1.055 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 2415584.00  | 2387640.75       | 1.157 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 2438542.00  | 2411929.32       | 1.091 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 2448463.00  | 2435007.12       | 0.55 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 2456709.00  | 2456732.40       | 0.001 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 2471617.00  | 2476998.37       | 0.218 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 2499507.00  | 2495735.65       | 0.151 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 2528006.00  | 2512912.25       | 0.597 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 2552898.00  | 2528531.22       | 0.954 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 2574631.00  | 2542626.54       | 1.243 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 2586647.00  | 2555257.82       | 1.214 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 2599850.00  | 2566504.48       | 1.283 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 2621116.00  | 2576459.89       | 1.704 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 2642242.00  | 2585226.00       | 2.158 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 2660088.00  | 2592908.62       | 2.525 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 2675874.00  | 2599613.55       | 2.85 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 2688025.00  | 2605443.66       | 3.072 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 2695327.00  | 2610496.68       | 3.147 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 2704571.00  | 2614863.80       | 3.317 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 2718493.00  | 2618628.82       | 3.674 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 2731256.00  | 2621867.81       | 4.005 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 2742122.00  | 2624649.12       | 4.284 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 2751632.00  | 2627033.61       | 4.528 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 2758856.00  | 2629075.09       | 4.704 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 2762323.00  | 2630820.84       | 4.761 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 2768034.00  | 2632312.19       | 4.903 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 2776927.00  | 2633585.10       | 5.162 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 2785353.00  | 2634670.77       | 5.41 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 2792142.00  | 2635596.16       | 5.607 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 2798617.00  | 2636384.49       | 5.797 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 2803233.00  | 2637055.76       | 5.928 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 2805756.00  | 2637627.13       | 5.992 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 2808052.00  | 2638113.30       | 6.052 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 2811951.00  | 2638526.86       | 6.167 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 2818378.00  | 2638878.57       | 6.369 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 2824425.00  | 2639177.61       | 6.559 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 2829196.00  | 2639431.83       | 6.707 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 2639647.91          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 2639831.56          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 2639987.61          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 2640120.22          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 2640232.89          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 2640328.61          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 2640409.92          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 2640479.00          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 2640537.68          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 2640587.53          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 2640629.86          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 2640665.83          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 2640696.37          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 2640722.32          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 2640744.35          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 2640763.06          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 2640778.96          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 2640792.46          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 2640803.92          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 2640813.66          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 2640821.93          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 2640828.96          |
## +----+------------+-----------------+---------------------+
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 153.4438 2543.205 1126.811 -Inf  Inf 0.2369805 -0.004435005
# Print Model Parameters
model_bats
## BATS(1, {0,0}, 1, -)
## 
## Call: bats(y = data_series)
## 
## Parameters
##   Alpha: 1.127032
##   Beta: 0.3404099
##   Damping Parameter: 1
## 
## Seed States:
##             [,1]
## [1,] -0.08133717
## [2,]  1.11499478
## 
## Sigma: 2543.205
## AIC: 9745.859
#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 Poland"
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 Poland"
paste(MAPE_Mean_All.bats,"%")
## [1] "3.462 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Poland %"
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 Poland"
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                | 2154821.00  | 2145514.70       | 0.432 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 2189966.00  | 2168864.31       | 0.964 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 2221725.00  | 2192213.93       | 1.328 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 2250991.00  | 2215563.54       | 1.574 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 2267964.00  | 2238913.16       | 1.281 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 2288826.00  | 2262262.77       | 1.161 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 2321717.00  | 2285612.39       | 1.555 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 2356970.00  | 2308962.00       | 2.037 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 2387511.00  | 2332311.62       | 2.312 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 2415584.00  | 2355661.23       | 2.481 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 2438542.00  | 2379010.85       | 2.441 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 2448463.00  | 2402360.46       | 1.883 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 2456709.00  | 2425710.08       | 1.262 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 2471617.00  | 2449059.69       | 0.913 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 2499507.00  | 2472409.31       | 1.084 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 2528006.00  | 2495758.92       | 1.276 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 2552898.00  | 2519108.53       | 1.324 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 2574631.00  | 2542458.15       | 1.25 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 2586647.00  | 2565807.76       | 0.806 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 2599850.00  | 2589157.38       | 0.411 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 2621116.00  | 2612506.99       | 0.328 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 2642242.00  | 2635856.61       | 0.242 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 2660088.00  | 2659206.22       | 0.033 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 2675874.00  | 2682555.84       | 0.25 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 2688025.00  | 2705905.45       | 0.665 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 2695327.00  | 2729255.07       | 1.259 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 2704571.00  | 2752604.68       | 1.776 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 2718493.00  | 2775954.30       | 2.114 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 2731256.00  | 2799303.91       | 2.491 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 2742122.00  | 2822653.53       | 2.937 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 2751632.00  | 2846003.14       | 3.43 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 2758856.00  | 2869352.75       | 4.005 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 2762323.00  | 2892702.37       | 4.72 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 2768034.00  | 2916051.98       | 5.347 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 2776927.00  | 2939401.60       | 5.851 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 2785353.00  | 2962751.21       | 6.369 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 2792142.00  | 2986100.83       | 6.947 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 2798617.00  | 3009450.44       | 7.533 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 2803233.00  | 3032800.06       | 8.189 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 2805756.00  | 3056149.67       | 8.924 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 2808052.00  | 3079499.29       | 9.667 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 2811951.00  | 3102848.90       | 10.345 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 2818378.00  | 3126198.52       | 10.922 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 2824425.00  | 3149548.13       | 11.511 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 2829196.00  | 3172897.75       | 12.148 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 3196247.36          | 2977845.19 | 2862230.06 | 2977845.19 | 2862230.06 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3219596.97          | 2994446.75 | 2875259.42 | 2994446.75 | 2875259.42 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3242946.59          | 3010980.28 | 2888184.74 | 3010980.28 | 2888184.74 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3266296.20          | 3027446.46 | 2901007.04 | 3027446.46 | 2901007.04 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3289645.82          | 3043845.92 | 2913727.32 | 3043845.92 | 2913727.32 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3312995.43          | 3060179.31 | 2926346.54 | 3060179.31 | 2926346.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3336345.05          | 3076447.24 | 2938865.65 | 3076447.24 | 2938865.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3359694.66          | 3092650.31 | 2951285.57 | 3092650.31 | 2951285.57 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3383044.28          | 3108789.10 | 2963607.18 | 3108789.10 | 2963607.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3406393.89          | 3124864.17 | 2975831.34 | 3124864.17 | 2975831.34 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3429743.51          | 3140876.09 | 2987958.91 | 3140876.09 | 2987958.91 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3453093.12          | 3156825.38 | 2999990.71 | 3156825.38 | 2999990.71 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3476442.74          | 3172712.57 | 3011927.54 | 3172712.57 | 3011927.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3499792.35          | 3188538.18 | 3023770.18 | 3188538.18 | 3023770.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3523141.97          | 3204302.70 | 3035519.39 | 3204302.70 | 3035519.39 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3546491.58          | 3220006.62 | 3047175.92 | 3220006.62 | 3047175.92 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3569841.20          | 3235650.42 | 3058740.51 | 3235650.42 | 3058740.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3593190.81          | 3251234.56 | 3070213.85 | 3251234.56 | 3070213.85 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3616540.42          | 3266759.49 | 3081596.65 | 3266759.49 | 3081596.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 3639890.04          | 3282225.66 | 3092889.58 | 3282225.66 | 3092889.58 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 3663239.65          | 3297633.51 | 3104093.30 | 3297633.51 | 3104093.30 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 3686589.27          | 3312983.45 | 3115208.48 | 3312983.45 | 3115208.48 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
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 152.4499 2532.129 1217.418 NaN  Inf 0.2560361 -0.005657954
# Print Model Parameters
model_TBATS
## TBATS(1, {0,0}, 1, {<6,2>})
## 
## Call: NULL
## 
## Parameters
##   Alpha: 1.127334
##   Beta: 0.3413824
##   Damping Parameter: 1
##   Gamma-1 Values: -0.002897789
##   Gamma-2 Values: -0.0002014399
## 
## Seed States:
##             [,1]
## [1,]    1.102094
## [2,]   -3.900142
## [3,] -239.394132
## [4,]   23.871110
## [5,]   28.240407
## [6,]   41.565978
## 
## Sigma: 2532.129
## AIC: 9753.957
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 Poland"
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 Poland"
paste(MAPE_Mean_All.TBATS,"%")
## [1] "3.43 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Poland %"
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 Poland"
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                | 2154821.00  | 2145464.19        | 0.434 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 2  | 2021-03-26 | Friday                  | 2189966.00  | 2168466.81        | 0.982 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 3  | 2021-03-27 | Saturday                | 2221725.00  | 2191530.39        | 1.359 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 4  | 2021-03-28 | Sunday                  | 2250991.00  | 2214745.59        | 1.61 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 5  | 2021-03-29 | Monday                  | 2267964.00  | 2238128.33        | 1.316 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 6  | 2021-03-30 | Tuesday                 | 2288826.00  | 2261689.41        | 1.186 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 7  | 2021-03-31 | Wednesday               | 2321717.00  | 2285022.00        | 1.581 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 8  | 2021-04-01 | Thursday                | 2356970.00  | 2308024.62        | 2.077 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 9  | 2021-04-02 | Friday                  | 2387511.00  | 2331088.20        | 2.363 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 10 | 2021-04-03 | Saturday                | 2415584.00  | 2354303.40        | 2.537 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 11 | 2021-04-04 | Sunday                  | 2438542.00  | 2377686.13        | 2.496 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 12 | 2021-04-05 | Monday                  | 2448463.00  | 2401247.22        | 1.928 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 13 | 2021-04-06 | Tuesday                 | 2456709.00  | 2424579.81        | 1.308 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 14 | 2021-04-07 | Wednesday               | 2471617.00  | 2447582.42        | 0.972 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 15 | 2021-04-08 | Thursday                | 2499507.00  | 2470646.01        | 1.155 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 16 | 2021-04-09 | Friday                  | 2528006.00  | 2493861.21        | 1.351 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 17 | 2021-04-10 | Saturday                | 2552898.00  | 2517243.94        | 1.397 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 18 | 2021-04-11 | Sunday                  | 2574631.00  | 2540805.03        | 1.314 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 19 | 2021-04-12 | Monday                  | 2586647.00  | 2564137.61        | 0.87 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 20 | 2021-04-13 | Tuesday                 | 2599850.00  | 2587140.23        | 0.489 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 21 | 2021-04-14 | Wednesday               | 2621116.00  | 2610203.82        | 0.416 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 22 | 2021-04-15 | Thursday                | 2642242.00  | 2633419.02        | 0.334 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 23 | 2021-04-16 | Friday                  | 2660088.00  | 2656801.75        | 0.124 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 24 | 2021-04-17 | Saturday                | 2675874.00  | 2680362.84        | 0.168 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 25 | 2021-04-18 | Sunday                  | 2688025.00  | 2703695.42        | 0.583 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 26 | 2021-04-19 | Monday                  | 2695327.00  | 2726698.04        | 1.164 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 27 | 2021-04-20 | Tuesday                 | 2704571.00  | 2749761.63        | 1.671 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 28 | 2021-04-21 | Wednesday               | 2718493.00  | 2772976.83        | 2.004 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 29 | 2021-04-22 | Thursday                | 2731256.00  | 2796359.56        | 2.384 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 30 | 2021-04-23 | Friday                  | 2742122.00  | 2819920.65        | 2.837 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 31 | 2021-04-24 | Saturday                | 2751632.00  | 2843253.23        | 3.33 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 32 | 2021-04-25 | Sunday                  | 2758856.00  | 2866255.85        | 3.893 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 33 | 2021-04-26 | Monday                  | 2762323.00  | 2889319.44        | 4.597 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 34 | 2021-04-27 | Tuesday                 | 2768034.00  | 2912534.64        | 5.22 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 35 | 2021-04-28 | Wednesday               | 2776927.00  | 2935917.37        | 5.725 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 36 | 2021-04-29 | Thursday                | 2785353.00  | 2959478.46        | 6.251 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 37 | 2021-04-30 | Friday                  | 2792142.00  | 2982811.04        | 6.829 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 38 | 2021-05-01 | Saturday                | 2798617.00  | 3005813.66        | 7.404 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 39 | 2021-05-02 | Sunday                  | 2803233.00  | 3028877.25        | 8.049 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 40 | 2021-05-03 | Monday                  | 2805756.00  | 3052092.45        | 8.78 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 41 | 2021-05-04 | Tuesday                 | 2808052.00  | 3075475.18        | 9.523 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 42 | 2021-05-05 | Wednesday               | 2811951.00  | 3099036.27        | 10.209 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 43 | 2021-05-06 | Thursday                | 2818378.00  | 3122368.85        | 10.786 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 44 | 2021-05-07 | Friday                  | 2824425.00  | 3145371.47        | 11.363 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 45 | 2021-05-08 | Saturday                | 2829196.00  | 3168435.06        | 11.991 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
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          | 3191650.26           | 3168320.97 | 3155971.19 | 3214979.54 | 3227329.32 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3215032.99           | 3191480.55 | 3179012.64 | 3238585.43 | 3251053.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3238594.08           | 3214822.29 | 3202238.26 | 3262365.87 | 3274949.89 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3261926.66           | 3237940.04 | 3225242.30 | 3285913.28 | 3298611.02 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3284929.28           | 3260731.81 | 3247922.45 | 3309126.75 | 3321936.11 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3307992.87           | 3283586.93 | 3270667.20 | 3332398.81 | 3345318.53 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3331208.06           | 3306595.42 | 3293566.27 | 3355820.71 | 3368849.86 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3354590.80           | 3329773.83 | 3316636.51 | 3379407.77 | 3392545.08 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3378151.89           | 3353133.85 | 3339890.10 | 3403169.93 | 3416413.68 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3401484.47           | 3376269.32 | 3362921.22 | 3426699.62 | 3440047.72 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3424487.09           | 3399078.29 | 3385627.68 | 3449895.89 | 3463346.49 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3447550.68           | 3421950.22 | 3408398.15 | 3473151.14 | 3486703.20 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3470765.87           | 3444975.18 | 3431322.41 | 3496556.57 | 3510209.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3494148.61           | 3468169.69 | 3454417.28 | 3520127.53 | 3533879.94 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3517709.70           | 3491545.40 | 3477694.86 | 3543874.00 | 3557724.54 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3541042.28           | 3514696.12 | 3500749.30 | 3567388.44 | 3581335.25 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3564044.90           | 3537519.94 | 3523478.48 | 3590569.85 | 3604611.32 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3587108.49           | 3560406.43 | 3546271.21 | 3613810.55 | 3627945.76 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3610323.68           | 3583445.69 | 3569217.33 | 3637201.68 | 3651430.03 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 3633706.42           | 3606654.21 | 3592333.63 | 3660758.63 | 3675079.20 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 3657267.51           | 3630043.61 | 3615632.15 | 3684491.40 | 3698902.87 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 3680600.09           | 3653207.67 | 3638706.99 | 3707992.51 | 3722493.18 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 -79.51092 2684.228 1305.333 NaN  Inf 0.2745257 0.2493017
# 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.2875 
## 
##   Smoothing parameters:
##     alpha = 0.8678 
##     beta  = 0.3122 
## 
##   Initial states:
##     l = -3.4791 
##     b = -3e-04 
## 
##   sigma:  0.259
## 
##      AIC     AICc      BIC 
## 1526.135 1526.271 1546.648 
## 
## Training set error measures:
##                     ME     RMSE      MAE MPE MAPE      MASE      ACF1
## Training set -79.51092 2684.228 1305.333 NaN  Inf 0.2745257 0.2493017
# 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 Poland"
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 Poland"
paste(MAPE_Mean_All.Holt,"%")
## [1] "5.188 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Poland %"
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 Poland"
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                | 2154821.00  | 2142345.99       | 0.579 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 2189966.00  | 2165581.53       | 1.113 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 2221725.00  | 2188996.07       | 1.473 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 2250991.00  | 2212590.43       | 1.706 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 2267964.00  | 2236365.41       | 1.393 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 2288826.00  | 2260321.86       | 1.245 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 2321717.00  | 2284460.58       | 1.605 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 2356970.00  | 2308782.41       | 2.044 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 2387511.00  | 2333288.17       | 2.271 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 2415584.00  | 2357978.69       | 2.385 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 2438542.00  | 2382854.79       | 2.284 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 2448463.00  | 2407917.31       | 1.656 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 2456709.00  | 2433167.07       | 0.958 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 2471617.00  | 2458604.92       | 0.526 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 2499507.00  | 2484231.67       | 0.611 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 2528006.00  | 2510048.17       | 0.71 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 2552898.00  | 2536055.25       | 0.66 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 2574631.00  | 2562253.75       | 0.481 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 2586647.00  | 2588644.50       | 0.077 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 2599850.00  | 2615228.35       | 0.592 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 2621116.00  | 2642006.13       | 0.797 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 2642242.00  | 2668978.69       | 1.012 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 2660088.00  | 2696146.87       | 1.356 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 2675874.00  | 2723511.51       | 1.78 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 2688025.00  | 2751073.45       | 2.346 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 2695327.00  | 2778833.55       | 3.098 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 2704571.00  | 2806792.65       | 3.78 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 2718493.00  | 2834951.60       | 4.284 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 2731256.00  | 2863311.25       | 4.835 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 2742122.00  | 2891872.45       | 5.461 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 2751632.00  | 2920636.04       | 6.142 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 2758856.00  | 2949602.90       | 6.914 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 2762323.00  | 2978773.86       | 7.836 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 2768034.00  | 3008149.78       | 8.675 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 2776927.00  | 3037731.52       | 9.392 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 2785353.00  | 3067519.95       | 10.13 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 2792142.00  | 3097515.90       | 10.937 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 2798617.00  | 3127720.26       | 11.759 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 2803233.00  | 3158133.87       | 12.66 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 2805756.00  | 3188757.61       | 13.651 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 2808052.00  | 3219592.33       | 14.656 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 2811951.00  | 3250638.89       | 15.601 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 2818378.00  | 3281898.17       | 16.446 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 2824425.00  | 3313371.03       | 17.311 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 2829196.00  | 3345058.34       | 18.234 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 3376960.97          | 2559598.14 | 2189540.95 | 4365099.68 | 4964004.79 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3409079.79          | 2562813.69 | 2181504.83 | 4437691.65 | 5063364.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3441415.66          | 2565796.56 | 2173169.68 | 4511491.76 | 5164725.08 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3473969.47          | 2568548.51 | 2164541.28 | 4586514.90 | 5268119.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3506742.09          | 2571071.31 | 2155625.36 | 4662776.10 | 5373577.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3539734.38          | 2573366.68 | 2146427.62 | 4740290.58 | 5481131.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3572947.23          | 2575436.35 | 2136953.72 | 4819073.77 | 5590814.45 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3606381.52          | 2577282.04 | 2127209.29 | 4899141.25 | 5702658.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3640038.11          | 2578905.45 | 2117199.93 | 4980508.79 | 5816697.05 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3673917.90          | 2580308.27 | 2106931.19 | 5063192.35 | 5932963.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3708021.76          | 2581492.18 | 2096408.62 | 5147208.06 | 6051492.32 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3742350.58          | 2582458.86 | 2085637.72 | 5232572.22 | 6172317.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3776905.23          | 2583209.98 | 2074623.97 | 5319301.34 | 6295474.64 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3811686.60          | 2583747.19 | 2063372.81 | 5407412.07 | 6420998.63 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3846695.57          | 2584072.17 | 2051889.67 | 5496921.25 | 6548925.48 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3881933.03          | 2584186.55 | 2040179.94 | 5587845.93 | 6679291.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3917399.88          | 2584092.00 | 2028249.00 | 5680203.28 | 6812133.44 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3953096.98          | 2583790.16 | 2016102.19 | 5774010.70 | 6947488.49 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3989025.25          | 2583282.67 | 2003744.82 | 5869285.74 | 7085394.31 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4025185.56          | 2582571.19 | 1991182.19 | 5966046.14 | 7225889.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4061578.80          | 2581657.34 | 1978419.57 | 6064309.80 | 7369011.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4098205.88          | 2580542.77 | 1965462.20 | 6164094.83 | 7514799.68 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
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 Poland"
kpss.test(data_series) # applay kpss test
## Warning in kpss.test(data_series): p-value smaller than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  data_series
## KPSS Level = 5.83, 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.92708, 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 = -0.99858, Lag order = 7, p-value = 0.9386
## 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 Poland"
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.0027, 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) = -34.672, 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 = -0.64341, Lag order = 7, p-value = 0.9752
## 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 Poland"
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.18627, 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) = -453.07, 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 = -7.5056, 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)                    : 8360.113
##  ARIMA(0,2,1)                    : 8256.93
##  ARIMA(0,2,2)                    : 8250.052
##  ARIMA(0,2,3)                    : 8252.034
##  ARIMA(0,2,4)                    : 8217.45
##  ARIMA(0,2,5)                    : 8205.835
##  ARIMA(1,2,0)                    : 8310.175
##  ARIMA(1,2,1)                    : 8251.025
##  ARIMA(1,2,2)                    : 8252.072
##  ARIMA(1,2,3)                    : 8253.792
##  ARIMA(1,2,4)                    : 8204.097
##  ARIMA(2,2,0)                    : 8291.035
##  ARIMA(2,2,1)                    : 8250.601
##  ARIMA(2,2,2)                    : 8191.93
##  ARIMA(2,2,3)                    : 8238.013
##  ARIMA(3,2,0)                    : 8275.246
##  ARIMA(3,2,1)                    : 8244.853
##  ARIMA(3,2,2)                    : 8174.075
##  ARIMA(4,2,0)                    : 8261.746
##  ARIMA(4,2,1)                    : 8236.541
##  ARIMA(5,2,0)                    : 8222.867
## 
## 
## 
##  Best model: ARIMA(3,2,2)
model1 # show the result of autoarima 
## Series: data_series 
## ARIMA(3,2,2) 
## 
## Coefficients:
##          ar1      ar2      ar3      ma1     ma2
##       0.8821  -0.3805  -0.2771  -1.5385  0.8529
## s.e.  0.0593   0.0619   0.0519   0.0380  0.0425
## 
## sigma^2 estimated as 5442695:  log likelihood=-4080.94
## AIC=8173.88   AICc=8174.08   BIC=8198.47
#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] 3 2 2
strtoi(bestmodel[3])
## [1] 2
#2. Using ACF and PACF Function
#par(mfrow=c(1,2))  # Code for making two plot in one graph 
acf(diff2_x1,xlab = paste ("Time in", frequency ,y_lab , sep=" ") , ylab=y_lab, main=paste("ACF-2nd differenced series ",y_lab, sep=" ",lag.max=20))    # plot ACF "auto correlation function after taking second diffrences

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

x1_model1= arima(data_series, order=c(bestmodel)) # Run Best model of auto arima  for forecasting
x1_model1  # Show result of best model of auto arima 
## 
## Call:
## arima(x = data_series, order = c(bestmodel))
## 
## Coefficients:
##          ar1      ar2      ar3      ma1     ma2
##       0.8821  -0.3805  -0.2771  -1.5385  0.8529
## s.e.  0.0593   0.0619   0.0519   0.0380  0.0425
## 
## sigma^2 estimated as 5381541:  log likelihood = -4080.94,  aic = 8173.88
paste ("accuracy of autoarima Model For  ==> ",y_lab, sep=" ")
## [1] "accuracy of autoarima Model For  ==>  Forecasting cumulative Covid 19 Infection cases in Poland"
accuracy(x1_model1)  # aacuracy of best model from auto arima
##                    ME     RMSE      MAE      MPE     MAPE      MASE        ACF1
## Training set 137.0867 2314.619 995.0878 1.015724 1.551364 0.2092777 -0.02536305
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(3,2,2)
## Q* = 45.626, df = 5, p-value = 1.082e-08
## 
## 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 Poland"
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 = 148.75, 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 = 10828, 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 Poland"
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 Poland"
paste(MAPE_Mean_All.ARIMA,"%")
## [1] "4.194 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Poland %"
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 Poland"
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                | 2154821.00  | 2150015.70             | 0.223 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 2  | 2021-03-26      | Friday                  | 2189966.00  | 2178809.33             | 0.509 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 3  | 2021-03-27      | Saturday                | 2221725.00  | 2203775.10             | 0.808 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 4  | 2021-03-28      | Sunday                  | 2250991.00  | 2225977.72             | 1.111 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 5  | 2021-03-29      | Monday                  | 2267964.00  | 2247352.23             | 0.909 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 6  | 2021-03-30      | Tuesday                 | 2288826.00  | 2270108.35             | 0.818 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 7  | 2021-03-31      | Wednesday               | 2321717.00  | 2295163.95             | 1.144 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 8  | 2021-04-01      | Thursday                | 2356970.00  | 2321951.68             | 1.486 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 9  | 2021-04-02      | Friday                  | 2387511.00  | 2349009.51             | 1.613 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 10 | 2021-04-03      | Saturday                | 2415584.00  | 2375009.31             | 1.68 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 11 | 2021-04-04      | Sunday                  | 2438542.00  | 2399493.10             | 1.601 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 12 | 2021-04-05      | Monday                  | 2448463.00  | 2422967.35             | 1.041 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 13 | 2021-04-06      | Tuesday                 | 2456709.00  | 2446421.12             | 0.419 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 14 | 2021-04-07      | Wednesday               | 2471617.00  | 2470661.04             | 0.039 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 15 | 2021-04-08      | Thursday                | 2499507.00  | 2495881.97             | 0.145 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 16 | 2021-04-09      | Friday                  | 2528006.00  | 2521674.77             | 0.25 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 17 | 2021-04-10      | Saturday                | 2552898.00  | 2547380.91             | 0.216 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 18 | 2021-04-11      | Sunday                  | 2574631.00  | 2572521.16             | 0.082 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 19 | 2021-04-12      | Monday                  | 2586647.00  | 2597036.75             | 0.402 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 20 | 2021-04-13      | Tuesday                 | 2599850.00  | 2621240.67             | 0.823 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 21 | 2021-04-14      | Wednesday               | 2621116.00  | 2645564.16             | 0.933 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 22 | 2021-04-15      | Thursday                | 2642242.00  | 2670284.81             | 1.061 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 23 | 2021-04-16      | Friday                  | 2660088.00  | 2695396.65             | 1.327 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 24 | 2021-04-17      | Saturday                | 2675874.00  | 2720669.32             | 1.674 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 25 | 2021-04-18      | Sunday                  | 2688025.00  | 2745824.94             | 2.15 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 26 | 2021-04-19      | Monday                  | 2695327.00  | 2770707.73             | 2.797 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 27 | 2021-04-20      | Tuesday                 | 2704571.00  | 2795349.81             | 3.356 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 28 | 2021-04-21      | Wednesday               | 2718493.00  | 2819915.83             | 3.731 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 29 | 2021-04-22      | Thursday                | 2731256.00  | 2844581.93             | 4.149 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 30 | 2021-04-23      | Friday                  | 2742122.00  | 2869431.97             | 4.643 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 31 | 2021-04-24      | Saturday                | 2751632.00  | 2894427.24             | 5.189 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 32 | 2021-04-25      | Sunday                  | 2758856.00  | 2919452.91             | 5.821 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 33 | 2021-04-26      | Monday                  | 2762323.00  | 2944399.16             | 6.591 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 34 | 2021-04-27      | Tuesday                 | 2768034.00  | 2969223.54             | 7.268 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 35 | 2021-04-28      | Wednesday               | 2776927.00  | 2993962.22             | 7.816 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 36 | 2021-04-29      | Thursday                | 2785353.00  | 3018693.68             | 8.377 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 37 | 2021-04-30      | Friday                  | 2792142.00  | 3043485.16             | 9.002 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 38 | 2021-05-01      | Saturday                | 2798617.00  | 3068356.06             | 9.638 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 39 | 2021-05-02      | Sunday                  | 2803233.00  | 3093276.19             | 10.347 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 40 | 2021-05-03      | Monday                  | 2805756.00  | 3118192.90             | 11.136 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 41 | 2021-05-04      | Tuesday                 | 2808052.00  | 3143065.85             | 11.93 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 42 | 2021-05-05      | Wednesday               | 2811951.00  | 3167887.85             | 12.658 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 43 | 2021-05-06      | Thursday                | 2818378.00  | 3192682.51             | 13.281 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 44 | 2021-05-07      | Friday                  | 2824425.00  | 3217484.57             | 13.916 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 45 | 2021-05-08      | Saturday                | 2829196.00  | 3242317.68             | 14.602 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
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          | 3267182.94                | 3043769.10 | 2925500.96 | 3490596.77 | 3608864.91 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3292062.68                | 3061461.74 | 2939388.98 | 3522663.62 | 3644736.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3316934.37                | 3079070.59 | 2953153.10 | 3554798.16 | 3680715.64 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3341784.54                | 3096584.13 | 2966782.88 | 3586984.95 | 3716786.21 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3366614.77                | 3114005.14 | 2980281.68 | 3619224.40 | 3752947.86 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3391437.84                | 3131346.70 | 2993662.76 | 3651528.98 | 3789212.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3416268.14                | 3148623.04 | 3006940.29 | 3683913.23 | 3825595.98 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3441113.06                | 3165841.58 | 3020121.66 | 3716384.54 | 3862104.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3465970.12                | 3183000.30 | 3033205.12 | 3748939.95 | 3898735.12 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3490830.32                | 3200091.18 | 3046183.18 | 3781569.46 | 3935477.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3515684.62                | 3217106.38 | 3059048.60 | 3814262.85 | 3972320.63 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3540529.15                | 3234043.04 | 3071799.09 | 3847015.25 | 4009259.20 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3565366.44                | 3250904.35 | 3084438.18 | 3879828.52 | 4046294.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3590202.70                | 3267696.87 | 3096972.60 | 3912708.53 | 4083432.80 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3615043.51                | 3284426.39 | 3109408.26 | 3945660.63 | 4120678.76 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3639890.73                | 3301095.11 | 3121747.55 | 3978686.35 | 4158033.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3664742.16                | 3317701.37 | 3133989.07 | 4011782.96 | 4195495.25 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3689593.61                | 3334241.67 | 3146129.72 | 4044945.54 | 4233057.49 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3714441.69                | 3350713.38 | 3158167.24 | 4078170.00 | 4270716.13 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 3739285.63                | 3367116.34 | 3170101.82 | 4111454.91 | 4308469.43 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 3764127.19                | 3383452.80 | 3181935.95 | 4144801.58 | 4346318.43 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 3788969.16                | 3399725.90 | 3193672.97 | 4178212.42 | 4384265.36 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
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] "4.194 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Poland"
## 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 Poland"
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 Poland"
paste(MAPE_Mean_EnsemblingAverage,"%")
## [1] "2.305 %"
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 Poland"
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                | 2154821.00  | 2146478.75 | 0.387 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 2  | 2021-03-26      | Friday                  | 2189966.00  | 2172756.23 | 0.786 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 3  | 2021-03-27      | Saturday                | 2221725.00  | 2199369.31 | 1.006 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 4  | 2021-03-28      | Sunday                  | 2250991.00  | 2226223.29 | 1.1 %           |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 5  | 2021-03-29      | Monday                  | 2267964.00  | 2253221.72 | 0.65 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 6  | 2021-03-30      | Tuesday                 | 2288826.00  | 2280255.50 | 0.374 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 7  | 2021-03-31      | Wednesday               | 2321717.00  | 2307157.25 | 0.627 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 8  | 2021-04-01      | Thursday                | 2356970.00  | 2333720.15 | 0.986 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 9  | 2021-04-02      | Friday                  | 2387511.00  | 2359724.29 | 1.164 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 10 | 2021-04-03      | Saturday                | 2415584.00  | 2384950.49 | 1.268 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 11 | 2021-04-04      | Sunday                  | 2438542.00  | 2409212.51 | 1.203 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 12 | 2021-04-05      | Monday                  | 2448463.00  | 2432368.72 | 0.657 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 13 | 2021-04-06      | Tuesday                 | 2456709.00  | 2454306.11 | 0.098 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 14 | 2021-04-07      | Wednesday               | 2471617.00  | 2474946.23 | 0.135 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 15 | 2021-04-08      | Thursday                | 2499507.00  | 2494241.31 | 0.211 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 16 | 2021-04-09      | Friday                  | 2528006.00  | 2512154.60 | 0.627 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 17 | 2021-04-10      | Saturday                | 2552898.00  | 2528672.81 | 0.949 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 18 | 2021-04-11      | Sunday                  | 2574631.00  | 2543814.84 | 1.197 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 19 | 2021-04-12      | Monday                  | 2586647.00  | 2557622.71 | 1.122 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 20 | 2021-04-13      | Tuesday                 | 2599850.00  | 2570173.20 | 1.141 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 21 | 2021-04-14      | Wednesday               | 2621116.00  | 2581570.93 | 1.509 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 22 | 2021-04-15      | Thursday                | 2642242.00  | 2591916.88 | 1.905 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 23 | 2021-04-16      | Friday                  | 2660088.00  | 2601306.54 | 2.21 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 24 | 2021-04-17      | Saturday                | 2675874.00  | 2609829.68 | 2.468 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 25 | 2021-04-18      | Sunday                  | 2688025.00  | 2617561.78 | 2.621 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 26 | 2021-04-19      | Monday                  | 2695327.00  | 2624584.37 | 2.625 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 27 | 2021-04-20      | Tuesday                 | 2704571.00  | 2630990.14 | 2.721 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 28 | 2021-04-21      | Wednesday               | 2718493.00  | 2636860.90 | 3.003 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 29 | 2021-04-22      | Thursday                | 2731256.00  | 2642269.95 | 3.258 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 30 | 2021-04-23      | Friday                  | 2742122.00  | 2647281.18 | 3.459 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 31 | 2021-04-24      | Saturday                | 2751632.00  | 2651938.24 | 3.623 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 32 | 2021-04-25      | Sunday                  | 2758856.00  | 2656284.19 | 3.718 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 33 | 2021-04-26      | Monday                  | 2762323.00  | 2660368.63 | 3.691 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 34 | 2021-04-27      | Tuesday                 | 2768034.00  | 2664229.97 | 3.75 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 35 | 2021-04-28      | Wednesday               | 2776927.00  | 2667901.91 | 3.926 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 36 | 2021-04-29      | Thursday                | 2785353.00  | 2671414.78 | 4.091 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 37 | 2021-04-30      | Friday                  | 2792142.00  | 2674784.36 | 4.203 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 38 | 2021-05-01      | Saturday                | 2798617.00  | 2678029.55 | 4.309 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 39 | 2021-05-02      | Sunday                  | 2803233.00  | 2681177.37 | 4.354 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 40 | 2021-05-03      | Monday                  | 2805756.00  | 2684244.23 | 4.331 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 41 | 2021-05-04      | Tuesday                 | 2808052.00  | 2687242.79 | 4.302 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 42 | 2021-05-05      | Wednesday               | 2811951.00  | 2690184.47 | 4.33 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 43 | 2021-05-06      | Thursday                | 2818378.00  | 2693069.41 | 4.446 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 44 | 2021-05-07      | Friday                  | 2824425.00  | 2695904.23 | 4.55 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 45 | 2021-05-08      | Saturday                | 2829196.00  | 2698706.37 | 4.612 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
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          | 2701484.16                |
## +----+------------+-----------------+---------------------------+
## | 2  | 2021-05-10 | Monday          | 2704242.71                |
## +----+------------+-----------------+---------------------------+
## | 3  | 2021-05-11 | Tuesday         | 2706986.12                |
## +----+------------+-----------------+---------------------------+
## | 4  | 2021-05-12 | Wednesday       | 2709707.62                |
## +----+------------+-----------------+---------------------------+
## | 5  | 2021-05-13 | Thursday        | 2712407.90                |
## +----+------------+-----------------+---------------------------+
## | 6  | 2021-05-14 | Friday          | 2715099.76                |
## +----+------------+-----------------+---------------------------+
## | 7  | 2021-05-15 | Saturday        | 2717788.14                |
## +----+------------+-----------------+---------------------------+
## | 8  | 2021-05-16 | Sunday          | 2720475.60                |
## +----+------------+-----------------+---------------------------+
## | 9  | 2021-05-17 | Monday          | 2723164.02                |
## +----+------------+-----------------+---------------------------+
## | 10 | 2021-05-18 | Tuesday         | 2725844.44                |
## +----+------------+-----------------+---------------------------+
## | 11 | 2021-05-19 | Wednesday       | 2728515.30                |
## +----+------------+-----------------+---------------------------+
## | 12 | 2021-05-20 | Thursday        | 2731187.33                |
## +----+------------+-----------------+---------------------------+
## | 13 | 2021-05-21 | Friday          | 2733863.74                |
## +----+------------+-----------------+---------------------------+
## | 14 | 2021-05-22 | Saturday        | 2736545.84                |
## +----+------------+-----------------+---------------------------+
## | 15 | 2021-05-23 | Sunday          | 2739234.68                |
## +----+------------+-----------------+---------------------------+
## | 16 | 2021-05-24 | Monday          | 2741920.70                |
## +----+------------+-----------------+---------------------------+
## | 17 | 2021-05-25 | Tuesday         | 2744601.77                |
## +----+------------+-----------------+---------------------------+
## | 18 | 2021-05-26 | Wednesday       | 2747287.96                |
## +----+------------+-----------------+---------------------------+
## | 19 | 2021-05-27 | Thursday        | 2749981.81                |
## +----+------------+-----------------+---------------------------+
## | 20 | 2021-05-28 | Friday          | 2752683.99                |
## +----+------------+-----------------+---------------------------+
## | 21 | 2021-05-29 | Saturday        | 2755395.07                |
## +----+------------+-----------------+---------------------------+
## | 22 | 2021-05-30 | Sunday          | 2758105.17                |
## +----+------------+-----------------+---------------------------+
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 Poland"
best_recommended_model
## [1] 2.305
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 Poland"
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          | 3196247.36          | 2977845.19 | 2862230.06 | 2977845.19 | 2862230.06 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3219596.97          | 2994446.75 | 2875259.42 | 2994446.75 | 2875259.42 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3242946.59          | 3010980.28 | 2888184.74 | 3010980.28 | 2888184.74 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3266296.20          | 3027446.46 | 2901007.04 | 3027446.46 | 2901007.04 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3289645.82          | 3043845.92 | 2913727.32 | 3043845.92 | 2913727.32 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3312995.43          | 3060179.31 | 2926346.54 | 3060179.31 | 2926346.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3336345.05          | 3076447.24 | 2938865.65 | 3076447.24 | 2938865.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3359694.66          | 3092650.31 | 2951285.57 | 3092650.31 | 2951285.57 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3383044.28          | 3108789.10 | 2963607.18 | 3108789.10 | 2963607.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3406393.89          | 3124864.17 | 2975831.34 | 3124864.17 | 2975831.34 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3429743.51          | 3140876.09 | 2987958.91 | 3140876.09 | 2987958.91 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3453093.12          | 3156825.38 | 2999990.71 | 3156825.38 | 2999990.71 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3476442.74          | 3172712.57 | 3011927.54 | 3172712.57 | 3011927.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3499792.35          | 3188538.18 | 3023770.18 | 3188538.18 | 3023770.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3523141.97          | 3204302.70 | 3035519.39 | 3204302.70 | 3035519.39 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3546491.58          | 3220006.62 | 3047175.92 | 3220006.62 | 3047175.92 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3569841.20          | 3235650.42 | 3058740.51 | 3235650.42 | 3058740.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3593190.81          | 3251234.56 | 3070213.85 | 3251234.56 | 3070213.85 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3616540.42          | 3266759.49 | 3081596.65 | 3266759.49 | 3081596.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 3639890.04          | 3282225.66 | 3092889.58 | 3282225.66 | 3092889.58 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 3663239.65          | 3297633.51 | 3104093.30 | 3297633.51 | 3104093.30 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 3686589.27          | 3312983.45 | 3115208.48 | 3312983.45 | 3115208.48 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using TBATS Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using TBATS Model  ==>  Forecasting cumulative Covid 19 Infection cases in Poland"
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          | 3191650.26           | 3168320.97 | 3155971.19 | 3214979.54 | 3227329.32 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3215032.99           | 3191480.55 | 3179012.64 | 3238585.43 | 3251053.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3238594.08           | 3214822.29 | 3202238.26 | 3262365.87 | 3274949.89 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3261926.66           | 3237940.04 | 3225242.30 | 3285913.28 | 3298611.02 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3284929.28           | 3260731.81 | 3247922.45 | 3309126.75 | 3321936.11 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3307992.87           | 3283586.93 | 3270667.20 | 3332398.81 | 3345318.53 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3331208.06           | 3306595.42 | 3293566.27 | 3355820.71 | 3368849.86 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3354590.80           | 3329773.83 | 3316636.51 | 3379407.77 | 3392545.08 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3378151.89           | 3353133.85 | 3339890.10 | 3403169.93 | 3416413.68 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3401484.47           | 3376269.32 | 3362921.22 | 3426699.62 | 3440047.72 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3424487.09           | 3399078.29 | 3385627.68 | 3449895.89 | 3463346.49 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3447550.68           | 3421950.22 | 3408398.15 | 3473151.14 | 3486703.20 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3470765.87           | 3444975.18 | 3431322.41 | 3496556.57 | 3510209.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3494148.61           | 3468169.69 | 3454417.28 | 3520127.53 | 3533879.94 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3517709.70           | 3491545.40 | 3477694.86 | 3543874.00 | 3557724.54 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3541042.28           | 3514696.12 | 3500749.30 | 3567388.44 | 3581335.25 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3564044.90           | 3537519.94 | 3523478.48 | 3590569.85 | 3604611.32 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3587108.49           | 3560406.43 | 3546271.21 | 3613810.55 | 3627945.76 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3610323.68           | 3583445.69 | 3569217.33 | 3637201.68 | 3651430.03 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 3633706.42           | 3606654.21 | 3592333.63 | 3660758.63 | 3675079.20 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 3657267.51           | 3630043.61 | 3615632.15 | 3684491.40 | 3698902.87 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 3680600.09           | 3653207.67 | 3638706.99 | 3707992.51 | 3722493.18 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 Poland"
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          | 3376960.97          | 2559598.14 | 2189540.95 | 4365099.68 | 4964004.79 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3409079.79          | 2562813.69 | 2181504.83 | 4437691.65 | 5063364.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3441415.66          | 2565796.56 | 2173169.68 | 4511491.76 | 5164725.08 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3473969.47          | 2568548.51 | 2164541.28 | 4586514.90 | 5268119.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3506742.09          | 2571071.31 | 2155625.36 | 4662776.10 | 5373577.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3539734.38          | 2573366.68 | 2146427.62 | 4740290.58 | 5481131.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3572947.23          | 2575436.35 | 2136953.72 | 4819073.77 | 5590814.45 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3606381.52          | 2577282.04 | 2127209.29 | 4899141.25 | 5702658.54 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3640038.11          | 2578905.45 | 2117199.93 | 4980508.79 | 5816697.05 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3673917.90          | 2580308.27 | 2106931.19 | 5063192.35 | 5932963.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3708021.76          | 2581492.18 | 2096408.62 | 5147208.06 | 6051492.32 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3742350.58          | 2582458.86 | 2085637.72 | 5232572.22 | 6172317.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3776905.23          | 2583209.98 | 2074623.97 | 5319301.34 | 6295474.64 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3811686.60          | 2583747.19 | 2063372.81 | 5407412.07 | 6420998.63 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3846695.57          | 2584072.17 | 2051889.67 | 5496921.25 | 6548925.48 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3881933.03          | 2584186.55 | 2040179.94 | 5587845.93 | 6679291.50 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3917399.88          | 2584092.00 | 2028249.00 | 5680203.28 | 6812133.44 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3953096.98          | 2583790.16 | 2016102.19 | 5774010.70 | 6947488.49 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3989025.25          | 2583282.67 | 2003744.82 | 5869285.74 | 7085394.31 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4025185.56          | 2582571.19 | 1991182.19 | 5966046.14 | 7225889.00 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4061578.80          | 2581657.34 | 1978419.57 | 6064309.80 | 7369011.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4098205.88          | 2580542.77 | 1965462.20 | 6164094.83 | 7514799.68 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using ARIMA Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using ARIMA Model  ==>  Forecasting cumulative Covid 19 Infection cases in Poland"
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          | 3267182.94                | 3043769.10 | 2925500.96 | 3490596.77 | 3608864.91 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 3292062.68                | 3061461.74 | 2939388.98 | 3522663.62 | 3644736.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 3316934.37                | 3079070.59 | 2953153.10 | 3554798.16 | 3680715.64 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 3341784.54                | 3096584.13 | 2966782.88 | 3586984.95 | 3716786.21 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 3366614.77                | 3114005.14 | 2980281.68 | 3619224.40 | 3752947.86 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 3391437.84                | 3131346.70 | 2993662.76 | 3651528.98 | 3789212.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 3416268.14                | 3148623.04 | 3006940.29 | 3683913.23 | 3825595.98 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 3441113.06                | 3165841.58 | 3020121.66 | 3716384.54 | 3862104.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 3465970.12                | 3183000.30 | 3033205.12 | 3748939.95 | 3898735.12 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 3490830.32                | 3200091.18 | 3046183.18 | 3781569.46 | 3935477.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 3515684.62                | 3217106.38 | 3059048.60 | 3814262.85 | 3972320.63 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 3540529.15                | 3234043.04 | 3071799.09 | 3847015.25 | 4009259.20 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 3565366.44                | 3250904.35 | 3084438.18 | 3879828.52 | 4046294.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 3590202.70                | 3267696.87 | 3096972.60 | 3912708.53 | 4083432.80 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 3615043.51                | 3284426.39 | 3109408.26 | 3945660.63 | 4120678.76 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 3639890.73                | 3301095.11 | 3121747.55 | 3978686.35 | 4158033.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 3664742.16                | 3317701.37 | 3133989.07 | 4011782.96 | 4195495.25 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 3689593.61                | 3334241.67 | 3146129.72 | 4044945.54 | 4233057.49 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 3714441.69                | 3350713.38 | 3158167.24 | 4078170.00 | 4270716.13 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 3739285.63                | 3367116.34 | 3170101.82 | 4111454.91 | 4308469.43 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 3764127.19                | 3383452.80 | 3181935.95 | 4144801.58 | 4346318.43 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 3788969.16                | 3399725.90 | 3193672.97 | 4178212.42 | 4384265.36 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
paste("Forecasting by using NNAR Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using NNAR Model  ==>  Forecasting cumulative Covid 19 Infection cases in Poland"
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          | 2639647.91          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 2639831.56          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 2639987.61          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 2640120.22          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 2640232.89          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 2640328.61          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 2640409.92          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 2640479.00          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 2640537.68          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 2640587.53          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 2640629.86          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 2640665.83          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 2640696.37          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 2640722.32          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 2640744.35          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 2640763.06          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 2640778.96          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 2640792.46          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 2640803.92          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 2640813.66          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 2640821.93          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 2640828.96          |
## +----+------------+-----------------+---------------------+
paste("Forecasting by using Ensembling Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using Ensembling Model  ==>  Forecasting cumulative Covid 19 Infection cases in Poland"
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          | 2701484.16             |
## +----+------------+-----------------+------------------------+
## | 2  | 2021-05-10 | Monday          | 2704242.71             |
## +----+------------+-----------------+------------------------+
## | 3  | 2021-05-11 | Tuesday         | 2706986.12             |
## +----+------------+-----------------+------------------------+
## | 4  | 2021-05-12 | Wednesday       | 2709707.62             |
## +----+------------+-----------------+------------------------+
## | 5  | 2021-05-13 | Thursday        | 2712407.90             |
## +----+------------+-----------------+------------------------+
## | 6  | 2021-05-14 | Friday          | 2715099.76             |
## +----+------------+-----------------+------------------------+
## | 7  | 2021-05-15 | Saturday        | 2717788.14             |
## +----+------------+-----------------+------------------------+
## | 8  | 2021-05-16 | Sunday          | 2720475.60             |
## +----+------------+-----------------+------------------------+
## | 9  | 2021-05-17 | Monday          | 2723164.02             |
## +----+------------+-----------------+------------------------+
## | 10 | 2021-05-18 | Tuesday         | 2725844.44             |
## +----+------------+-----------------+------------------------+
## | 11 | 2021-05-19 | Wednesday       | 2728515.30             |
## +----+------------+-----------------+------------------------+
## | 12 | 2021-05-20 | Thursday        | 2731187.33             |
## +----+------------+-----------------+------------------------+
## | 13 | 2021-05-21 | Friday          | 2733863.74             |
## +----+------------+-----------------+------------------------+
## | 14 | 2021-05-22 | Saturday        | 2736545.84             |
## +----+------------+-----------------+------------------------+
## | 15 | 2021-05-23 | Sunday          | 2739234.68             |
## +----+------------+-----------------+------------------------+
## | 16 | 2021-05-24 | Monday          | 2741920.70             |
## +----+------------+-----------------+------------------------+
## | 17 | 2021-05-25 | Tuesday         | 2744601.77             |
## +----+------------+-----------------+------------------------+
## | 18 | 2021-05-26 | Wednesday       | 2747287.96             |
## +----+------------+-----------------+------------------------+
## | 19 | 2021-05-27 | Thursday        | 2749981.81             |
## +----+------------+-----------------+------------------------+
## | 20 | 2021-05-28 | Friday          | 2752683.99             |
## +----+------------+-----------------+------------------------+
## | 21 | 2021-05-29 | Saturday        | 2755395.07             |
## +----+------------+-----------------+------------------------+
## | 22 | 2021-05-30 | Sunday          | 2758105.17             |
## +----+------------+-----------------+------------------------+
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 | Poland       | 2.897      | 3.462      | 3.43        | 5.188      | 4.194       | 2.305       | 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 Poland
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 Poland