comparison between two systems for forecasting covid 19 cumulative infected case

cumulative Covid 19 Infection cases In Turkey
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 Turkey"   # 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<-5# Number of Neural For model NNAR Model
NNAR_Model<- TRUE     #create new model (TRUE/FALSE)
frequency<-"days"
country.name <- "Turkey"
# Data Preparation & calculate some of statistics measures
summary(original_data) # Summary your time series
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0  127256  534854 1151817 2259230 4998089
# calculate standard deviation 
data.frame(kurtosis=kurtosis(original_data))   # calculate Cofficient of kurtosis
##   kurtosis
## 1 3.240595
data.frame(skewness=skewness(original_data))  # calculate Cofficient of skewness
##   skewness
## 1 1.114052
data.frame(Standard.deviation =sd(original_data))
##   Standard.deviation
## 1            1325503
#processing on data (input data)
rows <- NROW(original_data) # calculate number of rows in time series (number of days)
training_data<-original_data[1:(rows-validation_data_days)] # Training data
testing_data<-original_data[(rows-validation_data_days+1):rows] #testing data
AD<-fulldate<-seq(as.Date(Actual_date_interval[1]),as.Date(Actual_date_interval[2]), frequency)  #input range for actual date
FD<-seq(as.Date(Forecast_date_interval[1]),as.Date(Forecast_date_interval[2]), frequency)  #input range forecasting date
N_forecasting_days<-nrow(data.frame(FD))  #calculate number of days that you want to forecasting
validation_dates<-tail(AD,validation_data_days) # select validation_dates
validation_data_by_name<-weekdays(validation_dates) # put names of validation dates
forecasting_data_by_name<-weekdays(FD)  # put names of Forecasting dates
#NNAR Model 
if(NNAR_Model==TRUE){
  data_series<-ts(training_data)
  model_NNAR<-nnetar(data_series, size = Number_Neural)
  saveRDS(model_NNAR, file = "model_NNAR.RDS")
  my_model <- readRDS("model_NNAR.RDS")
  accuracy(model_NNAR)  # accuracy on training data #Print Model Parameters
  model_NNAR
}
## Series: data_series 
## Model:  NNAR(1,5) 
## Call:   nnetar(y = data_series, size = Number_Neural)
## 
## Average of 20 networks, each of which is
## a 1-5-1 network with 16 weights
## options were - linear output units 
## 
## sigma^2 estimated as 5604815
if(NNAR_Model==FALSE){
  data_series<-ts(training_data)
  #model_NNAR<-nnetar(data_series, size = Number_Numeral)
  model_NNAR <- readRDS("model_NNAR.RDS")
  accuracy(model_NNAR)  # accuracy on training data #Print Model Parameters
  model_NNAR
}

# Testing Data Evaluation
forecasting_NNAR <- forecast(model_NNAR, h=N_forecasting_days+validation_data_days)
validation_forecast<-head(forecasting_NNAR$mean,validation_data_days)
MAPE_Per_Day<-round(  abs(((testing_data-validation_forecast)/testing_data)*100)  ,3)
paste ("MAPE % For ",validation_data_days,frequency,"by using NNAR Model for  ==> ",y_lab, sep=" ")
## [1] "MAPE % For  45 days by using NNAR Model for  ==>  Forecasting cumulative Covid 19 Infection cases in Turkey"
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 Turkey"
paste(MAPE_Mean_All,"%")
## [1] "1.793 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Turkey %"
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 Turkey"
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                | 3091282.00  | 3086125.54       | 0.167 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 3120013.00  | 3112185.00       | 0.251 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 3149094.00  | 3139828.73       | 0.294 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 3179115.00  | 3169198.69       | 0.312 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 3208173.00  | 3200448.97       | 0.241 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 3240577.00  | 3233745.92       | 0.211 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 3277880.00  | 3269267.81       | 0.263 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 3317182.00  | 3307203.95       | 0.301 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 3357988.00  | 3347752.74       | 0.305 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 3400296.00  | 3391118.54       | 0.27 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 3445052.00  | 3437506.72       | 0.219 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 3487050.00  | 3487116.41       | 0.002 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 3529601.00  | 3540130.28       | 0.298 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 3579185.00  | 3596700.54       | 0.489 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 3633925.00  | 3656930.45       | 0.633 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 3689866.00  | 3720850.72       | 0.84 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 3745657.00  | 3788390.46       | 1.141 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 3798333.00  | 3859343.53       | 1.606 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 3849011.00  | 3933332.15       | 2.191 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 3903573.00  | 4009772.87       | 2.721 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 3962760.00  | 4087851.57       | 3.157 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 4025557.00  | 4166519.19       | 3.502 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 4086957.00  | 4244519.12       | 3.855 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 4150039.00  | 4320455.42       | 4.106 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 4212645.00  | 4392901.59       | 4.279 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 4268447.00  | 4460536.36       | 4.5 %           |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 4323596.00  | 4522279.80       | 4.595 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 4384624.00  | 4577397.95       | 4.397 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 4446591.00  | 4625551.88       | 4.025 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 4501382.00  | 4666784.05       | 3.674 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 4550820.00  | 4701453.42       | 3.31 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 4591416.00  | 4730142.35       | 3.021 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 4629969.00  | 4753559.04       | 2.669 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 4667281.00  | 4772453.25       | 2.253 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 4710582.00  | 4787553.88       | 1.634 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 4751026.00  | 4799529.36       | 1.021 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4788700.00  | 4808967.35       | 0.423 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4820591.00  | 4816368.58       | 0.088 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4849408.00  | 4822149.79       | 0.562 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4875388.00  | 4826651.60       | 1 %             |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4900121.00  | 4830148.66       | 1.428 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4929118.00  | 4832860.06       | 1.953 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4955594.00  | 4834959.24       | 2.434 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4977982.00  | 4836582.57       | 2.84 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4998089.00  | 4837836.80       | 3.206 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 4838805.20          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 4839552.50          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 4840128.96          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 4840573.48          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 4840916.19          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 4841180.34          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 4841383.93          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 4841540.81          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 4841661.69          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 4841754.83          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 4841826.59          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 4841881.88          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 4841924.47          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 4841957.28          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 4841982.55          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 4842002.03          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 4842017.03          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 4842028.58          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 4842037.48          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 4842044.34          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 4842049.62          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 4842053.69          |
## +----+------------+-----------------+---------------------+
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 55.06117 1062.114 390.0284 NaN  Inf 0.05681906 -0.002553297
# Print Model Parameters
model_bats
## BATS(1, {0,0}, 1, -)
## 
## Call: bats(y = data_series)
## 
## Parameters
##   Alpha: 1.001562
##   Beta: 1.074815
##   Damping Parameter: 1
## 
## Seed States:
##           [,1]
## [1,] -66.16169
## [2,]  11.57987
## 
## Sigma: 1062.114
## AIC: 8965.25
#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 Turkey"
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 Turkey"
paste(MAPE_Mean_All.bats,"%")
## [1] "9.036 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Turkey %"
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 Turkey"
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                | 3091282.00  | 3087991.26       | 0.106 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 3120013.00  | 3114456.54       | 0.178 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 3149094.00  | 3140921.82       | 0.26 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 3179115.00  | 3167387.11       | 0.369 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 3208173.00  | 3193852.39       | 0.446 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 3240577.00  | 3220317.67       | 0.625 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 3277880.00  | 3246782.95       | 0.949 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 3317182.00  | 3273248.24       | 1.324 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 3357988.00  | 3299713.52       | 1.735 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 3400296.00  | 3326178.80       | 2.18 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 3445052.00  | 3352644.09       | 2.682 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 3487050.00  | 3379109.37       | 3.095 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 3529601.00  | 3405574.65       | 3.514 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 3579185.00  | 3432039.93       | 4.111 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 3633925.00  | 3458505.22       | 4.827 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 3689866.00  | 3484970.50       | 5.553 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 3745657.00  | 3511435.78       | 6.253 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 3798333.00  | 3537901.07       | 6.856 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 3849011.00  | 3564366.35       | 7.395 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 3903573.00  | 3590831.63       | 8.012 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 3962760.00  | 3617296.91       | 8.718 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 4025557.00  | 3643762.20       | 9.484 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 4086957.00  | 3670227.48       | 10.197 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 4150039.00  | 3696692.76       | 10.924 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 4212645.00  | 3723158.05       | 11.619 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 4268447.00  | 3749623.33       | 12.155 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 4323596.00  | 3776088.61       | 12.663 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 4384624.00  | 3802553.89       | 13.275 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 4446591.00  | 3829019.18       | 13.889 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 4501382.00  | 3855484.46       | 14.349 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 4550820.00  | 3881949.74       | 14.698 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 4591416.00  | 3908415.03       | 14.876 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 4629969.00  | 3934880.31       | 15.013 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 4667281.00  | 3961345.59       | 15.125 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 4710582.00  | 3987810.87       | 15.344 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 4751026.00  | 4014276.16       | 15.507 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4788700.00  | 4040741.44       | 15.619 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4820591.00  | 4067206.72       | 15.628 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4849408.00  | 4093672.01       | 15.584 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4875388.00  | 4120137.29       | 15.491 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4900121.00  | 4146602.57       | 15.378 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4929118.00  | 4173067.86       | 15.338 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4955594.00  | 4199533.14       | 15.257 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4977982.00  | 4225998.42       | 15.106 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4998089.00  | 4252463.70       | 14.918 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 4278928.99          | 4011702.85 | 3870241.88 | 4011702.85 | 3870241.88 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4305394.27          | 4029488.30 | 3883432.51 | 4029488.30 | 3883432.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4331859.55          | 4047181.78 | 3896482.46 | 4047181.78 | 3896482.46 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4358324.84          | 4064784.22 | 3909393.20 | 4064784.22 | 3909393.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4384790.12          | 4082296.56 | 3922166.15 | 4082296.56 | 3922166.15 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4411255.40          | 4099719.70 | 3934802.67 | 4099719.70 | 3934802.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4437720.68          | 4117054.51 | 3947304.10 | 4117054.51 | 3947304.10 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4464185.97          | 4134301.84 | 3959671.73 | 4134301.84 | 3959671.73 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4490651.25          | 4151462.50 | 3971906.82 | 4151462.50 | 3971906.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4517116.53          | 4168537.30 | 3984010.60 | 4168537.30 | 3984010.60 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4543581.82          | 4185527.01 | 3995984.25 | 4185527.01 | 3995984.25 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4570047.10          | 4202432.40 | 4007828.93 | 4202432.40 | 4007828.93 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4596512.38          | 4219254.20 | 4019545.78 | 4219254.20 | 4019545.78 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4622977.66          | 4235993.12 | 4031135.88 | 4235993.12 | 4031135.88 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4649442.95          | 4252649.87 | 4042600.31 | 4252649.87 | 4042600.31 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4675908.23          | 4269225.13 | 4053940.11 | 4269225.13 | 4053940.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4702373.51          | 4285719.57 | 4065156.30 | 4285719.57 | 4065156.30 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4728838.80          | 4302133.84 | 4076249.88 | 4302133.84 | 4076249.88 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4755304.08          | 4318468.56 | 4087221.81 | 4318468.56 | 4087221.81 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4781769.36          | 4334724.37 | 4098073.05 | 4334724.37 | 4098073.05 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4808234.64          | 4350901.86 | 4108804.51 | 4350901.86 | 4108804.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4834699.93          | 4367001.63 | 4119417.11 | 4367001.63 | 4119417.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
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 54.92595 1064.069 457.4963 NaN  Inf 0.06664773 -0.003538617
# Print Model Parameters
model_TBATS
## TBATS(1, {0,0}, 1, {<6,2>})
## 
## Call: NULL
## 
## Parameters
##   Alpha: 1.005327
##   Beta: 1.07306
##   Damping Parameter: 1
##   Gamma-1 Values: -0.001123537
##   Gamma-2 Values: -0.0008276292
## 
## Seed States:
##           [,1]
## [1,] -81.72346
## [2,]  17.64944
## [3,]  45.33531
## [4,] -24.21524
## [5,] 138.92829
## [6,] -66.57749
## 
## Sigma: 1064.069
## AIC: 8978.895
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 Turkey"
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 Turkey"
paste(MAPE_Mean_All.TBATS,"%")
## [1] "9.094 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Turkey %"
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 Turkey"
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                | 3091282.00  | 3087671.14        | 0.117 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 2  | 2021-03-26 | Friday                  | 3120013.00  | 3113840.02        | 0.198 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 3  | 2021-03-27 | Saturday                | 3149094.00  | 3140425.74        | 0.275 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 4  | 2021-03-28 | Sunday                  | 3179115.00  | 3166903.46        | 0.384 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 5  | 2021-03-29 | Monday                  | 3208173.00  | 3193281.84        | 0.464 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 6  | 2021-03-30 | Tuesday                 | 3240577.00  | 3219725.19        | 0.643 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 7  | 2021-03-31 | Wednesday               | 3277880.00  | 3245851.04        | 0.977 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 8  | 2021-04-01 | Thursday                | 3317182.00  | 3272019.92        | 1.361 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 9  | 2021-04-02 | Friday                  | 3357988.00  | 3298605.64        | 1.768 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 10 | 2021-04-03 | Saturday                | 3400296.00  | 3325083.36        | 2.212 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 11 | 2021-04-04 | Sunday                  | 3445052.00  | 3351461.74        | 2.717 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 12 | 2021-04-05 | Monday                  | 3487050.00  | 3377905.09        | 3.13 %           |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 13 | 2021-04-06 | Tuesday                 | 3529601.00  | 3404030.94        | 3.558 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 14 | 2021-04-07 | Wednesday               | 3579185.00  | 3430199.82        | 4.163 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 15 | 2021-04-08 | Thursday                | 3633925.00  | 3456785.54        | 4.875 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 16 | 2021-04-09 | Friday                  | 3689866.00  | 3483263.27        | 5.599 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 17 | 2021-04-10 | Saturday                | 3745657.00  | 3509641.64        | 6.301 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 18 | 2021-04-11 | Sunday                  | 3798333.00  | 3536084.99        | 6.904 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 19 | 2021-04-12 | Monday                  | 3849011.00  | 3562210.85        | 7.451 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 20 | 2021-04-13 | Tuesday                 | 3903573.00  | 3588379.72        | 8.074 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 21 | 2021-04-14 | Wednesday               | 3962760.00  | 3614965.45        | 8.777 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 22 | 2021-04-15 | Thursday                | 4025557.00  | 3641443.17        | 9.542 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 23 | 2021-04-16 | Friday                  | 4086957.00  | 3667821.55        | 10.255 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 24 | 2021-04-17 | Saturday                | 4150039.00  | 3694264.90        | 10.982 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 25 | 2021-04-18 | Sunday                  | 4212645.00  | 3720390.75        | 11.685 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 26 | 2021-04-19 | Monday                  | 4268447.00  | 3746559.63        | 12.227 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 27 | 2021-04-20 | Tuesday                 | 4323596.00  | 3773145.35        | 12.731 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 28 | 2021-04-21 | Wednesday               | 4384624.00  | 3799623.07        | 13.342 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 29 | 2021-04-22 | Thursday                | 4446591.00  | 3826001.45        | 13.957 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 30 | 2021-04-23 | Friday                  | 4501382.00  | 3852444.80        | 14.416 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 31 | 2021-04-24 | Saturday                | 4550820.00  | 3878570.65        | 14.772 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 32 | 2021-04-25 | Sunday                  | 4591416.00  | 3904739.53        | 14.956 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 33 | 2021-04-26 | Monday                  | 4629969.00  | 3931325.25        | 15.09 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 34 | 2021-04-27 | Tuesday                 | 4667281.00  | 3957802.98        | 15.201 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 35 | 2021-04-28 | Wednesday               | 4710582.00  | 3984181.35        | 15.421 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 36 | 2021-04-29 | Thursday                | 4751026.00  | 4010624.70        | 15.584 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 37 | 2021-04-30 | Friday                  | 4788700.00  | 4036750.55        | 15.703 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 38 | 2021-05-01 | Saturday                | 4820591.00  | 4062919.43        | 15.717 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 39 | 2021-05-02 | Sunday                  | 4849408.00  | 4089505.16        | 15.67 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 40 | 2021-05-03 | Monday                  | 4875388.00  | 4115982.88        | 15.576 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 41 | 2021-05-04 | Tuesday                 | 4900121.00  | 4142361.26        | 15.464 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 42 | 2021-05-05 | Wednesday               | 4929118.00  | 4168804.60        | 15.425 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 43 | 2021-05-06 | Thursday                | 4955594.00  | 4194930.46        | 15.35 %          |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 44 | 2021-05-07 | Friday                  | 4977982.00  | 4221099.34        | 15.205 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 45 | 2021-05-08 | Saturday                | 4998089.00  | 4247685.06        | 15.014 %         |
## +----+------------+-------------------------+-------------+-------------------+------------------+
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          | 4274162.78           | 4265099.09 | 4260301.06 | 4283226.47 | 4288024.50 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4300541.16           | 4291384.59 | 4286537.40 | 4309697.73 | 4314544.92 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4326984.51           | 4317735.94 | 4312840.05 | 4336233.07 | 4341128.96 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4353110.36           | 4343771.13 | 4338827.25 | 4362449.59 | 4367393.47 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4379279.24           | 4369850.90 | 4364859.85 | 4388707.57 | 4393698.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4405864.96           | 4396348.36 | 4391310.58 | 4415381.56 | 4420419.35 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4432342.68           | 4422738.63 | 4417654.55 | 4441946.74 | 4447030.82 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4458721.06           | 4449030.54 | 4443900.68 | 4468411.59 | 4473541.44 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4485164.41           | 4475388.13 | 4470212.88 | 4494940.69 | 4500115.94 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4511290.26           | 4501429.38 | 4496209.34 | 4521151.15 | 4526371.18 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4537459.14           | 4527515.01 | 4522250.91 | 4547403.27 | 4552667.37 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4564044.86           | 4554018.19 | 4548710.39 | 4574071.54 | 4579379.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4590522.59           | 4580414.04 | 4575062.90 | 4600631.13 | 4605982.28 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4616900.96           | 4606711.39 | 4601317.35 | 4627090.54 | 4632484.57 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4643344.31           | 4633074.30 | 4627637.69 | 4653614.32 | 4659050.94 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4669470.17           | 4659120.73 | 4653642.06 | 4679819.61 | 4685298.27 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4695639.04           | 4685211.39 | 4679691.32 | 4706066.70 | 4711586.77 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4722224.77           | 4711719.48 | 4706158.32 | 4732730.05 | 4738291.22 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4748702.49           | 4738120.14 | 4732518.19 | 4759284.84 | 4764886.79 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4775080.87           | 4764422.20 | 4758779.84 | 4785739.54 | 4791381.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4801524.22           | 4790789.72 | 4785107.22 | 4812258.71 | 4817941.21 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4827650.07           | 4816840.64 | 4811118.47 | 4838459.50 | 4844181.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 10.60344 1123.261 439.9804 NaN  Inf 0.06409603 0.3073905
# 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.5319 
## 
##   Smoothing parameters:
##     alpha = 0.9941 
##     beta  = 0.7495 
## 
##   Initial states:
##     l = -2.6081 
##     b = -0.2915 
## 
##   sigma:  2.6724
## 
##      AIC     AICc      BIC 
## 3612.614 3612.750 3633.126 
## 
## Training set error measures:
##                    ME     RMSE      MAE MPE MAPE       MASE      ACF1
## Training set 10.60344 1123.261 439.9804 NaN  Inf 0.06409603 0.3073905
# 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 Turkey"
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 Turkey"
paste(MAPE_Mean_All.Holt,"%")
## [1] "8.986 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Turkey %"
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 Turkey"
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                | 3091282.00  | 3086710.75       | 0.148 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2  | 2021-03-26 | Friday                  | 3120013.00  | 3112023.68       | 0.256 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3  | 2021-03-27 | Saturday                | 3149094.00  | 3137433.36       | 0.37 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4  | 2021-03-28 | Sunday                  | 3179115.00  | 3162939.73       | 0.509 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5  | 2021-03-29 | Monday                  | 3208173.00  | 3188542.74       | 0.612 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6  | 2021-03-30 | Tuesday                 | 3240577.00  | 3214242.34       | 0.813 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7  | 2021-03-31 | Wednesday               | 3277880.00  | 3240038.49       | 1.154 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8  | 2021-04-01 | Thursday                | 3317182.00  | 3265931.12       | 1.545 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9  | 2021-04-02 | Friday                  | 3357988.00  | 3291920.20       | 1.967 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-04-03 | Saturday                | 3400296.00  | 3318005.68       | 2.42 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-04-04 | Sunday                  | 3445052.00  | 3344187.50       | 2.928 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-04-05 | Monday                  | 3487050.00  | 3370465.62       | 3.343 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-04-06 | Tuesday                 | 3529601.00  | 3396839.99       | 3.761 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-04-07 | Wednesday               | 3579185.00  | 3423310.56       | 4.355 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-04-08 | Thursday                | 3633925.00  | 3449877.29       | 5.065 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-04-09 | Friday                  | 3689866.00  | 3476540.12       | 5.781 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-04-10 | Saturday                | 3745657.00  | 3503299.02       | 6.47 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-04-11 | Sunday                  | 3798333.00  | 3530153.92       | 7.06 %          |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-04-12 | Monday                  | 3849011.00  | 3557104.79       | 7.584 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-04-13 | Tuesday                 | 3903573.00  | 3584151.58       | 8.183 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-04-14 | Wednesday               | 3962760.00  | 3611294.25       | 8.869 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-04-15 | Thursday                | 4025557.00  | 3638532.74       | 9.614 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-16 | Friday                  | 4086957.00  | 3665867.01       | 10.303 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-17 | Saturday                | 4150039.00  | 3693297.01       | 11.006 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-18 | Sunday                  | 4212645.00  | 3720822.71       | 11.675 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-19 | Monday                  | 4268447.00  | 3748444.05       | 12.182 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-20 | Tuesday                 | 4323596.00  | 3776160.99       | 12.662 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-21 | Wednesday               | 4384624.00  | 3803973.48       | 13.243 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-22 | Thursday                | 4446591.00  | 3831881.48       | 13.824 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-23 | Friday                  | 4501382.00  | 3859884.94       | 14.251 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-24 | Saturday                | 4550820.00  | 3887983.83       | 14.565 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 32 | 2021-04-25 | Sunday                  | 4591416.00  | 3916178.09       | 14.707 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 33 | 2021-04-26 | Monday                  | 4629969.00  | 3944467.69       | 14.806 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 34 | 2021-04-27 | Tuesday                 | 4667281.00  | 3972852.57       | 14.879 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 35 | 2021-04-28 | Wednesday               | 4710582.00  | 4001332.69       | 15.057 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 36 | 2021-04-29 | Thursday                | 4751026.00  | 4029908.02       | 15.178 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 37 | 2021-04-30 | Friday                  | 4788700.00  | 4058578.51       | 15.247 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 38 | 2021-05-01 | Saturday                | 4820591.00  | 4087344.11       | 15.211 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 39 | 2021-05-02 | Sunday                  | 4849408.00  | 4116204.78       | 15.119 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 40 | 2021-05-03 | Monday                  | 4875388.00  | 4145160.48       | 14.978 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 41 | 2021-05-04 | Tuesday                 | 4900121.00  | 4174211.17       | 14.814 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 42 | 2021-05-05 | Wednesday               | 4929118.00  | 4203356.80       | 14.724 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 43 | 2021-05-06 | Thursday                | 4955594.00  | 4232597.33       | 14.59 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 44 | 2021-05-07 | Friday                  | 4977982.00  | 4261932.73       | 14.384 %        |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 45 | 2021-05-08 | Saturday                | 4998089.00  | 4291362.94       | 14.14 %         |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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          | 4320887.93          | 3734819.77 | 3440805.57 | 4946743.15 | 5294038.68 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4350507.66          | 3744216.89 | 3440556.32 | 4999171.18 | 5359576.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4380222.07          | 3753433.03 | 3440025.13 | 5052078.54 | 5425840.09 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4410031.15          | 3762469.51 | 3439214.96 | 5105466.00 | 5492832.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4439934.83          | 3771327.60 | 3438128.72 | 5159334.40 | 5560554.91 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4469933.08          | 3780008.54 | 3436769.27 | 5213684.61 | 5629010.23 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4500025.87          | 3788513.54 | 3435139.40 | 5268517.52 | 5698200.47 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4530213.14          | 3796843.79 | 3433241.86 | 5323834.05 | 5768127.89 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4560494.86          | 3805000.42 | 3431079.37 | 5379635.16 | 5838794.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4590871.00          | 3812984.56 | 3428654.59 | 5435921.81 | 5910203.61 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4621341.50          | 3820797.30 | 3425970.15 | 5492695.02 | 5982356.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4651906.33          | 3828439.72 | 3423028.62 | 5549955.79 | 6055256.36 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4682565.45          | 3835912.85 | 3419832.58 | 5607705.18 | 6128905.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4713318.82          | 3843217.73 | 3416384.52 | 5665944.24 | 6203305.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4744166.40          | 3850355.35 | 3412686.94 | 5724674.07 | 6278460.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4775108.16          | 3857326.69 | 3408742.29 | 5783895.76 | 6354371.43 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4806144.04          | 3864132.73 | 3404552.99 | 5843610.42 | 6431041.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4837274.02          | 3870774.40 | 3400121.44 | 5903819.20 | 6508474.09 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4868498.06          | 3877252.63 | 3395450.02 | 5964523.23 | 6586670.71 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4899816.10          | 3883568.33 | 3390541.06 | 6025723.69 | 6665634.35 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4931228.13          | 3889722.40 | 3385396.89 | 6087421.75 | 6745367.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4962734.10          | 3895715.72 | 3380019.81 | 6149618.59 | 6825873.28 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
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 Turkey"
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.609, Truncation lag parameter = 5, p-value = 0.01
pp.test(data_series)   # applay pp test
## Warning in pp.test(data_series): p-value greater than printed p-value
## 
##  Phillips-Perron Unit Root Test
## 
## data:  data_series
## Dickey-Fuller Z(alpha) = -0.30766, Truncation lag parameter = 5,
## p-value = 0.99
## alternative hypothesis: stationary
adf.test(data_series)  # applay adf test
## 
##  Augmented Dickey-Fuller Test
## 
## data:  data_series
## Dickey-Fuller = -0.55119, Lag order = 7, p-value = 0.9794
## 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 Turkey"
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.2239, Truncation lag parameter = 5, p-value = 0.01
pp.test(diff1_x1)     # applay pp test after taking first differences
## 
##  Phillips-Perron Unit Root Test
## 
## data:  diff1_x1
## Dickey-Fuller Z(alpha) = -9.0049, Truncation lag parameter = 5, p-value
## = 0.6069
## alternative hypothesis: stationary
adf.test(diff1_x1)    # applay adf test after taking first differences
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff1_x1
## Dickey-Fuller = -3.1621, Lag order = 7, p-value = 0.09451
## 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 Turkey"
kpss.test(diff2_x1)   # applay kpss test after taking Second differences
## Warning in kpss.test(diff2_x1): p-value greater than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  diff2_x1
## KPSS Level = 0.12306, Truncation lag parameter = 5, p-value = 0.1
pp.test(diff2_x1)     # applay pp test after taking Second differences
## Warning in pp.test(diff2_x1): p-value smaller than printed p-value
## 
##  Phillips-Perron Unit Root Test
## 
## data:  diff2_x1
## Dickey-Fuller Z(alpha) = -418.37, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
adf.test(diff2_x1)    # applay adf test after taking Second differences
## Warning in adf.test(diff2_x1): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff2_x1
## Dickey-Fuller = -4.3402, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
####Fitting an ARIMA Model
#1. Using auto arima function
model1 <- auto.arima(data_series,stepwise=FALSE, approximation=FALSE, trace=T, test = c("kpss", "adf", "pp"))  #applaying auto arima
## 
##  ARIMA(0,2,0)                    : 7470.887
##  ARIMA(0,2,1)                    : 7470.412
##  ARIMA(0,2,2)                    : 7472.439
##  ARIMA(0,2,3)                    : 7474.393
##  ARIMA(0,2,4)                    : 7470.435
##  ARIMA(0,2,5)                    : 7472.106
##  ARIMA(1,2,0)                    : 7470.44
##  ARIMA(1,2,1)                    : 7472.447
##  ARIMA(1,2,2)                    : 7474.475
##  ARIMA(1,2,3)                    : 7473.213
##  ARIMA(1,2,4)                    : 7471.53
##  ARIMA(2,2,0)                    : 7472.433
##  ARIMA(2,2,1)                    : 7474.47
##  ARIMA(2,2,2)                    : 7452.959
##  ARIMA(2,2,3)                    : 7471.202
##  ARIMA(3,2,0)                    : 7474.466
##  ARIMA(3,2,1)                    : Inf
##  ARIMA(3,2,2)                    : 7463.446
##  ARIMA(4,2,0)                    : 7471.912
##  ARIMA(4,2,1)                    : 7472.167
##  ARIMA(5,2,0)                    : 7473.051
## 
## 
## 
##  Best model: ARIMA(2,2,2)
model1 # show the result of autoarima 
## Series: data_series 
## ARIMA(2,2,2) 
## 
## Coefficients:
##           ar1      ar2     ma1     ma2
##       -0.4309  -0.9788  0.4774  0.9654
## s.e.   0.0139   0.0154  0.0202  0.0173
## 
## sigma^2 estimated as 1081210:  log likelihood=-3721.41
## AIC=7452.82   AICc=7452.96   BIC=7473.31
#Make changes in the source of auto arima to run the best model
arima.string <- function (object, padding = FALSE) 
{
  order <- object$arma[c(1, 6, 2, 3, 7, 4, 5)]
  m <- order[7]
  result <- paste("ARIMA(", order[1], ",", order[2], ",", 
                  order[3], ")", sep = "")
  if (m > 1 && sum(order[4:6]) > 0) {
    result <- paste(result, "(", order[4], ",", order[5], 
                    ",", order[6], ")[", m, "]", sep = "")
  }
  if (padding && m > 1 && sum(order[4:6]) == 0) {
    result <- paste(result, "         ", sep = "")
    if (m <= 9) {
      result <- paste(result, " ", sep = "")
    }
    else if (m <= 99) {
      result <- paste(result, "  ", sep = "")
    }
    else {
      result <- paste(result, "   ", sep = "")
    }
  }
  if (!is.null(object$xreg)) {
    if (NCOL(object$xreg) == 1 && is.element("drift", names(object$coef))) {
      result <- paste(result, "with drift        ")
    }
    else {
      result <- paste("Regression with", result, "errors")
    }
  }
  else {
    if (is.element("constant", names(object$coef)) || is.element("intercept", 
                                                                 names(object$coef))) {
      result <- paste(result, "with non-zero mean")
    }
    else if (order[2] == 0 && order[5] == 0) {
      result <- paste(result, "with zero mean    ")
    }
    else {
      result <- paste(result, "                  ")
    }
  }
  if (!padding) {
    result <- gsub("[ ]*$", "", result)
  }
  return(result)
}


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

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

x1_model1= arima(data_series, order=c(bestmodel)) # Run Best model of auto arima  for forecasting
x1_model1  # Show result of best model of auto arima 
## 
## Call:
## arima(x = data_series, order = c(bestmodel))
## 
## Coefficients:
##           ar1      ar2     ma1     ma2
##       -0.4309  -0.9788  0.4774  0.9654
## s.e.   0.0139   0.0154  0.0202  0.0173
## 
## sigma^2 estimated as 1071491:  log likelihood = -3721.41,  aic = 7452.82
paste ("accuracy of autoarima Model For  ==> ",y_lab, sep=" ")
## [1] "accuracy of autoarima Model For  ==>  Forecasting cumulative Covid 19 Infection cases in Turkey"
accuracy(x1_model1)  # aacuracy of best model from auto arima
##                    ME    RMSE      MAE      MPE     MAPE       MASE       ACF1
## Training set 57.16129 1032.81 383.7761 0.593961 1.949234 0.05590822 0.04272289
x1_model1$x          # show result of best model from auto arima 
## NULL
checkresiduals(x1_model1,xlab = paste ("Time in", frequency ,y_lab , sep=" "), ylab=y_lab)  # checkresiduals from best model from using auto arima 

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(2,2,2)
## Q* = 41.97, df = 6, p-value = 1.864e-07
## 
## Model df: 4.   Total lags used: 10
paste("Box-Ljung test , Ljung-Box test For Modelling for   ==> ",y_lab, sep=" ")
## [1] "Box-Ljung test , Ljung-Box test For Modelling for   ==>  Forecasting cumulative Covid 19 Infection cases in Turkey"
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 = 0.83775, df = 20, p-value = 1
jarque.bera.test(x1_model1$residuals)  # Do test jarque.bera.test 
## 
##  Jarque Bera Test
## 
## data:  x1_model1$residuals
## X-squared = 271237, 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 Turkey"
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 Turkey"
paste(MAPE_Mean_All.ARIMA,"%")
## [1] "9.334 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Turkey %"
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 Turkey"
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                | 3091282.00  | 3087589.92             | 0.119 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 2  | 2021-03-26      | Friday                  | 3120013.00  | 3113147.70             | 0.22 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 3  | 2021-03-27      | Saturday                | 3149094.00  | 3139035.86             | 0.319 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 4  | 2021-03-28      | Sunday                  | 3179115.00  | 3165282.94             | 0.435 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 5  | 2021-03-29      | Monday                  | 3208173.00  | 3191051.98             | 0.534 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 6  | 2021-03-30      | Tuesday                 | 3240577.00  | 3216675.71             | 0.738 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 7  | 2021-03-31      | Wednesday               | 3277880.00  | 3242829.95             | 1.069 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 8  | 2021-04-01      | Thursday                | 3317182.00  | 3268897.83             | 1.456 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 9  | 2021-04-02      | Friday                  | 3357988.00  | 3294483.65             | 1.891 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 10 | 2021-04-03      | Saturday                | 3400296.00  | 3320361.73             | 2.351 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 11 | 2021-04-04      | Sunday                  | 3445052.00  | 3346585.71             | 2.858 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 12 | 2021-04-05      | Monday                  | 3487050.00  | 3372374.57             | 3.289 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 13 | 2021-04-06      | Tuesday                 | 3529601.00  | 3398012.37             | 3.728 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 14 | 2021-04-07      | Wednesday               | 3579185.00  | 3424141.15             | 4.332 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 15 | 2021-04-08      | Thursday                | 3633925.00  | 3450206.22             | 5.056 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 16 | 2021-04-09      | Friday                  | 3689866.00  | 3475818.18             | 5.801 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 17 | 2021-04-10      | Saturday                | 3745657.00  | 3501687.74             | 6.513 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 18 | 2021-04-11      | Sunday                  | 3798333.00  | 3527889.81             | 7.12 %                |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 19 | 2021-04-12      | Monday                  | 3849011.00  | 3553696.45             | 7.672 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 20 | 2021-04-13      | Tuesday                 | 3903573.00  | 3579348.03             | 8.306 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 21 | 2021-04-14      | Wednesday               | 3962760.00  | 3605453.47             | 9.017 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 22 | 2021-04-15      | Thursday                | 4025557.00  | 3631515.11             | 9.789 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 23 | 2021-04-16      | Friday                  | 4086957.00  | 3657151.39             | 10.517 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 24 | 2021-04-17      | Saturday                | 4150039.00  | 3683013.83             | 11.254 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 25 | 2021-04-18      | Sunday                  | 4212645.00  | 3709195.16             | 11.951 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 26 | 2021-04-19      | Monday                  | 4268447.00  | 3735017.71             | 12.497 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 27 | 2021-04-20      | Tuesday                 | 4323596.00  | 3760682.74             | 13.02 %               |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 28 | 2021-04-21      | Wednesday               | 4384624.00  | 3786766.81             | 13.635 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 29 | 2021-04-22      | Thursday                | 4446591.00  | 3812824.50             | 14.253 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 30 | 2021-04-23      | Friday                  | 4501382.00  | 3838483.40             | 14.727 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 31 | 2021-04-24      | Saturday                | 4550820.00  | 3864339.96             | 15.085 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 32 | 2021-04-25      | Sunday                  | 4591416.00  | 3890501.68             | 15.266 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 33 | 2021-04-26      | Monday                  | 4629969.00  | 3916338.43             | 15.413 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 34 | 2021-04-27      | Tuesday                 | 4667281.00  | 3942016.53             | 15.539 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 35 | 2021-04-28      | Wednesday               | 4710582.00  | 3968081.07             | 15.762 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 36 | 2021-04-29      | Thursday                | 4751026.00  | 3994134.38             | 15.931 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 37 | 2021-04-30      | Friday                  | 4788700.00  | 4019814.29             | 16.056 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 38 | 2021-05-01      | Saturday                | 4820591.00  | 4045666.08             | 16.075 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 39 | 2021-05-02      | Sunday                  | 4849408.00  | 4071809.30             | 16.035 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 40 | 2021-05-03      | Monday                  | 4875388.00  | 4097658.69             | 15.952 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 41 | 2021-05-04      | Tuesday                 | 4900121.00  | 4123349.45             | 15.852 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 42 | 2021-05-05      | Wednesday               | 4929118.00  | 4149396.16             | 15.819 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 43 | 2021-05-06      | Thursday                | 4955594.00  | 4175444.76             | 15.743 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 44 | 2021-05-07      | Friday                  | 4977982.00  | 4201144.14             | 15.605 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 45 | 2021-05-08      | Saturday                | 4998089.00  | 4226992.16             | 15.428 %              |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
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          | 4253117.94                | 4006890.76 | 3876545.97 | 4499345.11 | 4629689.90 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4278978.54                | 4024768.07 | 3890197.17 | 4533189.02 | 4667759.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4304681.55                | 4042397.27 | 3903552.37 | 4566965.82 | 4705810.73 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4330712.01                | 4060274.67 | 3917113.80 | 4601149.34 | 4744310.22 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4356755.62                | 4078086.38 | 3930567.79 | 4635424.87 | 4782943.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4382473.06                | 4095484.12 | 3943561.36 | 4669462.00 | 4821384.76 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4408318.17                | 4112927.14 | 3956556.58 | 4703709.20 | 4860079.77 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4434427.53                | 4130560.18 | 3969702.53 | 4738294.88 | 4899152.53 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4460298.06                | 4147873.38 | 3982485.75 | 4772722.73 | 4938110.36 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4486012.85                | 4164946.68 | 3994984.51 | 4807079.03 | 4977041.20 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4512028.52                | 4182246.29 | 4007670.12 | 4841810.75 | 5016386.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4538066.97                | 4199494.77 | 4020265.47 | 4876639.17 | 5055868.47 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4563801.11                | 4216357.17 | 4032431.45 | 4911245.05 | 5095170.77 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4589644.08                | 4233250.97 | 4044587.85 | 4946037.19 | 5134700.31 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4615738.01                | 4250325.60 | 4056887.94 | 4981150.43 | 5174588.09 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4641617.28                | 4267109.65 | 4068857.29 | 5016124.91 | 5214377.27 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4667343.41                | 4283661.61 | 4080552.74 | 5051025.21 | 5254134.08 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4693345.64                | 4300419.03 | 4092416.25 | 5086272.25 | 5294275.03 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4719378.79                | 4317137.54 | 4104203.89 | 5121620.04 | 5334553.69 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4745128.37                | 4333495.69 | 4115590.51 | 5156761.04 | 5374666.22 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4770969.88                | 4349872.52 | 4126957.05 | 5192067.23 | 5414982.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4797049.33                | 4366420.58 | 4138459.49 | 5227678.08 | 5455639.17 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
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] "9.334 % MAPE  45 days Forecasting cumulative Covid 19 Infection cases in Turkey"
## 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 Turkey"
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 Turkey"
paste(MAPE_Mean_EnsemblingAverage,"%")
## [1] "1.402 %"
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 Turkey"
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                | 3091282.00  | 3086262.06 | 0.162 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 2  | 2021-03-26      | Friday                  | 3120013.00  | 3112303.20 | 0.247 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 3  | 2021-03-27      | Saturday                | 3149094.00  | 3139791.27 | 0.295 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 4  | 2021-03-28      | Sunday                  | 3179115.00  | 3168841.65 | 0.323 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 5  | 2021-03-29      | Monday                  | 3208173.00  | 3199572.30 | 0.268 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 6  | 2021-03-30      | Tuesday                 | 3240577.00  | 3232145.35 | 0.26 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 7  | 2021-03-31      | Wednesday               | 3277880.00  | 3266728.59 | 0.34 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 8  | 2021-04-01      | Thursday                | 3317182.00  | 3303485.98 | 0.413 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 9  | 2021-04-02      | Friday                  | 3357988.00  | 3342595.54 | 0.458 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 10 | 2021-04-03      | Saturday                | 3400296.00  | 3384247.43 | 0.472 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 11 | 2021-04-04      | Sunday                  | 3445052.00  | 3428628.03 | 0.477 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 12 | 2021-04-05      | Monday                  | 3487050.00  | 3475901.14 | 0.32 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 13 | 2021-04-06      | Tuesday                 | 3529601.00  | 3526228.70 | 0.096 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 14 | 2021-04-07      | Wednesday               | 3579185.00  | 3579772.77 | 0.016 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 15 | 2021-04-08      | Thursday                | 3633925.00  | 3636621.76 | 0.074 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 16 | 2021-04-09      | Friday                  | 3689866.00  | 3696780.45 | 0.187 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 17 | 2021-04-10      | Saturday                | 3745657.00  | 3760203.02 | 0.388 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 18 | 2021-04-11      | Sunday                  | 3798333.00  | 3826709.92 | 0.747 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 19 | 2021-04-12      | Monday                  | 3849011.00  | 3895933.40 | 1.219 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 20 | 2021-04-13      | Tuesday                 | 3903573.00  | 3967363.36 | 1.634 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 21 | 2021-04-14      | Wednesday               | 3962760.00  | 4040291.67 | 1.957 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 22 | 2021-04-15      | Thursday                | 4025557.00  | 4113748.60 | 2.191 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 23 | 2021-04-16      | Friday                  | 4086957.00  | 4186593.90 | 2.438 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 24 | 2021-04-17      | Saturday                | 4150039.00  | 4257591.59 | 2.592 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 25 | 2021-04-18      | Sunday                  | 4212645.00  | 4325450.59 | 2.678 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 26 | 2021-04-19      | Monday                  | 4268447.00  | 4388973.84 | 2.824 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 27 | 2021-04-20      | Tuesday                 | 4323596.00  | 4447203.76 | 2.859 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 28 | 2021-04-21      | Wednesday               | 4384624.00  | 4499481.09 | 2.62 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 29 | 2021-04-22      | Thursday                | 4446591.00  | 4545489.86 | 2.224 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 30 | 2021-04-23      | Friday                  | 4501382.00  | 4585263.08 | 1.863 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 31 | 2021-04-24      | Saturday                | 4550820.00  | 4619129.18 | 1.501 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 32 | 2021-04-25      | Sunday                  | 4591416.00  | 4647623.98 | 1.224 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 33 | 2021-04-26      | Monday                  | 4629969.00  | 4671378.43 | 0.894 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 34 | 2021-04-27      | Tuesday                 | 4667281.00  | 4691058.36 | 0.509 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 35 | 2021-04-28      | Wednesday               | 4710582.00  | 4707333.64 | 0.069 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 36 | 2021-04-29      | Thursday                | 4751026.00  | 4720800.00 | 0.636 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 37 | 2021-04-30      | Friday                  | 4788700.00  | 4731967.73 | 1.185 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 38 | 2021-05-01      | Saturday                | 4820591.00  | 4741310.13 | 1.645 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 39 | 2021-05-02      | Sunday                  | 4849408.00  | 4749214.59 | 2.066 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 40 | 2021-05-03      | Monday                  | 4875388.00  | 4755959.93 | 2.45 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 41 | 2021-05-04      | Tuesday                 | 4900121.00  | 4761796.90 | 2.823 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 42 | 2021-05-05      | Wednesday               | 4929118.00  | 4766939.69 | 3.29 %          |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 43 | 2021-05-06      | Thursday                | 4955594.00  | 4771525.96 | 3.714 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 44 | 2021-05-07      | Friday                  | 4977982.00  | 4775678.67 | 4.064 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
## | 45 | 2021-05-08      | Saturday                | 4998089.00  | 4779515.72 | 4.373 %         |
## +----+-----------------+-------------------------+-------------+------------+-----------------+
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          | 4783102.12                |
## +----+------------+-----------------+---------------------------+
## | 2  | 2021-05-10 | Monday          | 4786482.79                |
## +----+------------+-----------------+---------------------------+
## | 3  | 2021-05-11 | Tuesday         | 4789709.75                |
## +----+------------+-----------------+---------------------------+
## | 4  | 2021-05-12 | Wednesday       | 4792820.59                |
## +----+------------+-----------------+---------------------------+
## | 5  | 2021-05-13 | Thursday        | 4795843.56                |
## +----+------------+-----------------+---------------------------+
## | 6  | 2021-05-14 | Friday          | 4798800.47                |
## +----+------------+-----------------+---------------------------+
## | 7  | 2021-05-15 | Saturday        | 4801705.72                |
## +----+------------+-----------------+---------------------------+
## | 8  | 2021-05-16 | Sunday          | 4804575.42                |
## +----+------------+-----------------+---------------------------+
## | 9  | 2021-05-17 | Monday          | 4807410.74                |
## +----+------------+-----------------+---------------------------+
## | 10 | 2021-05-18 | Tuesday         | 4810211.62                |
## +----+------------+-----------------+---------------------------+
## | 11 | 2021-05-19 | Wednesday       | 4813004.21                |
## +----+------------+-----------------+---------------------------+
## | 12 | 2021-05-20 | Thursday        | 4815795.32                |
## +----+------------+-----------------+---------------------------+
## | 13 | 2021-05-21 | Friday          | 4818567.06                |
## +----+------------+-----------------+---------------------------+
## | 14 | 2021-05-22 | Saturday        | 4821332.59                |
## +----+------------+-----------------+---------------------------+
## | 15 | 2021-05-23 | Sunday          | 4824101.59                |
## +----+------------+-----------------+---------------------------+
## | 16 | 2021-05-24 | Monday          | 4826854.42                |
## +----+------------+-----------------+---------------------------+
## | 17 | 2021-05-25 | Tuesday         | 4829602.82                |
## +----+------------+-----------------+---------------------------+
## | 18 | 2021-05-26 | Wednesday       | 4832367.80                |
## +----+------------+-----------------+---------------------------+
## | 19 | 2021-05-27 | Thursday        | 4835130.82                |
## +----+------------+-----------------+---------------------------+
## | 20 | 2021-05-28 | Friday          | 4837884.77                |
## +----+------------+-----------------+---------------------------+
## | 21 | 2021-05-29 | Saturday        | 4840643.58                |
## +----+------------+-----------------+---------------------------+
## | 22 | 2021-05-30 | Sunday          | 4843401.66                |
## +----+------------+-----------------+---------------------------+
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 Turkey"
best_recommended_model
## [1] 1.402
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 Turkey"
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          | 4278928.99          | 4011702.85 | 3870241.88 | 4011702.85 | 3870241.88 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4305394.27          | 4029488.30 | 3883432.51 | 4029488.30 | 3883432.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4331859.55          | 4047181.78 | 3896482.46 | 4047181.78 | 3896482.46 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4358324.84          | 4064784.22 | 3909393.20 | 4064784.22 | 3909393.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4384790.12          | 4082296.56 | 3922166.15 | 4082296.56 | 3922166.15 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4411255.40          | 4099719.70 | 3934802.67 | 4099719.70 | 3934802.67 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4437720.68          | 4117054.51 | 3947304.10 | 4117054.51 | 3947304.10 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4464185.97          | 4134301.84 | 3959671.73 | 4134301.84 | 3959671.73 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4490651.25          | 4151462.50 | 3971906.82 | 4151462.50 | 3971906.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4517116.53          | 4168537.30 | 3984010.60 | 4168537.30 | 3984010.60 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4543581.82          | 4185527.01 | 3995984.25 | 4185527.01 | 3995984.25 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4570047.10          | 4202432.40 | 4007828.93 | 4202432.40 | 4007828.93 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4596512.38          | 4219254.20 | 4019545.78 | 4219254.20 | 4019545.78 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4622977.66          | 4235993.12 | 4031135.88 | 4235993.12 | 4031135.88 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4649442.95          | 4252649.87 | 4042600.31 | 4252649.87 | 4042600.31 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4675908.23          | 4269225.13 | 4053940.11 | 4269225.13 | 4053940.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4702373.51          | 4285719.57 | 4065156.30 | 4285719.57 | 4065156.30 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4728838.80          | 4302133.84 | 4076249.88 | 4302133.84 | 4076249.88 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4755304.08          | 4318468.56 | 4087221.81 | 4318468.56 | 4087221.81 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4781769.36          | 4334724.37 | 4098073.05 | 4334724.37 | 4098073.05 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4808234.64          | 4350901.86 | 4108804.51 | 4350901.86 | 4108804.51 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4834699.93          | 4367001.63 | 4119417.11 | 4367001.63 | 4119417.11 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using TBATS Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using TBATS Model  ==>  Forecasting cumulative Covid 19 Infection cases in Turkey"
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          | 4274162.78           | 4265099.09 | 4260301.06 | 4283226.47 | 4288024.50 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4300541.16           | 4291384.59 | 4286537.40 | 4309697.73 | 4314544.92 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4326984.51           | 4317735.94 | 4312840.05 | 4336233.07 | 4341128.96 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4353110.36           | 4343771.13 | 4338827.25 | 4362449.59 | 4367393.47 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4379279.24           | 4369850.90 | 4364859.85 | 4388707.57 | 4393698.63 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4405864.96           | 4396348.36 | 4391310.58 | 4415381.56 | 4420419.35 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4432342.68           | 4422738.63 | 4417654.55 | 4441946.74 | 4447030.82 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4458721.06           | 4449030.54 | 4443900.68 | 4468411.59 | 4473541.44 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4485164.41           | 4475388.13 | 4470212.88 | 4494940.69 | 4500115.94 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4511290.26           | 4501429.38 | 4496209.34 | 4521151.15 | 4526371.18 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4537459.14           | 4527515.01 | 4522250.91 | 4547403.27 | 4552667.37 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4564044.86           | 4554018.19 | 4548710.39 | 4574071.54 | 4579379.34 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4590522.59           | 4580414.04 | 4575062.90 | 4600631.13 | 4605982.28 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4616900.96           | 4606711.39 | 4601317.35 | 4627090.54 | 4632484.57 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4643344.31           | 4633074.30 | 4627637.69 | 4653614.32 | 4659050.94 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4669470.17           | 4659120.73 | 4653642.06 | 4679819.61 | 4685298.27 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4695639.04           | 4685211.39 | 4679691.32 | 4706066.70 | 4711586.77 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4722224.77           | 4711719.48 | 4706158.32 | 4732730.05 | 4738291.22 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4748702.49           | 4738120.14 | 4732518.19 | 4759284.84 | 4764886.79 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4775080.87           | 4764422.20 | 4758779.84 | 4785739.54 | 4791381.90 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4801524.22           | 4790789.72 | 4785107.22 | 4812258.71 | 4817941.21 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4827650.07           | 4816840.64 | 4811118.47 | 4838459.50 | 4844181.67 |
## +----+------------+-----------------+----------------------+------------+------------+------------+------------+
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 Turkey"
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          | 4320887.93          | 3734819.77 | 3440805.57 | 4946743.15 | 5294038.68 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4350507.66          | 3744216.89 | 3440556.32 | 4999171.18 | 5359576.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4380222.07          | 3753433.03 | 3440025.13 | 5052078.54 | 5425840.09 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4410031.15          | 3762469.51 | 3439214.96 | 5105466.00 | 5492832.26 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4439934.83          | 3771327.60 | 3438128.72 | 5159334.40 | 5560554.91 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4469933.08          | 3780008.54 | 3436769.27 | 5213684.61 | 5629010.23 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4500025.87          | 3788513.54 | 3435139.40 | 5268517.52 | 5698200.47 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4530213.14          | 3796843.79 | 3433241.86 | 5323834.05 | 5768127.89 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4560494.86          | 3805000.42 | 3431079.37 | 5379635.16 | 5838794.82 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4590871.00          | 3812984.56 | 3428654.59 | 5435921.81 | 5910203.61 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4621341.50          | 3820797.30 | 3425970.15 | 5492695.02 | 5982356.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4651906.33          | 3828439.72 | 3423028.62 | 5549955.79 | 6055256.36 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4682565.45          | 3835912.85 | 3419832.58 | 5607705.18 | 6128905.20 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4713318.82          | 3843217.73 | 3416384.52 | 5665944.24 | 6203305.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4744166.40          | 3850355.35 | 3412686.94 | 5724674.07 | 6278460.21 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4775108.16          | 3857326.69 | 3408742.29 | 5783895.76 | 6354371.43 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4806144.04          | 3864132.73 | 3404552.99 | 5843610.42 | 6431041.86 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4837274.02          | 3870774.40 | 3400121.44 | 5903819.20 | 6508474.09 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4868498.06          | 3877252.63 | 3395450.02 | 5964523.23 | 6586670.71 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4899816.10          | 3883568.33 | 3390541.06 | 6025723.69 | 6665634.35 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4931228.13          | 3889722.40 | 3385396.89 | 6087421.75 | 6745367.65 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4962734.10          | 3895715.72 | 3380019.81 | 6149618.59 | 6825873.28 |
## +----+------------+-----------------+---------------------+------------+------------+------------+------------+
paste("Forecasting by using ARIMA Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using ARIMA Model  ==>  Forecasting cumulative Covid 19 Infection cases in Turkey"
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          | 4253117.94                | 4006890.76 | 3876545.97 | 4499345.11 | 4629689.90 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 2  | 2021-05-10 | Monday          | 4278978.54                | 4024768.07 | 3890197.17 | 4533189.02 | 4667759.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 3  | 2021-05-11 | Tuesday         | 4304681.55                | 4042397.27 | 3903552.37 | 4566965.82 | 4705810.73 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 4  | 2021-05-12 | Wednesday       | 4330712.01                | 4060274.67 | 3917113.80 | 4601149.34 | 4744310.22 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 5  | 2021-05-13 | Thursday        | 4356755.62                | 4078086.38 | 3930567.79 | 4635424.87 | 4782943.46 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 6  | 2021-05-14 | Friday          | 4382473.06                | 4095484.12 | 3943561.36 | 4669462.00 | 4821384.76 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 7  | 2021-05-15 | Saturday        | 4408318.17                | 4112927.14 | 3956556.58 | 4703709.20 | 4860079.77 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 8  | 2021-05-16 | Sunday          | 4434427.53                | 4130560.18 | 3969702.53 | 4738294.88 | 4899152.53 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 9  | 2021-05-17 | Monday          | 4460298.06                | 4147873.38 | 3982485.75 | 4772722.73 | 4938110.36 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 10 | 2021-05-18 | Tuesday         | 4486012.85                | 4164946.68 | 3994984.51 | 4807079.03 | 4977041.20 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 11 | 2021-05-19 | Wednesday       | 4512028.52                | 4182246.29 | 4007670.12 | 4841810.75 | 5016386.92 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 12 | 2021-05-20 | Thursday        | 4538066.97                | 4199494.77 | 4020265.47 | 4876639.17 | 5055868.47 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 13 | 2021-05-21 | Friday          | 4563801.11                | 4216357.17 | 4032431.45 | 4911245.05 | 5095170.77 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 14 | 2021-05-22 | Saturday        | 4589644.08                | 4233250.97 | 4044587.85 | 4946037.19 | 5134700.31 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 15 | 2021-05-23 | Sunday          | 4615738.01                | 4250325.60 | 4056887.94 | 4981150.43 | 5174588.09 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 16 | 2021-05-24 | Monday          | 4641617.28                | 4267109.65 | 4068857.29 | 5016124.91 | 5214377.27 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 17 | 2021-05-25 | Tuesday         | 4667343.41                | 4283661.61 | 4080552.74 | 5051025.21 | 5254134.08 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 18 | 2021-05-26 | Wednesday       | 4693345.64                | 4300419.03 | 4092416.25 | 5086272.25 | 5294275.03 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 19 | 2021-05-27 | Thursday        | 4719378.79                | 4317137.54 | 4104203.89 | 5121620.04 | 5334553.69 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 20 | 2021-05-28 | Friday          | 4745128.37                | 4333495.69 | 4115590.51 | 5156761.04 | 5374666.22 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 21 | 2021-05-29 | Saturday        | 4770969.88                | 4349872.52 | 4126957.05 | 5192067.23 | 5414982.70 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
## | 22 | 2021-05-30 | Sunday          | 4797049.33                | 4366420.58 | 4138459.49 | 5227678.08 | 5455639.17 |
## +----+------------+-----------------+---------------------------+------------+------------+------------+------------+
paste("Forecasting by using NNAR Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using NNAR Model  ==>  Forecasting cumulative Covid 19 Infection cases in Turkey"
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          | 4838805.20          |
## +----+------------+-----------------+---------------------+
## | 2  | 2021-05-10 | Monday          | 4839552.50          |
## +----+------------+-----------------+---------------------+
## | 3  | 2021-05-11 | Tuesday         | 4840128.96          |
## +----+------------+-----------------+---------------------+
## | 4  | 2021-05-12 | Wednesday       | 4840573.48          |
## +----+------------+-----------------+---------------------+
## | 5  | 2021-05-13 | Thursday        | 4840916.19          |
## +----+------------+-----------------+---------------------+
## | 6  | 2021-05-14 | Friday          | 4841180.34          |
## +----+------------+-----------------+---------------------+
## | 7  | 2021-05-15 | Saturday        | 4841383.93          |
## +----+------------+-----------------+---------------------+
## | 8  | 2021-05-16 | Sunday          | 4841540.81          |
## +----+------------+-----------------+---------------------+
## | 9  | 2021-05-17 | Monday          | 4841661.69          |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-05-18 | Tuesday         | 4841754.83          |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-05-19 | Wednesday       | 4841826.59          |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-05-20 | Thursday        | 4841881.88          |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-05-21 | Friday          | 4841924.47          |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-05-22 | Saturday        | 4841957.28          |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-05-23 | Sunday          | 4841982.55          |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-05-24 | Monday          | 4842002.03          |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-05-25 | Tuesday         | 4842017.03          |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-05-26 | Wednesday       | 4842028.58          |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-05-27 | Thursday        | 4842037.48          |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-05-28 | Friday          | 4842044.34          |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-05-29 | Saturday        | 4842049.62          |
## +----+------------+-----------------+---------------------+
## | 22 | 2021-05-30 | Sunday          | 4842053.69          |
## +----+------------+-----------------+---------------------+
paste("Forecasting by using Ensembling Model  ==> ", y_lab , sep=" ")
## [1] "Forecasting by using Ensembling Model  ==>  Forecasting cumulative Covid 19 Infection cases in Turkey"
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          | 4783102.12             |
## +----+------------+-----------------+------------------------+
## | 2  | 2021-05-10 | Monday          | 4786482.79             |
## +----+------------+-----------------+------------------------+
## | 3  | 2021-05-11 | Tuesday         | 4789709.75             |
## +----+------------+-----------------+------------------------+
## | 4  | 2021-05-12 | Wednesday       | 4792820.59             |
## +----+------------+-----------------+------------------------+
## | 5  | 2021-05-13 | Thursday        | 4795843.56             |
## +----+------------+-----------------+------------------------+
## | 6  | 2021-05-14 | Friday          | 4798800.47             |
## +----+------------+-----------------+------------------------+
## | 7  | 2021-05-15 | Saturday        | 4801705.72             |
## +----+------------+-----------------+------------------------+
## | 8  | 2021-05-16 | Sunday          | 4804575.42             |
## +----+------------+-----------------+------------------------+
## | 9  | 2021-05-17 | Monday          | 4807410.74             |
## +----+------------+-----------------+------------------------+
## | 10 | 2021-05-18 | Tuesday         | 4810211.62             |
## +----+------------+-----------------+------------------------+
## | 11 | 2021-05-19 | Wednesday       | 4813004.21             |
## +----+------------+-----------------+------------------------+
## | 12 | 2021-05-20 | Thursday        | 4815795.32             |
## +----+------------+-----------------+------------------------+
## | 13 | 2021-05-21 | Friday          | 4818567.06             |
## +----+------------+-----------------+------------------------+
## | 14 | 2021-05-22 | Saturday        | 4821332.59             |
## +----+------------+-----------------+------------------------+
## | 15 | 2021-05-23 | Sunday          | 4824101.59             |
## +----+------------+-----------------+------------------------+
## | 16 | 2021-05-24 | Monday          | 4826854.42             |
## +----+------------+-----------------+------------------------+
## | 17 | 2021-05-25 | Tuesday         | 4829602.82             |
## +----+------------+-----------------+------------------------+
## | 18 | 2021-05-26 | Wednesday       | 4832367.80             |
## +----+------------+-----------------+------------------------+
## | 19 | 2021-05-27 | Thursday        | 4835130.82             |
## +----+------------+-----------------+------------------------+
## | 20 | 2021-05-28 | Friday          | 4837884.77             |
## +----+------------+-----------------+------------------------+
## | 21 | 2021-05-29 | Saturday        | 4840643.58             |
## +----+------------+-----------------+------------------------+
## | 22 | 2021-05-30 | Sunday          | 4843401.66             |
## +----+------------+-----------------+------------------------+
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 | Turkey       | 1.793      | 9.036      | 9.094       | 8.986      | 9.334       | 1.402       | 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 Turkey
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 Turkey