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
##Global vriable##
Full_original_data <- read.csv("data.csv") # path of your data ( time series data)
original_data<-Full_original_data$Recovery
y_lab <- "Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk" # input name of data
Actual_date_interval <- c("2020/03/12","2021/04/09")
Forecast_date_interval <- c("2021/04/10","2021/04/30")
validation_data_days <-31
frequency<-"day"
Number_Neural<-5 # Number of Neural For model NNAR Model
NNAR_Model<- FALSE #create new model (TRUE/FALSE)
frequency<-"days"
Population <-1130319 # population in England for SIR Model
country.name <- "Chelyabinsk"
# Data Preparation & calculate some of statistics measures
summary(original_data) # Summary your time series
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 2610 11308 16236 23238 52005
# calculate standard deviation
data.frame(kurtosis=kurtosis(original_data)) # calculate Cofficient of kurtosis
## kurtosis
## 1 2.59904
data.frame(skewness=skewness(original_data)) # calculate Cofficient of skewness
## skewness
## 1 0.8765831
data.frame(Standard.deviation =sd(original_data))
## Standard.deviation
## 1 15719.85
#processing on data (input data)
rows <- NROW(original_data) # calculate number of rows in time series (number of days)
training_data<-original_data[1:(rows-validation_data_days)] # Training data
testing_data<-original_data[(rows-validation_data_days+1):rows] #testing data
AD<-fulldate<-seq(as.Date(Actual_date_interval[1]),as.Date(Actual_date_interval[2]), frequency) #input range for actual date
FD<-seq(as.Date(Forecast_date_interval[1]),as.Date(Forecast_date_interval[2]), frequency) #input range forecasting date
N_forecasting_days<-nrow(data.frame(FD)) #calculate number of days that you want to forecasting
validation_dates<-tail(AD,validation_data_days) # select validation_dates
validation_data_by_name<-weekdays(validation_dates) # put names of validation dates
forecasting_data_by_name<-weekdays(FD) # put names of Forecasting dates
#NNAR Model
if(NNAR_Model==TRUE){
data_series<-ts(training_data)
model_NNAR<-nnetar(data_series, size = Number_Neural)
saveRDS(model_NNAR, file = "model_NNAR.RDS")
my_model <- readRDS("model_NNAR.RDS")
accuracy(model_NNAR) # accuracy on training data #Print Model Parameters
model_NNAR
}
if(NNAR_Model==FALSE){
data_series<-ts(training_data)
#model_NNAR<-nnetar(data_series, size = Number_Numeral)
model_NNAR <- readRDS("model_NNAR.RDS")
accuracy(model_NNAR) # accuracy on training data #Print Model Parameters
model_NNAR
}
## Series: data_series
## Model: NNAR(1,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 9029
# 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 31 days by using NNAR Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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 31 days in NNAR Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
paste(MAPE_Mean_All,"%")
## [1] "5.367 % MAPE 31 days Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk %"
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 31 days in NNAR Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-10 | Wednesday | 46447.00 | 46332.57 | 0.246 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2 | 2021-03-11 | Thursday | 46605.00 | 46373.13 | 0.498 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3 | 2021-03-12 | Friday | 46761.00 | 46409.21 | 0.752 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4 | 2021-03-13 | Saturday | 46916.00 | 46441.27 | 1.012 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5 | 2021-03-14 | Sunday | 47069.00 | 46469.74 | 1.273 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6 | 2021-03-15 | Monday | 47221.00 | 46495.03 | 1.537 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7 | 2021-03-16 | Tuesday | 47399.00 | 46517.47 | 1.86 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8 | 2021-03-17 | Wednesday | 47596.00 | 46537.38 | 2.224 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9 | 2021-03-18 | Thursday | 47811.00 | 46555.04 | 2.627 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-03-19 | Friday | 48046.00 | 46570.70 | 3.071 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-03-20 | Saturday | 48287.00 | 46584.57 | 3.526 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-03-21 | Sunday | 48541.00 | 46596.87 | 4.005 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-03-22 | Monday | 48790.00 | 46607.76 | 4.473 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-03-23 | Tuesday | 49023.00 | 46617.41 | 4.907 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-03-24 | Wednesday | 49234.00 | 46625.96 | 5.297 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-03-25 | Thursday | 49421.00 | 46633.53 | 5.64 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-03-26 | Friday | 49585.00 | 46640.23 | 5.939 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-03-27 | Saturday | 49746.00 | 46646.16 | 6.231 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-03-28 | Sunday | 49924.00 | 46651.41 | 6.555 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-03-29 | Monday | 50123.00 | 46656.06 | 6.917 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-03-30 | Tuesday | 50293.00 | 46660.18 | 7.223 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-03-31 | Wednesday | 50488.00 | 46663.82 | 7.574 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-01 | Thursday | 50705.00 | 46667.04 | 7.964 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-02 | Friday | 50928.00 | 46669.89 | 8.361 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-03 | Saturday | 51129.00 | 46672.41 | 8.716 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-04 | Sunday | 51311.00 | 46674.64 | 9.036 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-05 | Monday | 51472.00 | 46676.62 | 9.316 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-06 | Tuesday | 51611.00 | 46678.37 | 9.557 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-07 | Wednesday | 51733.00 | 46679.91 | 9.768 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-08 | Thursday | 51881.00 | 46681.28 | 10.022 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-09 | Friday | 52005.00 | 46682.49 | 10.235 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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-04-10 | Saturday | 46683.56 |
## +----+------------+-----------------+---------------------+
## | 2 | 2021-04-11 | Sunday | 46684.51 |
## +----+------------+-----------------+---------------------+
## | 3 | 2021-04-12 | Monday | 46685.35 |
## +----+------------+-----------------+---------------------+
## | 4 | 2021-04-13 | Tuesday | 46686.09 |
## +----+------------+-----------------+---------------------+
## | 5 | 2021-04-14 | Wednesday | 46686.74 |
## +----+------------+-----------------+---------------------+
## | 6 | 2021-04-15 | Thursday | 46687.32 |
## +----+------------+-----------------+---------------------+
## | 7 | 2021-04-16 | Friday | 46687.83 |
## +----+------------+-----------------+---------------------+
## | 8 | 2021-04-17 | Saturday | 46688.29 |
## +----+------------+-----------------+---------------------+
## | 9 | 2021-04-18 | Sunday | 46688.69 |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-04-19 | Monday | 46689.04 |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-04-20 | Tuesday | 46689.36 |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-04-21 | Wednesday | 46689.64 |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-04-22 | Thursday | 46689.88 |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-04-23 | Friday | 46690.10 |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-04-24 | Saturday | 46690.29 |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-04-25 | Sunday | 46690.46 |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-04-26 | Monday | 46690.61 |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-04-27 | Tuesday | 46690.75 |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-04-28 | Wednesday | 46690.86 |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-04-29 | Thursday | 46690.97 |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-04-30 | Friday | 46691.06 |
## +----+------------+-----------------+---------------------+
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 4.920209 76.23611 42.89116 -Inf Inf 0.3354419 -0.003300385
# Print Model Parameters
model_bats
## BATS(1, {0,0}, 0.987, -)
##
## Call: bats(y = data_series)
##
## Parameters
## Alpha: 1.180673
## Beta: 0.4064877
## Damping Parameter: 0.987424
##
## Seed States:
## [,1]
## [1,] 0.294984
## [2,] 2.846649
##
## Sigma: 76.23611
## AIC: 5296.033
#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 31 days by using bats Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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 31 days in bats Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
paste(MAPE_Mean_All.bats,"%")
## [1] "1.361 % MAPE 31 days Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk %"
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 31 days in bats Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-10 | Wednesday | 46447.00 | 46449.95 | 0.006 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2 | 2021-03-11 | Thursday | 46605.00 | 46611.99 | 0.015 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3 | 2021-03-12 | Friday | 46761.00 | 46772.00 | 0.024 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4 | 2021-03-13 | Saturday | 46916.00 | 46930.00 | 0.03 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5 | 2021-03-14 | Sunday | 47069.00 | 47086.01 | 0.036 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6 | 2021-03-15 | Monday | 47221.00 | 47240.05 | 0.04 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7 | 2021-03-16 | Tuesday | 47399.00 | 47392.16 | 0.014 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8 | 2021-03-17 | Wednesday | 47596.00 | 47542.36 | 0.113 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9 | 2021-03-18 | Thursday | 47811.00 | 47690.66 | 0.252 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-03-19 | Friday | 48046.00 | 47837.11 | 0.435 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-03-20 | Saturday | 48287.00 | 47981.71 | 0.632 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-03-21 | Sunday | 48541.00 | 48124.49 | 0.858 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-03-22 | Monday | 48790.00 | 48265.48 | 1.075 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-03-23 | Tuesday | 49023.00 | 48404.69 | 1.261 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-03-24 | Wednesday | 49234.00 | 48542.15 | 1.405 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-03-25 | Thursday | 49421.00 | 48677.88 | 1.504 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-03-26 | Friday | 49585.00 | 48811.91 | 1.559 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-03-27 | Saturday | 49746.00 | 48944.25 | 1.612 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-03-28 | Sunday | 49924.00 | 49074.93 | 1.701 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-03-29 | Monday | 50123.00 | 49203.96 | 1.834 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-03-30 | Tuesday | 50293.00 | 49331.37 | 1.912 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-03-31 | Wednesday | 50488.00 | 49457.18 | 2.042 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-01 | Thursday | 50705.00 | 49581.41 | 2.216 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-02 | Friday | 50928.00 | 49704.07 | 2.403 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-03 | Saturday | 51129.00 | 49825.19 | 2.55 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-04 | Sunday | 51311.00 | 49944.79 | 2.663 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-05 | Monday | 51472.00 | 50062.89 | 2.738 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-06 | Tuesday | 51611.00 | 50179.49 | 2.774 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-07 | Wednesday | 51733.00 | 50294.64 | 2.78 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-08 | Thursday | 51881.00 | 50408.33 | 2.839 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-09 | Friday | 52005.00 | 50520.60 | 2.854 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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-04-10 | Saturday | 50631.45 | 46562.95 | 44409.22 | 46562.95 | 44409.22 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 50740.91 | 46511.98 | 44273.32 | 46511.98 | 44273.32 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 50848.99 | 46458.54 | 44134.38 | 46458.54 | 44134.38 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 50955.71 | 46402.71 | 43992.50 | 46402.71 | 43992.50 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 51061.09 | 46344.55 | 43847.77 | 46344.55 | 43847.77 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 51165.15 | 46284.13 | 43700.28 | 46284.13 | 43700.28 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 51267.89 | 46221.51 | 43550.11 | 46221.51 | 43550.11 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 51369.35 | 46156.75 | 43397.36 | 46156.75 | 43397.36 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 51469.53 | 46089.91 | 43242.11 | 46089.91 | 43242.11 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 51568.45 | 46021.04 | 43084.42 | 46021.04 | 43084.42 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 51666.12 | 45950.21 | 42924.39 | 45950.21 | 42924.39 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 51762.57 | 45877.47 | 42762.08 | 45877.47 | 42762.08 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 51857.80 | 45802.86 | 42597.57 | 45802.86 | 42597.57 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 51951.84 | 45726.44 | 42430.92 | 45726.44 | 42430.92 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 52044.69 | 45648.27 | 42262.20 | 45648.27 | 42262.20 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 52136.37 | 45568.37 | 42091.48 | 45568.37 | 42091.48 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 52226.91 | 45486.81 | 41918.82 | 45486.81 | 41918.82 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 52316.30 | 45403.62 | 41744.27 | 45403.62 | 41744.27 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 52404.57 | 45318.85 | 41567.90 | 45318.85 | 41567.90 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 52491.73 | 45232.55 | 41389.77 | 45232.55 | 41389.77 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 52577.79 | 45144.74 | 41209.93 | 45144.74 | 41209.93 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
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 1.171742 75.86472 44.55446 NaN Inf 0.3484502 -0.001713971
# Print Model Parameters
model_TBATS
## TBATS(1, {0,0}, 1, {<6,2>})
##
## Call: NULL
##
## Parameters
## Alpha: 1.201059
## Beta: 0.4021874
## Damping Parameter: 1
## Gamma-1 Values: -0.005180363
## Gamma-2 Values: 0.001142116
##
## Seed States:
## [,1]
## [1,] 0.6144247
## [2,] 2.9390271
## [3,] 5.8529295
## [4,] -2.2228888
## [5,] -1.7675832
## [6,] -1.6516381
##
## Sigma: 75.86472
## AIC: 5302.487
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 31 days by using TBATS Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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 31 days in TBATS Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
paste(MAPE_Mean_All.TBATS,"%")
## [1] "0.514 % MAPE 31 days Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk %"
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 31 days in TBATS Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-10 | Wednesday | 46447.00 | 46458.82 | 0.025 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 2 | 2021-03-11 | Thursday | 46605.00 | 46638.96 | 0.073 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 3 | 2021-03-12 | Friday | 46761.00 | 46822.59 | 0.132 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 4 | 2021-03-13 | Saturday | 46916.00 | 46996.70 | 0.172 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 5 | 2021-03-14 | Sunday | 47069.00 | 47161.24 | 0.196 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 6 | 2021-03-15 | Monday | 47221.00 | 47329.01 | 0.229 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 7 | 2021-03-16 | Tuesday | 47399.00 | 47502.86 | 0.219 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 8 | 2021-03-17 | Wednesday | 47596.00 | 47683.00 | 0.183 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 9 | 2021-03-18 | Thursday | 47811.00 | 47866.63 | 0.116 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 10 | 2021-03-19 | Friday | 48046.00 | 48040.73 | 0.011 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 11 | 2021-03-20 | Saturday | 48287.00 | 48205.28 | 0.169 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 12 | 2021-03-21 | Sunday | 48541.00 | 48373.05 | 0.346 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 13 | 2021-03-22 | Monday | 48790.00 | 48546.89 | 0.498 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 14 | 2021-03-23 | Tuesday | 49023.00 | 48727.04 | 0.604 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 15 | 2021-03-24 | Wednesday | 49234.00 | 48910.66 | 0.657 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 16 | 2021-03-25 | Thursday | 49421.00 | 49084.77 | 0.68 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 17 | 2021-03-26 | Friday | 49585.00 | 49249.32 | 0.677 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 18 | 2021-03-27 | Saturday | 49746.00 | 49417.09 | 0.661 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 19 | 2021-03-28 | Sunday | 49924.00 | 49590.93 | 0.667 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 20 | 2021-03-29 | Monday | 50123.00 | 49771.08 | 0.702 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 21 | 2021-03-30 | Tuesday | 50293.00 | 49954.70 | 0.673 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 22 | 2021-03-31 | Wednesday | 50488.00 | 50128.81 | 0.711 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 23 | 2021-04-01 | Thursday | 50705.00 | 50293.36 | 0.812 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 24 | 2021-04-02 | Friday | 50928.00 | 50461.12 | 0.917 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 25 | 2021-04-03 | Saturday | 51129.00 | 50634.97 | 0.966 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 26 | 2021-04-04 | Sunday | 51311.00 | 50815.12 | 0.966 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 27 | 2021-04-05 | Monday | 51472.00 | 50998.74 | 0.919 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 28 | 2021-04-06 | Tuesday | 51611.00 | 51172.85 | 0.849 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 29 | 2021-04-07 | Wednesday | 51733.00 | 51337.40 | 0.765 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 30 | 2021-04-08 | Thursday | 51881.00 | 51505.16 | 0.724 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
## | 31 | 2021-04-09 | Friday | 52005.00 | 51679.01 | 0.627 % |
## +----+------------+-------------------------+-------------+-------------------+------------------+
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-04-10 | Saturday | 51859.15 | 51245.65 | 50920.89 | 52472.65 | 52797.42 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 52042.78 | 51421.11 | 51092.02 | 52664.45 | 52993.54 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 52216.89 | 51587.16 | 51253.80 | 52846.62 | 53179.98 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 52381.44 | 51743.77 | 51406.21 | 53019.10 | 53356.66 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 52549.20 | 51903.86 | 51562.24 | 53194.54 | 53536.16 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 52723.05 | 52070.27 | 51724.72 | 53375.82 | 53721.38 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 52903.19 | 52243.14 | 51893.73 | 53563.24 | 53912.65 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 53086.82 | 52419.61 | 52066.42 | 53754.02 | 54107.22 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 53260.93 | 52586.65 | 52229.71 | 53935.20 | 54292.15 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 53425.47 | 52744.22 | 52383.59 | 54106.73 | 54467.36 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 53593.24 | 52905.22 | 52541.01 | 54281.25 | 54645.47 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 53767.09 | 53072.51 | 52704.83 | 54461.66 | 54829.34 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 53947.23 | 53246.23 | 52875.14 | 54648.23 | 55019.32 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 54130.86 | 53423.53 | 53049.09 | 54838.18 | 55212.62 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 54304.97 | 53591.36 | 53213.61 | 55018.57 | 55396.32 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 54469.51 | 53749.72 | 53368.68 | 55189.31 | 55570.34 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 54637.28 | 53911.47 | 53527.26 | 55363.08 | 55747.30 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 54811.12 | 54079.49 | 53692.19 | 55542.76 | 55930.06 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 54991.27 | 54253.91 | 53863.58 | 55728.63 | 56118.96 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 55174.89 | 54431.89 | 54038.57 | 55917.89 | 56311.21 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 55349.00 | 54600.41 | 54204.12 | 56097.60 | 56493.88 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
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 -2.290668 81.14658 47.0406 -Inf Inf 0.3678937 0.3048274
# 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.4695
##
## Smoothing parameters:
## alpha = 0.9999
## beta = 0.2705
##
## Initial states:
## l = -2.0919
## b = 0.0167
##
## sigma: 0.6367
##
## AIC AICc BIC
## 1817.850 1818.018 1837.322
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -2.290668 81.14658 47.0406 -Inf Inf 0.3678937 0.3048274
# 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 31 days by using holt Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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 31 days in holt Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
paste(MAPE_Mean_All.Holt,"%")
## [1] "0.359 % MAPE 31 days Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk %"
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 31 days in holt Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-10 | Wednesday | 46447.00 | 46463.18 | 0.035 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 2 | 2021-03-11 | Thursday | 46605.00 | 46639.71 | 0.074 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 3 | 2021-03-12 | Friday | 46761.00 | 46816.59 | 0.119 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 4 | 2021-03-13 | Saturday | 46916.00 | 46993.83 | 0.166 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 5 | 2021-03-14 | Sunday | 47069.00 | 47171.43 | 0.218 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 6 | 2021-03-15 | Monday | 47221.00 | 47349.38 | 0.272 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 7 | 2021-03-16 | Tuesday | 47399.00 | 47527.69 | 0.272 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 8 | 2021-03-17 | Wednesday | 47596.00 | 47706.35 | 0.232 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 9 | 2021-03-18 | Thursday | 47811.00 | 47885.37 | 0.156 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 10 | 2021-03-19 | Friday | 48046.00 | 48064.75 | 0.039 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 11 | 2021-03-20 | Saturday | 48287.00 | 48244.48 | 0.088 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 12 | 2021-03-21 | Sunday | 48541.00 | 48424.56 | 0.24 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 13 | 2021-03-22 | Monday | 48790.00 | 48605.00 | 0.379 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 14 | 2021-03-23 | Tuesday | 49023.00 | 48785.80 | 0.484 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 15 | 2021-03-24 | Wednesday | 49234.00 | 48966.96 | 0.542 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 16 | 2021-03-25 | Thursday | 49421.00 | 49148.47 | 0.551 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 17 | 2021-03-26 | Friday | 49585.00 | 49330.33 | 0.514 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 18 | 2021-03-27 | Saturday | 49746.00 | 49512.56 | 0.469 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 19 | 2021-03-28 | Sunday | 49924.00 | 49695.14 | 0.458 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 20 | 2021-03-29 | Monday | 50123.00 | 49878.07 | 0.489 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 21 | 2021-03-30 | Tuesday | 50293.00 | 50061.37 | 0.461 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 22 | 2021-03-31 | Wednesday | 50488.00 | 50245.02 | 0.481 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 23 | 2021-04-01 | Thursday | 50705.00 | 50429.02 | 0.544 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 24 | 2021-04-02 | Friday | 50928.00 | 50613.39 | 0.618 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 25 | 2021-04-03 | Saturday | 51129.00 | 50798.11 | 0.647 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 26 | 2021-04-04 | Sunday | 51311.00 | 50983.18 | 0.639 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 27 | 2021-04-05 | Monday | 51472.00 | 51168.62 | 0.589 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 28 | 2021-04-06 | Tuesday | 51611.00 | 51354.41 | 0.497 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 29 | 2021-04-07 | Wednesday | 51733.00 | 51540.56 | 0.372 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 30 | 2021-04-08 | Thursday | 51881.00 | 51727.07 | 0.297 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
## | 31 | 2021-04-09 | Friday | 52005.00 | 51913.93 | 0.175 % |
## +----+------------+-------------------------+-------------+------------------+-----------------+
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-04-10 | Saturday | 52101.15 | 44005.71 | 40012.60 | 60925.09 | 65893.50 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 52288.73 | 43844.99 | 39693.12 | 61525.06 | 66738.04 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 52476.67 | 43680.00 | 39368.35 | 62133.69 | 67597.15 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 52664.96 | 43510.81 | 39038.46 | 62750.99 | 68470.89 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 52853.61 | 43337.52 | 38703.64 | 63376.98 | 69359.33 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 53042.63 | 43160.21 | 38364.04 | 64011.68 | 70262.53 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 53231.99 | 42978.95 | 38019.83 | 64655.09 | 71180.58 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 53421.72 | 42793.85 | 37671.17 | 65307.26 | 72113.54 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 53611.80 | 42604.96 | 37318.23 | 65968.20 | 73061.51 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 53802.25 | 42412.38 | 36961.17 | 66637.93 | 74024.57 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 53993.05 | 42216.17 | 36600.13 | 67316.49 | 75002.79 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 54184.21 | 42016.41 | 36235.27 | 68003.90 | 75996.26 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 54375.73 | 41813.19 | 35866.74 | 68700.19 | 77005.09 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 54567.60 | 41606.56 | 35494.70 | 69405.39 | 78029.35 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 54759.84 | 41396.60 | 35119.28 | 70119.54 | 79069.14 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 54952.43 | 41183.38 | 34740.64 | 70842.66 | 80124.56 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 55145.38 | 40966.97 | 34358.92 | 71574.79 | 81195.70 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 55338.69 | 40747.44 | 33974.27 | 72315.97 | 82282.67 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 55532.37 | 40524.85 | 33586.81 | 73066.24 | 83385.56 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 55726.39 | 40299.28 | 33196.69 | 73825.62 | 84504.48 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 55920.78 | 40070.78 | 32804.06 | 74594.17 | 85639.54 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
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
##################
require(tseries) # need to install tseries tj test Stationarity in time series
paste ("tests For Check Stationarity in series ==> ",y_lab, sep=" ")
## [1] "tests For Check Stationarity in series ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
kpss.test(data_series) # applay kpss test
## Warning in kpss.test(data_series): p-value smaller than printed p-value
##
## KPSS Test for Level Stationarity
##
## data: data_series
## KPSS Level = 5.5216, 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) = 1.6608, Truncation lag parameter = 5, p-value
## = 0.99
## alternative hypothesis: stationary
adf.test(data_series) # applay adf test
##
## Augmented Dickey-Fuller Test
##
## data: data_series
## Dickey-Fuller = -1.5033, Lag order = 7, p-value = 0.7865
## 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 Recovery cases in Chelyabinsk"
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 = 2.5197, Truncation lag parameter = 5, p-value = 0.01
pp.test(diff1_x1) # applay pp test after taking first differences
## Warning in pp.test(diff1_x1): p-value smaller than printed p-value
##
## Phillips-Perron Unit Root Test
##
## data: diff1_x1
## Dickey-Fuller Z(alpha) = -65.374, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
adf.test(diff1_x1) # applay adf test after taking first differences
##
## Augmented Dickey-Fuller Test
##
## data: diff1_x1
## Dickey-Fuller = -2.9692, Lag order = 7, p-value = 0.1679
## 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 Recovery cases in Chelyabinsk"
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.025909, 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) = -361.36, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
adf.test(diff2_x1) # applay adf test after taking Second differences
## Warning in adf.test(diff2_x1): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff2_x1
## Dickey-Fuller = -8.1741, 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) : 4227.675
## ARIMA(0,2,1) : 4176.151
## ARIMA(0,2,2) : 4163.943
## ARIMA(0,2,3) : 4165.934
## ARIMA(0,2,4) : 4165.135
## ARIMA(0,2,5) : 4163.157
## ARIMA(1,2,0) : 4203.824
## ARIMA(1,2,1) : 4165.905
## ARIMA(1,2,2) : 4165.965
## ARIMA(1,2,3) : 4167.764
## ARIMA(1,2,4) : 4165.742
## ARIMA(2,2,0) : 4185.844
## ARIMA(2,2,1) : 4164.377
## ARIMA(2,2,2) : 4163.286
## ARIMA(2,2,3) : 4160.431
## ARIMA(3,2,0) : 4167.827
## ARIMA(3,2,1) : 4162.181
## ARIMA(3,2,2) : 4162.733
## ARIMA(4,2,0) : 4158.929
## ARIMA(4,2,1) : 4160.935
## ARIMA(5,2,0) : 4160.93
##
##
##
## Best model: ARIMA(4,2,0)
model1 # show the result of autoarima
## Series: data_series
## ARIMA(4,2,0)
##
## Coefficients:
## ar1 ar2 ar3 ar4
## -0.4184 -0.3603 -0.2969 -0.1719
## s.e. 0.0518 0.0540 0.0539 0.0515
##
## sigma^2 estimated as 5793: log likelihood=-2074.38
## AIC=4158.76 AICc=4158.93 BIC=4178.2
#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] 4 2 0
strtoi(bestmodel[3])
## [1] 0
#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

library(forecast) # install library forecast
x1_model1= arima(data_series, order=c(bestmodel)) # Run Best model of auto arima for forecasting
x1_model1 # Show result of best model of auto arima
##
## Call:
## arima(x = data_series, order = c(bestmodel))
##
## Coefficients:
## ar1 ar2 ar3 ar4
## -0.4184 -0.3603 -0.2969 -0.1719
## s.e. 0.0518 0.0540 0.0539 0.0515
##
## sigma^2 estimated as 5729: log likelihood = -2074.38, aic = 4158.76
paste ("accuracy of autoarima Model For ==> ",y_lab, sep=" ")
## [1] "accuracy of autoarima Model For ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
accuracy(x1_model1) # aacuracy of best model from auto arima
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 1.036487 75.47907 43.86832 0.4123501 2.232161 0.343084 0.001017614
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(4,2,0)
## Q* = 2.0114, df = 6, p-value = 0.9186
##
## 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 Recovery cases in Chelyabinsk"
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 = 125.52, df = 20, p-value < 2.2e-16
library(tseries)
jarque.bera.test(x1_model1$residuals) # Do test jarque.bera.test
##
## Jarque Bera Test
##
## data: x1_model1$residuals
## X-squared = 1411.2, 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 31 days by using bats Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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 31 days in bats Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
paste(MAPE_Mean_All.ARIMA,"%")
## [1] "0.689 % MAPE 31 days Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk %"
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 31 days in bats Model for ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-10 | Wednesday | 46447.00 | 46453.88 | 0.015 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 2 | 2021-03-11 | Thursday | 46605.00 | 46622.36 | 0.037 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 3 | 2021-03-12 | Friday | 46761.00 | 46790.83 | 0.064 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 4 | 2021-03-13 | Saturday | 46916.00 | 46958.48 | 0.091 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 5 | 2021-03-14 | Sunday | 47069.00 | 47125.16 | 0.119 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 6 | 2021-03-15 | Monday | 47221.00 | 47292.27 | 0.151 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 7 | 2021-03-16 | Tuesday | 47399.00 | 47459.80 | 0.128 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 8 | 2021-03-17 | Wednesday | 47596.00 | 47627.42 | 0.066 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 9 | 2021-03-18 | Thursday | 47811.00 | 47794.90 | 0.034 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 10 | 2021-03-19 | Friday | 48046.00 | 47962.20 | 0.174 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 11 | 2021-03-20 | Saturday | 48287.00 | 48129.53 | 0.326 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 12 | 2021-03-21 | Sunday | 48541.00 | 48296.94 | 0.503 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 13 | 2021-03-22 | Monday | 48790.00 | 48464.38 | 0.667 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 14 | 2021-03-23 | Tuesday | 49023.00 | 48631.80 | 0.798 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 15 | 2021-03-24 | Wednesday | 49234.00 | 48799.19 | 0.883 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 16 | 2021-03-25 | Thursday | 49421.00 | 48966.58 | 0.919 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 17 | 2021-03-26 | Friday | 49585.00 | 49133.98 | 0.91 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 18 | 2021-03-27 | Saturday | 49746.00 | 49301.39 | 0.894 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 19 | 2021-03-28 | Sunday | 49924.00 | 49468.80 | 0.912 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 20 | 2021-03-29 | Monday | 50123.00 | 49636.20 | 0.971 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 21 | 2021-03-30 | Tuesday | 50293.00 | 49803.60 | 0.973 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 22 | 2021-03-31 | Wednesday | 50488.00 | 49971.00 | 1.024 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 23 | 2021-04-01 | Thursday | 50705.00 | 50138.40 | 1.117 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 24 | 2021-04-02 | Friday | 50928.00 | 50305.80 | 1.222 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 25 | 2021-04-03 | Saturday | 51129.00 | 50473.20 | 1.283 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 26 | 2021-04-04 | Sunday | 51311.00 | 50640.61 | 1.307 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 27 | 2021-04-05 | Monday | 51472.00 | 50808.01 | 1.29 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 28 | 2021-04-06 | Tuesday | 51611.00 | 50975.41 | 1.232 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 29 | 2021-04-07 | Wednesday | 51733.00 | 51142.81 | 1.141 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 30 | 2021-04-08 | Thursday | 51881.00 | 51310.21 | 1.1 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
## | 31 | 2021-04-09 | Friday | 52005.00 | 51477.62 | 1.014 % |
## +----+-----------------+-------------------------+-------------+------------------------+-----------------------+
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-04-10 | Saturday | 51645.02 | 46768.80 | 44187.48 | 56521.24 | 59102.56 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 51812.42 | 46717.60 | 44020.57 | 56907.24 | 59604.27 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 51979.82 | 46663.23 | 43848.80 | 57296.41 | 60110.85 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 52147.22 | 46605.74 | 43672.25 | 57688.71 | 60622.20 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 52314.63 | 46545.16 | 43490.98 | 58084.10 | 61138.27 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 52482.03 | 46481.53 | 43305.06 | 58482.53 | 61659.00 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 52649.43 | 46414.90 | 43114.54 | 58883.96 | 62184.32 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 52816.83 | 46345.31 | 42919.49 | 59288.36 | 62714.18 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 52984.23 | 46272.78 | 42719.96 | 59695.68 | 63248.51 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 53151.64 | 46197.37 | 42516.00 | 60105.91 | 63787.27 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 53319.04 | 46119.09 | 42307.67 | 60518.99 | 64330.41 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 53486.44 | 46037.99 | 42095.01 | 60934.89 | 64877.87 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 53653.84 | 45954.09 | 41878.08 | 61353.60 | 65429.60 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 53821.24 | 45867.42 | 41656.93 | 61775.06 | 65985.56 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 53988.65 | 45778.03 | 41431.59 | 62199.27 | 66545.71 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 54156.05 | 45685.92 | 41202.11 | 62626.17 | 67109.99 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 54323.45 | 45591.14 | 40968.54 | 63055.76 | 67678.36 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 54490.85 | 45493.71 | 40730.91 | 63487.99 | 68250.79 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 54658.25 | 45393.65 | 40489.27 | 63922.86 | 68827.24 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 54825.66 | 45291.00 | 40243.66 | 64360.31 | 69407.66 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 54993.06 | 45185.77 | 39994.10 | 64800.35 | 69992.01 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
plot(forecasting_auto_arima)
x1_test <- ts(testing_data, start =(rows-validation_data_days+1) )
lines(x1_test, col='red',lwd=2)

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

MAPE_Mean_All.ARIMA
## [1] "0.689 % MAPE 31 days Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
# 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)
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 Recovery cases in Chelyabinsk"
best_recommended_model
## [1] 0.359
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")}
panderOptions('table.split.table', Inf)
paste("Forecasting by using BATS Model ==> ", y_lab , sep=" ")
## [1] "Forecasting by using BATS Model ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-04-10 | Saturday | 50631.45 | 46562.95 | 44409.22 | 46562.95 | 44409.22 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 50740.91 | 46511.98 | 44273.32 | 46511.98 | 44273.32 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 50848.99 | 46458.54 | 44134.38 | 46458.54 | 44134.38 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 50955.71 | 46402.71 | 43992.50 | 46402.71 | 43992.50 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 51061.09 | 46344.55 | 43847.77 | 46344.55 | 43847.77 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 51165.15 | 46284.13 | 43700.28 | 46284.13 | 43700.28 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 51267.89 | 46221.51 | 43550.11 | 46221.51 | 43550.11 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 51369.35 | 46156.75 | 43397.36 | 46156.75 | 43397.36 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 51469.53 | 46089.91 | 43242.11 | 46089.91 | 43242.11 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 51568.45 | 46021.04 | 43084.42 | 46021.04 | 43084.42 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 51666.12 | 45950.21 | 42924.39 | 45950.21 | 42924.39 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 51762.57 | 45877.47 | 42762.08 | 45877.47 | 42762.08 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 51857.80 | 45802.86 | 42597.57 | 45802.86 | 42597.57 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 51951.84 | 45726.44 | 42430.92 | 45726.44 | 42430.92 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 52044.69 | 45648.27 | 42262.20 | 45648.27 | 42262.20 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 52136.37 | 45568.37 | 42091.48 | 45568.37 | 42091.48 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 52226.91 | 45486.81 | 41918.82 | 45486.81 | 41918.82 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 52316.30 | 45403.62 | 41744.27 | 45403.62 | 41744.27 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 52404.57 | 45318.85 | 41567.90 | 45318.85 | 41567.90 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 52491.73 | 45232.55 | 41389.77 | 45232.55 | 41389.77 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 52577.79 | 45144.74 | 41209.93 | 45144.74 | 41209.93 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
paste("Forecasting by using TBATS Model ==> ", y_lab , sep=" ")
## [1] "Forecasting by using TBATS Model ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-04-10 | Saturday | 51859.15 | 51245.65 | 50920.89 | 52472.65 | 52797.42 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 52042.78 | 51421.11 | 51092.02 | 52664.45 | 52993.54 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 52216.89 | 51587.16 | 51253.80 | 52846.62 | 53179.98 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 52381.44 | 51743.77 | 51406.21 | 53019.10 | 53356.66 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 52549.20 | 51903.86 | 51562.24 | 53194.54 | 53536.16 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 52723.05 | 52070.27 | 51724.72 | 53375.82 | 53721.38 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 52903.19 | 52243.14 | 51893.73 | 53563.24 | 53912.65 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 53086.82 | 52419.61 | 52066.42 | 53754.02 | 54107.22 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 53260.93 | 52586.65 | 52229.71 | 53935.20 | 54292.15 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 53425.47 | 52744.22 | 52383.59 | 54106.73 | 54467.36 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 53593.24 | 52905.22 | 52541.01 | 54281.25 | 54645.47 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 53767.09 | 53072.51 | 52704.83 | 54461.66 | 54829.34 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 53947.23 | 53246.23 | 52875.14 | 54648.23 | 55019.32 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 54130.86 | 53423.53 | 53049.09 | 54838.18 | 55212.62 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 54304.97 | 53591.36 | 53213.61 | 55018.57 | 55396.32 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 54469.51 | 53749.72 | 53368.68 | 55189.31 | 55570.34 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 54637.28 | 53911.47 | 53527.26 | 55363.08 | 55747.30 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 54811.12 | 54079.49 | 53692.19 | 55542.76 | 55930.06 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 54991.27 | 54253.91 | 53863.58 | 55728.63 | 56118.96 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 55174.89 | 54431.89 | 54038.57 | 55917.89 | 56311.21 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 55349.00 | 54600.41 | 54204.12 | 56097.60 | 56493.88 |
## +----+------------+-----------------+----------------------+-----------+-----------+-----------+-----------+
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 Recovery cases in Chelyabinsk"
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-04-10 | Saturday | 52101.15 | 44005.71 | 40012.60 | 60925.09 | 65893.50 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 52288.73 | 43844.99 | 39693.12 | 61525.06 | 66738.04 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 52476.67 | 43680.00 | 39368.35 | 62133.69 | 67597.15 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 52664.96 | 43510.81 | 39038.46 | 62750.99 | 68470.89 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 52853.61 | 43337.52 | 38703.64 | 63376.98 | 69359.33 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 53042.63 | 43160.21 | 38364.04 | 64011.68 | 70262.53 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 53231.99 | 42978.95 | 38019.83 | 64655.09 | 71180.58 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 53421.72 | 42793.85 | 37671.17 | 65307.26 | 72113.54 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 53611.80 | 42604.96 | 37318.23 | 65968.20 | 73061.51 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 53802.25 | 42412.38 | 36961.17 | 66637.93 | 74024.57 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 53993.05 | 42216.17 | 36600.13 | 67316.49 | 75002.79 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 54184.21 | 42016.41 | 36235.27 | 68003.90 | 75996.26 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 54375.73 | 41813.19 | 35866.74 | 68700.19 | 77005.09 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 54567.60 | 41606.56 | 35494.70 | 69405.39 | 78029.35 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 54759.84 | 41396.60 | 35119.28 | 70119.54 | 79069.14 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 54952.43 | 41183.38 | 34740.64 | 70842.66 | 80124.56 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 55145.38 | 40966.97 | 34358.92 | 71574.79 | 81195.70 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 55338.69 | 40747.44 | 33974.27 | 72315.97 | 82282.67 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 55532.37 | 40524.85 | 33586.81 | 73066.24 | 83385.56 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 55726.39 | 40299.28 | 33196.69 | 73825.62 | 84504.48 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 55920.78 | 40070.78 | 32804.06 | 74594.17 | 85639.54 |
## +----+------------+-----------------+---------------------+-----------+-----------+-----------+-----------+
paste("Forecasting by using ARIMA Model ==> ", y_lab , sep=" ")
## [1] "Forecasting by using ARIMA Model ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-04-10 | Saturday | 51645.02 | 46768.80 | 44187.48 | 56521.24 | 59102.56 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 2 | 2021-04-11 | Sunday | 51812.42 | 46717.60 | 44020.57 | 56907.24 | 59604.27 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 3 | 2021-04-12 | Monday | 51979.82 | 46663.23 | 43848.80 | 57296.41 | 60110.85 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 4 | 2021-04-13 | Tuesday | 52147.22 | 46605.74 | 43672.25 | 57688.71 | 60622.20 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 5 | 2021-04-14 | Wednesday | 52314.63 | 46545.16 | 43490.98 | 58084.10 | 61138.27 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 6 | 2021-04-15 | Thursday | 52482.03 | 46481.53 | 43305.06 | 58482.53 | 61659.00 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 7 | 2021-04-16 | Friday | 52649.43 | 46414.90 | 43114.54 | 58883.96 | 62184.32 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 8 | 2021-04-17 | Saturday | 52816.83 | 46345.31 | 42919.49 | 59288.36 | 62714.18 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 9 | 2021-04-18 | Sunday | 52984.23 | 46272.78 | 42719.96 | 59695.68 | 63248.51 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 10 | 2021-04-19 | Monday | 53151.64 | 46197.37 | 42516.00 | 60105.91 | 63787.27 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 11 | 2021-04-20 | Tuesday | 53319.04 | 46119.09 | 42307.67 | 60518.99 | 64330.41 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 12 | 2021-04-21 | Wednesday | 53486.44 | 46037.99 | 42095.01 | 60934.89 | 64877.87 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 13 | 2021-04-22 | Thursday | 53653.84 | 45954.09 | 41878.08 | 61353.60 | 65429.60 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 14 | 2021-04-23 | Friday | 53821.24 | 45867.42 | 41656.93 | 61775.06 | 65985.56 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 15 | 2021-04-24 | Saturday | 53988.65 | 45778.03 | 41431.59 | 62199.27 | 66545.71 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 16 | 2021-04-25 | Sunday | 54156.05 | 45685.92 | 41202.11 | 62626.17 | 67109.99 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 17 | 2021-04-26 | Monday | 54323.45 | 45591.14 | 40968.54 | 63055.76 | 67678.36 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 18 | 2021-04-27 | Tuesday | 54490.85 | 45493.71 | 40730.91 | 63487.99 | 68250.79 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 19 | 2021-04-28 | Wednesday | 54658.25 | 45393.65 | 40489.27 | 63922.86 | 68827.24 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 20 | 2021-04-29 | Thursday | 54825.66 | 45291.00 | 40243.66 | 64360.31 | 69407.66 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
## | 21 | 2021-04-30 | Friday | 54993.06 | 45185.77 | 39994.10 | 64800.35 | 69992.01 |
## +----+------------+-----------------+---------------------------+-----------+-----------+-----------+-----------+
paste("Forecasting by using NNAR Model ==> ", y_lab , sep=" ")
## [1] "Forecasting by using NNAR Model ==> Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk"
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-04-10 | Saturday | 46683.56 |
## +----+------------+-----------------+---------------------+
## | 2 | 2021-04-11 | Sunday | 46684.51 |
## +----+------------+-----------------+---------------------+
## | 3 | 2021-04-12 | Monday | 46685.35 |
## +----+------------+-----------------+---------------------+
## | 4 | 2021-04-13 | Tuesday | 46686.09 |
## +----+------------+-----------------+---------------------+
## | 5 | 2021-04-14 | Wednesday | 46686.74 |
## +----+------------+-----------------+---------------------+
## | 6 | 2021-04-15 | Thursday | 46687.32 |
## +----+------------+-----------------+---------------------+
## | 7 | 2021-04-16 | Friday | 46687.83 |
## +----+------------+-----------------+---------------------+
## | 8 | 2021-04-17 | Saturday | 46688.29 |
## +----+------------+-----------------+---------------------+
## | 9 | 2021-04-18 | Sunday | 46688.69 |
## +----+------------+-----------------+---------------------+
## | 10 | 2021-04-19 | Monday | 46689.04 |
## +----+------------+-----------------+---------------------+
## | 11 | 2021-04-20 | Tuesday | 46689.36 |
## +----+------------+-----------------+---------------------+
## | 12 | 2021-04-21 | Wednesday | 46689.64 |
## +----+------------+-----------------+---------------------+
## | 13 | 2021-04-22 | Thursday | 46689.88 |
## +----+------------+-----------------+---------------------+
## | 14 | 2021-04-23 | Friday | 46690.10 |
## +----+------------+-----------------+---------------------+
## | 15 | 2021-04-24 | Saturday | 46690.29 |
## +----+------------+-----------------+---------------------+
## | 16 | 2021-04-25 | Sunday | 46690.46 |
## +----+------------+-----------------+---------------------+
## | 17 | 2021-04-26 | Monday | 46690.61 |
## +----+------------+-----------------+---------------------+
## | 18 | 2021-04-27 | Tuesday | 46690.75 |
## +----+------------+-----------------+---------------------+
## | 19 | 2021-04-28 | Wednesday | 46690.86 |
## +----+------------+-----------------+---------------------+
## | 20 | 2021-04-29 | Thursday | 46690.97 |
## +----+------------+-----------------+---------------------+
## | 21 | 2021-04-30 | Friday | 46691.06 |
## +----+------------+-----------------+---------------------+
result<-c(x1,x2,x3,x4,x5)
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,Best.Model=result)
library(ascii)
print(ascii(table(table.error)), type = "rest")
##
## +---+--------------+------------+------------+-------------+------------+-------------+------------+------+
## | | country.name | NNAR.model | BATS.Model | TBATS.Model | Holt.Model | ARIMA.Model | Best.Model | Freq |
## +===+==============+============+============+=============+============+=============+============+======+
## | 1 | Chelyabinsk | 5.367 | 1.361 | 0.514 | 0.359 | 0.689 | Holt Model | 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)
Model<-c("NNAR.model","BATS.Model","TBATS.Model","Holt.Model","ARIMA.Model")
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 SIR Model ==>",y_lab, sep=" ")
## System finished Modelling and Forecasting by using BATS, TBATS, Holt's Linear Trend,ARIMA Model, and SIR Model ==>Forecasting Cumulative Covid 19 Recovery cases in Chelyabinsk
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 Recovery cases in Chelyabinsk