comparison between two systems for forecasting covid 19 cumulative infected case

cumulative Covid 19 Infection cases In Russian Federation
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 Russia"   # 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 <- "Russia"
# Data Preparation & calculate some of statistics measures
summary(original_data) # Summary your time series
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0  152844 1017708 1697559 3290438 4871843
# calculate standard deviation 
data.frame(kurtosis=kurtosis(original_data))   # calculate Cofficient of kurtosis
##   kurtosis
## 1 1.900261
data.frame(skewness=skewness(original_data))  # calculate Cofficient of skewness
##    skewness
## 1 0.6570666
data.frame(Standard.deviation =sd(original_data))
##   Standard.deviation
## 1            1677499
#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 7519520
# 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 Russia"
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 Russia"
paste(MAPE_Mean_All,"%")
## [1] "2.766 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Russia %"
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 Russia"
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                | 4492692.00  | 4488144.64       | 0.101 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 4501859.00  | 4492665.09       | 0.204 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 4510744.00  | 4497036.68       | 0.304 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 4519832.00  | 4501263.66       | 0.411 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 4528543.00  | 4505350.23       | 0.512 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 4536820.00  | 4509300.49       | 0.607 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 4545095.00  | 4513118.48       | 0.704 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 4554264.00  | 4516808.13       | 0.822 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 4563056.00  | 4520373.31       | 0.935 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 4572077.00  | 4523817.81       | 1.056 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 4580894.00  | 4527145.33       | 1.173 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 4589540.00  | 4530359.47       | 1.289 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 4597868.00  | 4533463.77       | 1.401 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 4606162.00  | 4536461.66       | 1.513 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 4614834.00  | 4539356.52       | 1.636 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 4623984.00  | 4542151.60       | 1.77 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 4632688.00  | 4544850.10       | 1.896 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 4641390.00  | 4547455.13       | 2.024 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 4649710.00  | 4549969.70       | 2.145 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 4657883.00  | 4552396.77       | 2.265 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 4666209.00  | 4554739.19       | 2.389 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 4675153.00  | 4556999.73       | 2.527 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 4684148.00  | 4559181.12       | 2.668 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 4693469.00  | 4561285.96       | 2.816 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 4702101.00  | 4563316.80       | 2.952 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 4710690.00  | 4565276.13       | 3.087 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 4718854.00  | 4567166.34       | 3.215 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 4727125.00  | 4568989.76       | 3.345 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 4736121.00  | 4570748.65       | 3.492 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 4744961.00  | 4572445.20       | 3.636 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 4753789.00  | 4574081.53       | 3.78 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 4762569.00  | 4575659.70       | 3.925 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 4771372.00  | 4577181.69       | 4.07 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 4779425.00  | 4578649.45       | 4.201 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 4787273.00  | 4580064.83       | 4.328 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 4796557.00  | 4581429.65       | 4.485 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4805288.00  | 4582745.66       | 4.631 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4814558.00  | 4584014.55       | 4.788 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4823255.00  | 4585237.96       | 4.935 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4831744.00  | 4586417.47       | 5.077 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4839514.00  | 4587554.63       | 5.206 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4847489.00  | 4588650.91       | 5.34 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4855128.00  | 4589707.75       | 5.467 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4863514.00  | 4590726.53       | 5.609 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4871843.00  | 4591708.60       | 5.75 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 4592655.24          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 4593567.72          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 4594447.23          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 4595294.96          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 4596112.02          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 4596899.50          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 4597658.47          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 4598389.93          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 4599094.86          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 4599774.22          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 4600428.92          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 4601059.84          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 4601667.84          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 4602253.73          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 4602818.31          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 4603362.35          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 4603886.58          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 4604391.72          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 4604878.46          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 4605347.46          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 4605799.36          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 4606234.78          |
## +----+------------+-----------------+---------------------+
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 21.72611 580.3338 354.758 NaN  Inf 0.03529009 -0.001091273
# Print Model Parameters
model_bats
## BATS(1, {0,0}, 1, -)
## 
## Call: bats(y = data_series)
## 
## Parameters
##   Alpha: 1.03717
##   Beta: 0.9136316
##   Damping Parameter: 1
## 
## Seed States:
##           [,1]
## [1,] -29.75345
## [2,] -11.74250
## 
## Sigma: 580.3338
## AIC: 8424.905
#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 Russia"
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 Russia"
paste(MAPE_Mean_All.bats,"%")
## [1] "0.071 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Russia %"
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 Russia"
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                | 4492692.00  | 4492345.49       | 0.008 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 4501859.00  | 4501206.54       | 0.014 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 4510744.00  | 4510067.60       | 0.015 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 4519832.00  | 4518928.66       | 0.02 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 4528543.00  | 4527789.71       | 0.017 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 4536820.00  | 4536650.77       | 0.004 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 4545095.00  | 4545511.82       | 0.009 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 4554264.00  | 4554372.88       | 0.002 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 4563056.00  | 4563233.93       | 0.004 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 4572077.00  | 4572094.99       | 0 %             |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 4580894.00  | 4580956.05       | 0.001 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 4589540.00  | 4589817.10       | 0.006 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 4597868.00  | 4598678.16       | 0.018 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 4606162.00  | 4607539.21       | 0.03 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 4614834.00  | 4616400.27       | 0.034 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 4623984.00  | 4625261.32       | 0.028 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 4632688.00  | 4634122.38       | 0.031 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 4641390.00  | 4642983.44       | 0.034 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 4649710.00  | 4651844.49       | 0.046 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 4657883.00  | 4660705.55       | 0.061 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 4666209.00  | 4669566.60       | 0.072 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 4675153.00  | 4678427.66       | 0.07 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 4684148.00  | 4687288.71       | 0.067 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 4693469.00  | 4696149.77       | 0.057 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 4702101.00  | 4705010.82       | 0.062 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 4710690.00  | 4713871.88       | 0.068 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 4718854.00  | 4722732.94       | 0.082 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 4727125.00  | 4731593.99       | 0.095 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 4736121.00  | 4740455.05       | 0.092 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 4744961.00  | 4749316.10       | 0.092 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 4753789.00  | 4758177.16       | 0.092 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 4762569.00  | 4767038.21       | 0.094 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 4771372.00  | 4775899.27       | 0.095 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 4779425.00  | 4784760.33       | 0.112 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 4787273.00  | 4793621.38       | 0.133 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 4796557.00  | 4802482.44       | 0.124 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4805288.00  | 4811343.49       | 0.126 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4814558.00  | 4820204.55       | 0.117 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4823255.00  | 4829065.60       | 0.12 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4831744.00  | 4837926.66       | 0.128 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4839514.00  | 4846787.72       | 0.15 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4847489.00  | 4855648.77       | 0.168 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4855128.00  | 4864509.83       | 0.193 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4863514.00  | 4873370.88       | 0.203 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4871843.00  | 4882231.94       | 0.213 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 4891092.99          | 4766162.14 | 4700027.74 | 4766162.14 | 4700027.74 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4899954.05          | 4770983.07 | 4702709.95 | 4770983.07 | 4702709.95 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4908815.11          | 4775761.36 | 4705326.96 | 4775761.36 | 4705326.96 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4917676.16          | 4780497.47 | 4707879.46 | 4780497.47 | 4707879.46 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4926537.22          | 4785191.82 | 4710368.08 | 4785191.82 | 4710368.08 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4935398.27          | 4789844.82 | 4712793.47 | 4789844.82 | 4712793.47 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4944259.33          | 4794456.87 | 4715156.24 | 4794456.87 | 4715156.24 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4953120.38          | 4799028.37 | 4717456.98 | 4799028.37 | 4717456.98 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4961981.44          | 4803559.70 | 4719696.29 | 4803559.70 | 4719696.29 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4970842.50          | 4808051.22 | 4721874.72 | 4808051.22 | 4721874.72 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4979703.55          | 4812503.29 | 4723992.82 | 4812503.29 | 4723992.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4988564.61          | 4816916.27 | 4726051.13 | 4816916.27 | 4726051.13 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4997425.66          | 4821290.49 | 4728050.17 | 4821290.49 | 4728050.17 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 5006286.72          | 4825626.29 | 4729990.44 | 4825626.29 | 4729990.44 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 5015147.77          | 4829924.00 | 4731872.45 | 4829924.00 | 4731872.45 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 5024008.83          | 4834183.91 | 4733696.67 | 4834183.91 | 4733696.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 5032869.89          | 4838406.35 | 4735463.57 | 4838406.35 | 4735463.57 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 5041730.94          | 4842591.61 | 4737173.62 | 4842591.61 | 4737173.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 5050592.00          | 4846739.99 | 4738827.26 | 4846739.99 | 4738827.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5059453.05          | 4850851.77 | 4740424.93 | 4850851.77 | 4740424.93 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5068314.11          | 4854927.24 | 4741967.06 | 4854927.24 | 4741967.06 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5077175.16          | 4858966.66 | 4743454.06 | 4858966.66 | 4743454.06 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
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 22.00545 578.8215 364.0443 NaN  Inf 0.03621385 0.0002286151
# Print Model Parameters
model_TBATS
## TBATS(1, {0,0}, 1, {<6,2>})
## 
## Call: NULL
## 
## Parameters
##   Alpha: 1.049738
##   Beta: 0.9036269
##   Damping Parameter: 1
##   Gamma-1 Values: -0.001403385
##   Gamma-2 Values: 0.001001786
## 
## Seed States:
##            [,1]
## [1,] -30.399350
## [2,] -11.506873
## [3,]  -3.666777
## [4,]  12.648037
## [5,]   2.876446
## [6,]  -8.251949
## 
## Sigma: 578.8215
## AIC: 8434.572
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 Russia"
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 Russia"
paste(MAPE_Mean_All.TBATS,"%")
## [1] "0.079 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Russia %"
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 Russia"
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                | 4492692.00  | 4492409.27        | 0.006 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 2  | 2021-03-26 | Friday                  | 4501859.00  | 4501249.68        | 0.014 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 3  | 2021-03-27 | Saturday                | 4510744.00  | 4510104.71        | 0.014 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 4  | 2021-03-28 | Sunday                  | 4519832.00  | 4519031.81        | 0.018 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 5  | 2021-03-29 | Monday                  | 4528543.00  | 4527886.12        | 0.015 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 6  | 2021-03-30 | Tuesday                 | 4536820.00  | 4536749.49        | 0.002 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 7  | 2021-03-31 | Wednesday               | 4545095.00  | 4545671.03        | 0.013 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 8  | 2021-04-01 | Thursday                | 4554264.00  | 4554511.44        | 0.005 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 9  | 2021-04-02 | Friday                  | 4563056.00  | 4563366.47        | 0.007 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 10 | 2021-04-03 | Saturday                | 4572077.00  | 4572293.57        | 0.005 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 11 | 2021-04-04 | Sunday                  | 4580894.00  | 4581147.89        | 0.006 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 12 | 2021-04-05 | Monday                  | 4589540.00  | 4590011.26        | 0.01 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 13 | 2021-04-06 | Tuesday                 | 4597868.00  | 4598932.80        | 0.023 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 14 | 2021-04-07 | Wednesday               | 4606162.00  | 4607773.20        | 0.035 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 15 | 2021-04-08 | Thursday                | 4614834.00  | 4616628.24        | 0.039 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 16 | 2021-04-09 | Friday                  | 4623984.00  | 4625555.34        | 0.034 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 17 | 2021-04-10 | Saturday                | 4632688.00  | 4634409.65        | 0.037 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 18 | 2021-04-11 | Sunday                  | 4641390.00  | 4643273.02        | 0.041 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 19 | 2021-04-12 | Monday                  | 4649710.00  | 4652194.56        | 0.053 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 20 | 2021-04-13 | Tuesday                 | 4657883.00  | 4661034.97        | 0.068 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 21 | 2021-04-14 | Wednesday               | 4666209.00  | 4669890.00        | 0.079 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 22 | 2021-04-15 | Thursday                | 4675153.00  | 4678817.10        | 0.078 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 23 | 2021-04-16 | Friday                  | 4684148.00  | 4687671.41        | 0.075 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 24 | 2021-04-17 | Saturday                | 4693469.00  | 4696534.79        | 0.065 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 25 | 2021-04-18 | Sunday                  | 4702101.00  | 4705456.32        | 0.071 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 26 | 2021-04-19 | Monday                  | 4710690.00  | 4714296.73        | 0.077 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 27 | 2021-04-20 | Tuesday                 | 4718854.00  | 4723151.77        | 0.091 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 28 | 2021-04-21 | Wednesday               | 4727125.00  | 4732078.87        | 0.105 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 29 | 2021-04-22 | Thursday                | 4736121.00  | 4740933.18        | 0.102 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 30 | 2021-04-23 | Friday                  | 4744961.00  | 4749796.55        | 0.102 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 31 | 2021-04-24 | Saturday                | 4753789.00  | 4758718.09        | 0.104 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 32 | 2021-04-25 | Sunday                  | 4762569.00  | 4767558.50        | 0.105 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 33 | 2021-04-26 | Monday                  | 4771372.00  | 4776413.53        | 0.106 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 34 | 2021-04-27 | Tuesday                 | 4779425.00  | 4785340.63        | 0.124 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 35 | 2021-04-28 | Wednesday               | 4787273.00  | 4794194.94        | 0.145 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 36 | 2021-04-29 | Thursday                | 4796557.00  | 4803058.31        | 0.136 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 37 | 2021-04-30 | Friday                  | 4805288.00  | 4811979.85        | 0.139 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 38 | 2021-05-01 | Saturday                | 4814558.00  | 4820820.26        | 0.13 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 39 | 2021-05-02 | Sunday                  | 4823255.00  | 4829675.29        | 0.133 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 40 | 2021-05-03 | Monday                  | 4831744.00  | 4838602.39        | 0.142 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 41 | 2021-05-04 | Tuesday                 | 4839514.00  | 4847456.70        | 0.164 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 42 | 2021-05-05 | Wednesday               | 4847489.00  | 4856320.08        | 0.182 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 43 | 2021-05-06 | Thursday                | 4855128.00  | 4865241.61        | 0.208 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 44 | 2021-05-07 | Friday                  | 4863514.00  | 4874082.02        | 0.217 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 45 | 2021-05-08 | Saturday                | 4871843.00  | 4882937.06        | 0.228 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
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          | 4891864.16           | 4886746.30 | 4884037.07 | 4896982.01 | 4899691.24 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4900718.47           | 4895548.44 | 4892811.60 | 4905888.49 | 4908625.33 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4909581.84           | 4904360.64 | 4901596.70 | 4914803.04 | 4917566.98 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4918503.38           | 4913231.78 | 4910441.16 | 4923774.98 | 4926565.59 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4927343.79           | 4922022.24 | 4919205.19 | 4932665.33 | 4935482.38 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4936198.82           | 4930827.93 | 4927984.75 | 4941569.71 | 4944412.89 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4945125.92           | 4939706.13 | 4936837.07 | 4950545.71 | 4953414.77 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4953980.23           | 4948511.99 | 4945617.28 | 4959448.47 | 4962343.18 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4962843.60           | 4957327.77 | 4954407.87 | 4968359.44 | 4971279.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4971765.14           | 4966202.39 | 4963257.65 | 4977327.89 | 4980272.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4980605.55           | 4974996.26 | 4972026.87 | 4986214.84 | 4989184.23 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4989460.58           | 4983805.25 | 4980811.50 | 4995115.92 | 4998109.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4998387.68           | 4992686.69 | 4989668.76 | 5004088.68 | 5007106.61 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 5007241.99           | 5001495.70 | 4998453.79 | 5012988.29 | 5016030.20 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 5016105.37           | 5010314.54 | 5007249.06 | 5021896.19 | 5024961.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 5025026.91           | 5019192.14 | 5016103.41 | 5030861.67 | 5033950.40 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 5033867.31           | 5027988.92 | 5024877.09 | 5039745.71 | 5042857.54 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 5042722.35           | 5036800.76 | 5033666.07 | 5048643.93 | 5051778.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 5051649.45           | 5045684.99 | 5042527.59 | 5057613.91 | 5060771.30 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5060503.76           | 5054496.73 | 5051316.80 | 5066510.78 | 5069690.71 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5069367.13           | 5063318.23 | 5060116.13 | 5075416.03 | 5078618.13 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5078288.67           | 5072198.42 | 5068974.44 | 5084378.92 | 5087602.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 -56.75677 614.1658 385.8766 NaN  Inf 0.03838565 0.3115108
# 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.5839 
## 
##   Smoothing parameters:
##     alpha = 0.9555 
##     beta  = 0.6374 
## 
##   Initial states:
##     l = -2.0666 
##     b = -0.5033 
## 
##   sigma:  3.3382
## 
##      AIC     AICc      BIC 
## 3811.471 3811.607 3831.984 
## 
## Training set error measures:
##                     ME     RMSE      MAE MPE MAPE       MASE      ACF1
## Training set -56.75677 614.1658 385.8766 NaN  Inf 0.03838565 0.3115108
# 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 Russia"
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 Russia"
paste(MAPE_Mean_All.Holt,"%")
## [1] "0.099 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Russia %"
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 Russia"
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                | 4492692.00  | 4492282.13       | 0.009 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 4501859.00  | 4501102.39       | 0.017 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 4510744.00  | 4509929.84       | 0.018 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 4519832.00  | 4518764.49       | 0.024 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 4528543.00  | 4527606.33       | 0.021 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 4536820.00  | 4536455.36       | 0.008 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 4545095.00  | 4545311.58       | 0.005 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 4554264.00  | 4554174.99       | 0.002 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 4563056.00  | 4563045.58       | 0 %             |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 4572077.00  | 4571923.36       | 0.003 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 4580894.00  | 4580808.31       | 0.002 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 4589540.00  | 4589700.44       | 0.003 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 4597868.00  | 4598599.74       | 0.016 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 4606162.00  | 4607506.22       | 0.029 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 4614834.00  | 4616419.86       | 0.034 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 4623984.00  | 4625340.68       | 0.029 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 4632688.00  | 4634268.66       | 0.034 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 4641390.00  | 4643203.80       | 0.039 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 4649710.00  | 4652146.10       | 0.052 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 4657883.00  | 4661095.56       | 0.069 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 4666209.00  | 4670052.18       | 0.082 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 4675153.00  | 4679015.95       | 0.083 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 4684148.00  | 4687986.87       | 0.082 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 4693469.00  | 4696964.94       | 0.074 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 4702101.00  | 4705950.16       | 0.082 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 4710690.00  | 4714942.52       | 0.09 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 4718854.00  | 4723942.03       | 0.108 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 4727125.00  | 4732948.67       | 0.123 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 4736121.00  | 4741962.45       | 0.123 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 4744961.00  | 4750983.37       | 0.127 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 4753789.00  | 4760011.42       | 0.131 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 4762569.00  | 4769046.60       | 0.136 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 4771372.00  | 4778088.91       | 0.141 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 4779425.00  | 4787138.35       | 0.161 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 4787273.00  | 4796194.91       | 0.186 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 4796557.00  | 4805258.59       | 0.181 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4805288.00  | 4814329.40       | 0.188 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4814558.00  | 4823407.32       | 0.184 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4823255.00  | 4832492.35       | 0.192 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4831744.00  | 4841584.50       | 0.204 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4839514.00  | 4850683.76       | 0.231 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4847489.00  | 4859790.12       | 0.254 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4855128.00  | 4868903.59       | 0.284 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4863514.00  | 4878024.17       | 0.298 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4871843.00  | 4887151.85       | 0.314 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 4896286.63          | 4592003.22 | 4434225.87 | 5208650.26 | 5377247.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4905428.50          | 4591267.78 | 4428476.81 | 5228193.65 | 5402506.85 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4914577.47          | 4590431.53 | 4422578.97 | 5247874.11 | 5427980.49 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4923733.53          | 4589495.53 | 4416534.18 | 5267691.04 | 5453667.99 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4932896.68          | 4588460.81 | 4410344.19 | 5287643.84 | 5479568.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4942066.92          | 4587328.37 | 4404010.74 | 5307731.96 | 5505681.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4951244.25          | 4586099.18 | 4397535.51 | 5327954.86 | 5532006.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4960428.66          | 4584774.21 | 4390920.14 | 5348312.04 | 5558542.60 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4969620.16          | 4583354.36 | 4384166.25 | 5368802.99 | 5585289.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4978818.73          | 4581840.56 | 4377275.41 | 5389427.27 | 5612245.98 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4988024.38          | 4580233.67 | 4370249.17 | 5410184.42 | 5639412.27 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4997237.10          | 4578534.57 | 4363089.05 | 5431074.03 | 5666787.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 5006456.90          | 4576744.09 | 4355796.51 | 5452095.68 | 5694371.61 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 5015683.77          | 4574863.06 | 4348373.04 | 5473248.99 | 5722163.79 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 5024917.70          | 4572892.29 | 4340820.04 | 5494533.59 | 5750163.77 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 5034158.71          | 4570832.57 | 4333138.93 | 5515949.12 | 5778371.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 5043406.77          | 4568684.67 | 4325331.08 | 5537495.25 | 5806785.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 5052661.90          | 4566449.35 | 4317397.84 | 5559171.66 | 5835406.91 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 5061924.09          | 4564127.34 | 4309340.55 | 5580978.04 | 5864234.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5071193.34          | 4561719.39 | 4301160.52 | 5602914.10 | 5893268.43 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5080469.64          | 4559226.19 | 4292859.03 | 5624979.55 | 5922508.16 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5089753.00          | 4556648.46 | 4284437.36 | 5647174.13 | 5951953.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
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 Russia"
kpss.test(data_series) # applay kpss test
## Warning in kpss.test(data_series): p-value smaller than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  data_series
## KPSS Level = 6.7863, Truncation lag parameter = 5, p-value = 0.01
pp.test(data_series)   # applay pp test
## 
##  Phillips-Perron Unit Root Test
## 
## data:  data_series
## Dickey-Fuller Z(alpha) = -0.86577, Truncation lag parameter = 5,
## p-value = 0.9895
## alternative hypothesis: stationary
adf.test(data_series)  # applay adf test
## Warning in adf.test(data_series): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  data_series
## Dickey-Fuller = -4.5406, Lag order = 7, p-value = 0.01
## 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 Russia"
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.9323, 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 greater than printed p-value
## 
##  Phillips-Perron Unit Root Test
## 
## data:  diff1_x1
## Dickey-Fuller Z(alpha) = 0.55875, Truncation lag parameter = 5, p-value
## = 0.99
## alternative hypothesis: stationary
adf.test(diff1_x1)    # applay adf test after taking first differences
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff1_x1
## Dickey-Fuller = -0.94606, Lag order = 7, p-value = 0.9471
## 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 Russia"
kpss.test(diff2_x1)   # applay kpss test after taking Second differences
## 
##  KPSS Test for Level Stationarity
## 
## data:  diff2_x1
## KPSS Level = 0.617, Truncation lag parameter = 5, p-value = 0.02109
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) = -445.54, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
adf.test(diff2_x1)    # applay adf test after taking Second differences
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff2_x1
## Dickey-Fuller = -3.6431, Lag order = 7, p-value = 0.02877
## 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)                    : 6932.144
##  ARIMA(0,2,1)                    : 6933.117
##  ARIMA(0,2,2)                    : 6934.51
##  ARIMA(0,2,3)                    : 6936.517
##  ARIMA(0,2,4)                    : 6937.177
##  ARIMA(0,2,5)                    : 6917.505
##  ARIMA(1,2,0)                    : 6933.199
##  ARIMA(1,2,1)                    : 6934.758
##  ARIMA(1,2,2)                    : 6936.535
##  ARIMA(1,2,3)                    : Inf
##  ARIMA(1,2,4)                    : 6893.29
##  ARIMA(2,2,0)                    : 6934.522
##  ARIMA(2,2,1)                    : 6936.51
##  ARIMA(2,2,2)                    : 6938.548
##  ARIMA(2,2,3)                    : Inf
##  ARIMA(3,2,0)                    : 6936.45
##  ARIMA(3,2,1)                    : Inf
##  ARIMA(3,2,2)                    : Inf
##  ARIMA(4,2,0)                    : 6938.363
##  ARIMA(4,2,1)                    : 6939.415
##  ARIMA(5,2,0)                    : 6939.092
## 
## 
## 
##  Best model: ARIMA(1,2,4)
model1 # show the result of autoarima 
## Series: data_series 
## ARIMA(1,2,4) 
## 
## Coefficients:
##          ar1      ma1      ma2     ma3     ma4
##       0.7214  -0.8886  -0.0446  0.0836  0.2503
## s.e.  0.0676   0.0742   0.0673  0.0592  0.0524
## 
## sigma^2 estimated as 306932:  log likelihood=-3440.55
## AIC=6893.1   AICc=6893.29   BIC=6917.69
#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] 1 2 4
strtoi(bestmodel[3])
## [1] 4
#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      ma1      ma2     ma3     ma4
##       0.7214  -0.8886  -0.0446  0.0836  0.2503
## s.e.  0.0676   0.0742   0.0673  0.0592  0.0524
## 
## sigma^2 estimated as 303483:  log likelihood = -3440.55,  aic = 6893.1
paste ("accuracy of autoarima Model For  ==> ",y_lab, sep=" ")
## [1] "accuracy of autoarima Model For  ==>  Forecasting cumulative Covid 19 Infection cases in Russia"
accuracy(x1_model1)  # aacuracy of best model from auto arima
##                    ME     RMSE      MAE       MPE     MAPE       MASE
## Training set 12.28731 549.6594 338.2559 0.3124402 2.246239 0.03364851
##                    ACF1
## Training set 0.01098464
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(1,2,4)
## Q* = 53.974, df = 5, p-value = 2.121e-10
## 
## 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 Russia"
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 = 541.88, 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 = 162.6, 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 Russia"
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 Russia"
paste(MAPE_Mean_All.ARIMA,"%")
## [1] "0.316 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Russia %"
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 Russia"
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                | 4492692.00  | 4492391.89             | 0.007 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 2  | 2021-03-26      | Friday                  | 4501859.00  | 4501209.49             | 0.014 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 3  | 2021-03-27      | Saturday                | 4510744.00  | 4509723.90             | 0.023 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 4  | 2021-03-28      | Sunday                  | 4519832.00  | 4518066.44             | 0.039 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 5  | 2021-03-29      | Monday                  | 4528543.00  | 4526284.98             | 0.05 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 6  | 2021-03-30      | Tuesday                 | 4536820.00  | 4534414.07             | 0.053 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 7  | 2021-03-31      | Wednesday               | 4545095.00  | 4542478.62             | 0.058 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 8  | 2021-04-01      | Thursday                | 4554264.00  | 4550496.62             | 0.083 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 9  | 2021-04-02      | Friday                  | 4563056.00  | 4558481.04             | 0.1 %                 |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 10 | 2021-04-03      | Saturday                | 4572077.00  | 4566441.22             | 0.123 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 11 | 2021-04-04      | Sunday                  | 4580894.00  | 4574383.92             | 0.142 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 12 | 2021-04-05      | Monday                  | 4589540.00  | 4582314.01             | 0.157 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 13 | 2021-04-06      | Tuesday                 | 4597868.00  | 4590235.01             | 0.166 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 14 | 2021-04-07      | Wednesday               | 4606162.00  | 4598149.44             | 0.174 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 15 | 2021-04-08      | Thursday                | 4614834.00  | 4606059.14             | 0.19 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 16 | 2021-04-09      | Friday                  | 4623984.00  | 4613965.42             | 0.217 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 17 | 2021-04-10      | Saturday                | 4632688.00  | 4621869.24             | 0.234 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 18 | 2021-04-11      | Sunday                  | 4641390.00  | 4629771.28             | 0.25 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 19 | 2021-04-12      | Monday                  | 4649710.00  | 4637672.03             | 0.259 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 20 | 2021-04-13      | Tuesday                 | 4657883.00  | 4645571.87             | 0.264 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 21 | 2021-04-14      | Wednesday               | 4666209.00  | 4653471.03             | 0.273 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 22 | 2021-04-15      | Thursday                | 4675153.00  | 4661369.71             | 0.295 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 23 | 2021-04-16      | Friday                  | 4684148.00  | 4669268.05             | 0.318 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 24 | 2021-04-17      | Saturday                | 4693469.00  | 4677166.14             | 0.347 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 25 | 2021-04-18      | Sunday                  | 4702101.00  | 4685064.04             | 0.362 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 26 | 2021-04-19      | Monday                  | 4710690.00  | 4692961.81             | 0.376 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 27 | 2021-04-20      | Tuesday                 | 4718854.00  | 4700859.49             | 0.381 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 28 | 2021-04-21      | Wednesday               | 4727125.00  | 4708757.11             | 0.389 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 29 | 2021-04-22      | Thursday                | 4736121.00  | 4716654.67             | 0.411 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 30 | 2021-04-23      | Friday                  | 4744961.00  | 4724552.20             | 0.43 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 31 | 2021-04-24      | Saturday                | 4753789.00  | 4732449.70             | 0.449 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 32 | 2021-04-25      | Sunday                  | 4762569.00  | 4740347.18             | 0.467 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 33 | 2021-04-26      | Monday                  | 4771372.00  | 4748244.65             | 0.485 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 34 | 2021-04-27      | Tuesday                 | 4779425.00  | 4756142.11             | 0.487 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 35 | 2021-04-28      | Wednesday               | 4787273.00  | 4764039.57             | 0.485 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 36 | 2021-04-29      | Thursday                | 4796557.00  | 4771937.02             | 0.513 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 37 | 2021-04-30      | Friday                  | 4805288.00  | 4779834.46             | 0.53 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 38 | 2021-05-01      | Saturday                | 4814558.00  | 4787731.90             | 0.557 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 39 | 2021-05-02      | Sunday                  | 4823255.00  | 4795629.35             | 0.573 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 40 | 2021-05-03      | Monday                  | 4831744.00  | 4803526.79             | 0.584 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 41 | 2021-05-04      | Tuesday                 | 4839514.00  | 4811424.22             | 0.58 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 42 | 2021-05-05      | Wednesday               | 4847489.00  | 4819321.66             | 0.581 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 43 | 2021-05-06      | Thursday                | 4855128.00  | 4827219.10             | 0.575 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 44 | 2021-05-07      | Friday                  | 4863514.00  | 4835116.54             | 0.584 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 45 | 2021-05-08      | Saturday                | 4871843.00  | 4843013.97             | 0.592 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
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          | 4850911.41                | 4684217.55 | 4595975.15 | 5017605.27 | 5105847.67 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4858808.85                | 4686306.09 | 4594988.65 | 5031311.60 | 5122629.04 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4866706.28                | 4688328.29 | 4593900.69 | 5045084.27 | 5139511.87 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4874603.72                | 4690284.90 | 4592712.41 | 5058922.54 | 5156495.03 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4882501.16                | 4692176.64 | 4591424.93 | 5072825.67 | 5173577.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4890398.59                | 4694004.22 | 4590039.31 | 5086792.97 | 5190757.87 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4898296.03                | 4695768.31 | 4588556.62 | 5100823.74 | 5208035.44 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4906193.46                | 4697469.59 | 4586977.84 | 5114917.34 | 5225409.09 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4914090.90                | 4699108.67 | 4585303.96 | 5129073.13 | 5242877.84 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4921988.34                | 4700686.20 | 4583535.92 | 5143290.47 | 5260440.75 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4929885.77                | 4702202.76 | 4581674.65 | 5157568.79 | 5278096.89 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4937783.21                | 4703658.94 | 4579721.03 | 5171907.48 | 5295845.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4945680.64                | 4705055.30 | 4577675.94 | 5186305.99 | 5313685.35 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4953578.08                | 4706392.40 | 4575540.20 | 5200763.76 | 5331615.96 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4961475.52                | 4707670.77 | 4573314.65 | 5215280.26 | 5349636.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4969372.95                | 4708890.93 | 4571000.08 | 5229854.97 | 5367745.83 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4977270.39                | 4710053.39 | 4568597.26 | 5244487.39 | 5385943.52 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4985167.83                | 4711158.65 | 4566106.95 | 5259177.00 | 5404228.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4993065.26                | 4712207.17 | 4563529.88 | 5273923.35 | 5422600.64 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5000962.70                | 4713199.45 | 4560866.78 | 5288725.95 | 5441058.61 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5008860.13                | 4714135.92 | 4558118.34 | 5303584.35 | 5459601.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5016757.57                | 4715017.04 | 4555285.25 | 5318498.10 | 5478229.89 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
plot(forecasting_auto_arima)
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) )
lines(x1_test, col='red',lwd=2)

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

MAPE_Mean_All.ARIMA
## [1] "0.316 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Russia"
## 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 Russia"
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 Russia"
paste(MAPE_Mean_EnsemblingAverage,"%")
## [1] "0.018 %"
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 Russia"
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                | 4492692.00  | 4492241.64 | 0.01 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 2  | 2021-03-26      | Friday                  | 4501859.00  | 4500991.56 | 0.019 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 3  | 2021-03-27      | Saturday                | 4510744.00  | 4509730.72 | 0.022 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 4  | 2021-03-28      | Sunday                  | 4519832.00  | 4518463.95 | 0.03 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 5  | 2021-03-29      | Monday                  | 4528543.00  | 4527188.93 | 0.03 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 6  | 2021-03-30      | Tuesday                 | 4536820.00  | 4535908.68 | 0.02 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 7  | 2021-03-31      | Wednesday               | 4545095.00  | 4544625.13 | 0.01 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 8  | 2021-04-01      | Thursday                | 4554264.00  | 4553335.37 | 0.02 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 9  | 2021-04-02      | Friday                  | 4563056.00  | 4562042.20 | 0.022 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 10 | 2021-04-03      | Saturday                | 4572077.00  | 4570747.39 | 0.029 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 11 | 2021-04-04      | Sunday                  | 4580894.00  | 4579447.58 | 0.032 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 12 | 2021-04-05      | Monday                  | 4589540.00  | 4588145.02 | 0.03 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 13 | 2021-04-06      | Tuesday                 | 4597868.00  | 4596841.12 | 0.022 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 14 | 2021-04-07      | Wednesday               | 4606162.00  | 4605532.55 | 0.014 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 15 | 2021-04-08      | Thursday                | 4614834.00  | 4614221.84 | 0.013 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 16 | 2021-04-09      | Friday                  | 4623984.00  | 4622910.52 | 0.023 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 17 | 2021-04-10      | Saturday                | 4632688.00  | 4631595.08 | 0.024 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 18 | 2021-04-11      | Sunday                  | 4641390.00  | 4640277.67 | 0.024 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 19 | 2021-04-12      | Monday                  | 4649710.00  | 4648959.60 | 0.016 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 20 | 2021-04-13      | Tuesday                 | 4657883.00  | 4657637.47 | 0.005 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 21 | 2021-04-14      | Wednesday               | 4666209.00  | 4666313.75 | 0.002 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 22 | 2021-04-15      | Thursday                | 4675153.00  | 4674989.95 | 0.003 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 23 | 2021-04-16      | Friday                  | 4684148.00  | 4683662.53 | 0.01 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 24 | 2021-04-17      | Saturday                | 4693469.00  | 4692333.59 | 0.024 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 25 | 2021-04-18      | Sunday                  | 4702101.00  | 4701004.43 | 0.023 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 26 | 2021-04-19      | Monday                  | 4710690.00  | 4709671.62 | 0.022 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 27 | 2021-04-20      | Tuesday                 | 4718854.00  | 4718337.63 | 0.011 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 28 | 2021-04-21      | Wednesday               | 4727125.00  | 4727003.95 | 0.003 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 29 | 2021-04-22      | Thursday                | 4736121.00  | 4735667.02 | 0.01 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 30 | 2021-04-23      | Friday                  | 4744961.00  | 4744328.93 | 0.013 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 31 | 2021-04-24      | Saturday                | 4753789.00  | 4752990.96 | 0.017 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 32 | 2021-04-25      | Sunday                  | 4762569.00  | 4761649.69 | 0.019 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 33 | 2021-04-26      | Monday                  | 4771372.00  | 4770307.56 | 0.022 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 34 | 2021-04-27      | Tuesday                 | 4779425.00  | 4778966.06 | 0.01 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 35 | 2021-04-28      | Wednesday               | 4787273.00  | 4787621.60 | 0.007 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 36 | 2021-04-29      | Thursday                | 4796557.00  | 4796276.28 | 0.006 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 37 | 2021-04-30      | Friday                  | 4805288.00  | 4804931.38 | 0.007 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 38 | 2021-05-01      | Saturday                | 4814558.00  | 4813583.44 | 0.02 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 39 | 2021-05-02      | Sunday                  | 4823255.00  | 4822234.92 | 0.021 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 40 | 2021-05-03      | Monday                  | 4831744.00  | 4830887.27 | 0.018 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 41 | 2021-05-04      | Tuesday                 | 4839514.00  | 4839536.93 | 0 %             |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 42 | 2021-05-05      | Wednesday               | 4847489.00  | 4848185.96 | 0.014 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 43 | 2021-05-06      | Thursday                | 4855128.00  | 4856835.65 | 0.035 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 44 | 2021-05-07      | Friday                  | 4863514.00  | 4865482.53 | 0.04 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 45 | 2021-05-08      | Saturday                | 4871843.00  | 4874129.03 | 0.047 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
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          | 4882776.63                |
## +----+------------+-----------------+---------------------------+
## | 2  | 2021-05-10 | Monday          | 4891421.73                |
## +----+------------+-----------------+---------------------------+
## | 3  | 2021-05-11 | Tuesday         | 4900066.42                |
## +----+------------+-----------------+---------------------------+
## | 4  | 2021-05-12 | Wednesday       | 4908711.94                |
## +----+------------+-----------------+---------------------------+
## | 5  | 2021-05-13 | Thursday        | 4917354.84                |
## +----+------------+-----------------+---------------------------+
## | 6  | 2021-05-14 | Friday          | 4925997.54                |
## +----+------------+-----------------+---------------------------+
## | 7  | 2021-05-15 | Saturday        | 4934641.51                |
## +----+------------+-----------------+---------------------------+
## | 8  | 2021-05-16 | Sunday          | 4943283.15                |
## +----+------------+-----------------+---------------------------+
## | 9  | 2021-05-17 | Monday          | 4951924.53                |
## +----+------------+-----------------+---------------------------+
## | 10 | 2021-05-18 | Tuesday         | 4960566.91                |
## +----+------------+-----------------+---------------------------+
## | 11 | 2021-05-19 | Wednesday       | 4969206.81                |
## +----+------------+-----------------+---------------------------+
## | 12 | 2021-05-20 | Thursday        | 4977846.66                |
## +----+------------+-----------------+---------------------------+
## | 13 | 2021-05-21 | Friday          | 4986487.92                |
## +----+------------+-----------------+---------------------------+
## | 14 | 2021-05-22 | Saturday        | 4995126.99                |
## +----+------------+-----------------+---------------------------+
## | 15 | 2021-05-23 | Sunday          | 5003765.92                |
## +----+------------+-----------------+---------------------------+
## | 16 | 2021-05-24 | Monday          | 5012405.97                |
## +----+------------+-----------------+---------------------------+
## | 17 | 2021-05-25 | Tuesday         | 5021043.67                |
## +----+------------+-----------------+---------------------------+
## | 18 | 2021-05-26 | Wednesday       | 5029681.44                |
## +----+------------+-----------------+---------------------------+
## | 19 | 2021-05-27 | Thursday        | 5038320.73                |
## +----+------------+-----------------+---------------------------+
## | 20 | 2021-05-28 | Friday          | 5046957.93                |
## +----+------------+-----------------+---------------------------+
## | 21 | 2021-05-29 | Saturday        | 5055595.10                |
## +----+------------+-----------------+---------------------------+
## | 22 | 2021-05-30 | Sunday          | 5064233.50                |
## +----+------------+-----------------+---------------------------+
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 Russia"
best_recommended_model
## [1] 0.018
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 Russia"
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          | 4891092.99          | 4766162.14 | 4700027.74 | 4766162.14 | 4700027.74 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4899954.05          | 4770983.07 | 4702709.95 | 4770983.07 | 4702709.95 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4908815.11          | 4775761.36 | 4705326.96 | 4775761.36 | 4705326.96 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4917676.16          | 4780497.47 | 4707879.46 | 4780497.47 | 4707879.46 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4926537.22          | 4785191.82 | 4710368.08 | 4785191.82 | 4710368.08 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4935398.27          | 4789844.82 | 4712793.47 | 4789844.82 | 4712793.47 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4944259.33          | 4794456.87 | 4715156.24 | 4794456.87 | 4715156.24 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4953120.38          | 4799028.37 | 4717456.98 | 4799028.37 | 4717456.98 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4961981.44          | 4803559.70 | 4719696.29 | 4803559.70 | 4719696.29 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4970842.50          | 4808051.22 | 4721874.72 | 4808051.22 | 4721874.72 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4979703.55          | 4812503.29 | 4723992.82 | 4812503.29 | 4723992.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4988564.61          | 4816916.27 | 4726051.13 | 4816916.27 | 4726051.13 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4997425.66          | 4821290.49 | 4728050.17 | 4821290.49 | 4728050.17 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 5006286.72          | 4825626.29 | 4729990.44 | 4825626.29 | 4729990.44 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 5015147.77          | 4829924.00 | 4731872.45 | 4829924.00 | 4731872.45 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 5024008.83          | 4834183.91 | 4733696.67 | 4834183.91 | 4733696.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 5032869.89          | 4838406.35 | 4735463.57 | 4838406.35 | 4735463.57 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 5041730.94          | 4842591.61 | 4737173.62 | 4842591.61 | 4737173.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 5050592.00          | 4846739.99 | 4738827.26 | 4846739.99 | 4738827.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5059453.05          | 4850851.77 | 4740424.93 | 4850851.77 | 4740424.93 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5068314.11          | 4854927.24 | 4741967.06 | 4854927.24 | 4741967.06 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5077175.16          | 4858966.66 | 4743454.06 | 4858966.66 | 4743454.06 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using TBATS Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using TBATS Model  ==>  Forecasting cumulative Covid 19 Infection cases in Russia"
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          | 4891864.16           | 4886746.30 | 4884037.07 | 4896982.01 | 4899691.24 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4900718.47           | 4895548.44 | 4892811.60 | 4905888.49 | 4908625.33 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4909581.84           | 4904360.64 | 4901596.70 | 4914803.04 | 4917566.98 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4918503.38           | 4913231.78 | 4910441.16 | 4923774.98 | 4926565.59 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4927343.79           | 4922022.24 | 4919205.19 | 4932665.33 | 4935482.38 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4936198.82           | 4930827.93 | 4927984.75 | 4941569.71 | 4944412.89 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4945125.92           | 4939706.13 | 4936837.07 | 4950545.71 | 4953414.77 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4953980.23           | 4948511.99 | 4945617.28 | 4959448.47 | 4962343.18 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4962843.60           | 4957327.77 | 4954407.87 | 4968359.44 | 4971279.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4971765.14           | 4966202.39 | 4963257.65 | 4977327.89 | 4980272.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4980605.55           | 4974996.26 | 4972026.87 | 4986214.84 | 4989184.23 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4989460.58           | 4983805.25 | 4980811.50 | 4995115.92 | 4998109.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4998387.68           | 4992686.69 | 4989668.76 | 5004088.68 | 5007106.61 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 5007241.99           | 5001495.70 | 4998453.79 | 5012988.29 | 5016030.20 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 5016105.37           | 5010314.54 | 5007249.06 | 5021896.19 | 5024961.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 5025026.91           | 5019192.14 | 5016103.41 | 5030861.67 | 5033950.40 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 5033867.31           | 5027988.92 | 5024877.09 | 5039745.71 | 5042857.54 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 5042722.35           | 5036800.76 | 5033666.07 | 5048643.93 | 5051778.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 5051649.45           | 5045684.99 | 5042527.59 | 5057613.91 | 5060771.30 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5060503.76           | 5054496.73 | 5051316.80 | 5066510.78 | 5069690.71 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5069367.13           | 5063318.23 | 5060116.13 | 5075416.03 | 5078618.13 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5078288.67           | 5072198.42 | 5068974.44 | 5084378.92 | 5087602.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 Russia"
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          | 4896286.63          | 4592003.22 | 4434225.87 | 5208650.26 | 5377247.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4905428.50          | 4591267.78 | 4428476.81 | 5228193.65 | 5402506.85 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4914577.47          | 4590431.53 | 4422578.97 | 5247874.11 | 5427980.49 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4923733.53          | 4589495.53 | 4416534.18 | 5267691.04 | 5453667.99 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4932896.68          | 4588460.81 | 4410344.19 | 5287643.84 | 5479568.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4942066.92          | 4587328.37 | 4404010.74 | 5307731.96 | 5505681.69 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4951244.25          | 4586099.18 | 4397535.51 | 5327954.86 | 5532006.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4960428.66          | 4584774.21 | 4390920.14 | 5348312.04 | 5558542.60 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4969620.16          | 4583354.36 | 4384166.25 | 5368802.99 | 5585289.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4978818.73          | 4581840.56 | 4377275.41 | 5389427.27 | 5612245.98 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4988024.38          | 4580233.67 | 4370249.17 | 5410184.42 | 5639412.27 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4997237.10          | 4578534.57 | 4363089.05 | 5431074.03 | 5666787.62 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 5006456.90          | 4576744.09 | 4355796.51 | 5452095.68 | 5694371.61 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 5015683.77          | 4574863.06 | 4348373.04 | 5473248.99 | 5722163.79 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 5024917.70          | 4572892.29 | 4340820.04 | 5494533.59 | 5750163.77 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 5034158.71          | 4570832.57 | 4333138.93 | 5515949.12 | 5778371.18 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 5043406.77          | 4568684.67 | 4325331.08 | 5537495.25 | 5806785.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 5052661.90          | 4566449.35 | 4317397.84 | 5559171.66 | 5835406.91 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 5061924.09          | 4564127.34 | 4309340.55 | 5580978.04 | 5864234.59 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5071193.34          | 4561719.39 | 4301160.52 | 5602914.10 | 5893268.43 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5080469.64          | 4559226.19 | 4292859.03 | 5624979.55 | 5922508.16 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5089753.00          | 4556648.46 | 4284437.36 | 5647174.13 | 5951953.55 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using ARIMA Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using ARIMA Model  ==>  Forecasting cumulative Covid 19 Infection cases in Russia"
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          | 4850911.41                | 4684217.55 | 4595975.15 | 5017605.27 | 5105847.67 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4858808.85                | 4686306.09 | 4594988.65 | 5031311.60 | 5122629.04 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4866706.28                | 4688328.29 | 4593900.69 | 5045084.27 | 5139511.87 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4874603.72                | 4690284.90 | 4592712.41 | 5058922.54 | 5156495.03 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4882501.16                | 4692176.64 | 4591424.93 | 5072825.67 | 5173577.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4890398.59                | 4694004.22 | 4590039.31 | 5086792.97 | 5190757.87 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4898296.03                | 4695768.31 | 4588556.62 | 5100823.74 | 5208035.44 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4906193.46                | 4697469.59 | 4586977.84 | 5114917.34 | 5225409.09 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4914090.90                | 4699108.67 | 4585303.96 | 5129073.13 | 5242877.84 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4921988.34                | 4700686.20 | 4583535.92 | 5143290.47 | 5260440.75 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4929885.77                | 4702202.76 | 4581674.65 | 5157568.79 | 5278096.89 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4937783.21                | 4703658.94 | 4579721.03 | 5171907.48 | 5295845.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4945680.64                | 4705055.30 | 4577675.94 | 5186305.99 | 5313685.35 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4953578.08                | 4706392.40 | 4575540.20 | 5200763.76 | 5331615.96 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4961475.52                | 4707670.77 | 4573314.65 | 5215280.26 | 5349636.38 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4969372.95                | 4708890.93 | 4571000.08 | 5229854.97 | 5367745.83 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4977270.39                | 4710053.39 | 4568597.26 | 5244487.39 | 5385943.52 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4985167.83                | 4711158.65 | 4566106.95 | 5259177.00 | 5404228.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4993065.26                | 4712207.17 | 4563529.88 | 5273923.35 | 5422600.64 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 5000962.70                | 4713199.45 | 4560866.78 | 5288725.95 | 5441058.61 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 5008860.13                | 4714135.92 | 4558118.34 | 5303584.35 | 5459601.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 5016757.57                | 4715017.04 | 4555285.25 | 5318498.10 | 5478229.89 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
paste("Forecasting by using NNAR Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using NNAR Model  ==>  Forecasting cumulative Covid 19 Infection cases in Russia"
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          | 4592655.24          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 4593567.72          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 4594447.23          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 4595294.96          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 4596112.02          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 4596899.50          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 4597658.47          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 4598389.93          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 4599094.86          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 4599774.22          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 4600428.92          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 4601059.84          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 4601667.84          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 4602253.73          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 4602818.31          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 4603362.35          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 4603886.58          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 4604391.72          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 4604878.46          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 4605347.46          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 4605799.36          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 4606234.78          |
## +----+------------+-----------------+---------------------+
paste("Forecasting by using Ensembling Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using Ensembling Model  ==>  Forecasting cumulative Covid 19 Infection cases in Russia"
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          | 4882776.63             |
## +----+------------+-----------------+------------------------+
## | 2  | 2021-05-10 | Monday          | 4891421.73             |
## +----+------------+-----------------+------------------------+
## | 3  | 2021-05-11 | Tuesday         | 4900066.42             |
## +----+------------+-----------------+------------------------+
## | 4  | 2021-05-12 | Wednesday       | 4908711.94             |
## +----+------------+-----------------+------------------------+
## | 5  | 2021-05-13 | Thursday        | 4917354.84             |
## +----+------------+-----------------+------------------------+
## | 6  | 2021-05-14 | Friday          | 4925997.54             |
## +----+------------+-----------------+------------------------+
## | 7  | 2021-05-15 | Saturday        | 4934641.51             |
## +----+------------+-----------------+------------------------+
## | 8  | 2021-05-16 | Sunday          | 4943283.15             |
## +----+------------+-----------------+------------------------+
## | 9  | 2021-05-17 | Monday          | 4951924.53             |
## +----+------------+-----------------+------------------------+
## | 10 | 2021-05-18 | Tuesday         | 4960566.91             |
## +----+------------+-----------------+------------------------+
## | 11 | 2021-05-19 | Wednesday       | 4969206.81             |
## +----+------------+-----------------+------------------------+
## | 12 | 2021-05-20 | Thursday        | 4977846.66             |
## +----+------------+-----------------+------------------------+
## | 13 | 2021-05-21 | Friday          | 4986487.92             |
## +----+------------+-----------------+------------------------+
## | 14 | 2021-05-22 | Saturday        | 4995126.99             |
## +----+------------+-----------------+------------------------+
## | 15 | 2021-05-23 | Sunday          | 5003765.92             |
## +----+------------+-----------------+------------------------+
## | 16 | 2021-05-24 | Monday          | 5012405.97             |
## +----+------------+-----------------+------------------------+
## | 17 | 2021-05-25 | Tuesday         | 5021043.67             |
## +----+------------+-----------------+------------------------+
## | 18 | 2021-05-26 | Wednesday       | 5029681.44             |
## +----+------------+-----------------+------------------------+
## | 19 | 2021-05-27 | Thursday        | 5038320.73             |
## +----+------------+-----------------+------------------------+
## | 20 | 2021-05-28 | Friday          | 5046957.93             |
## +----+------------+-----------------+------------------------+
## | 21 | 2021-05-29 | Saturday        | 5055595.10             |
## +----+------------+-----------------+------------------------+
## | 22 | 2021-05-30 | Sunday          | 5064233.50             |
## +----+------------+-----------------+------------------------+
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 | Russia       | 2.766      | 0.071      | 0.079       | 0.099      | 0.316       | 0.018       | 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 Russia
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 Russia