Useful Packages

library(FactoMineR)
library(PerformanceAnalytics)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(rpart)
library(rpart.plot)
library(tidyverse)
## -- Attaching packages ------------------------------------------------------------------------- tidyverse 1.3.0 --
## v tibble  2.1.3     v dplyr   0.8.5
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## v purrr   0.3.3
## -- Conflicts ---------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks plotly::filter(), stats::filter()
## x dplyr::first()  masks xts::first()
## x dplyr::lag()    masks stats::lag()
## x dplyr::last()   masks xts::last()
library(dplyr)
library(tidyr)
library(FactoMineR)
library(DT)
library(rpivotTable)
library(treemap)
library(treemapify)
library(tidyverse)
library(viridis)
## Loading required package: viridisLite
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
library(ggcorrplot)
library(moonBook)
library(webr)
library(webreadr)
library(magrittr)  
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(ggforce) 
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(PerformanceAnalytics)
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## 
## Attaching package: 'tseries'
## The following object is masked from 'package:webr':
## 
##     runs.test
library(forecast)

Checking Data

#Checking data
co<-read.csv("C://Users/md/Desktop/Research/10 countries cocona Update.csv")
as.Date(co$DateRep)
##   [1] "0008-03-20" "0014-03-20" "0016-03-20" "0017-03-20" "0018-03-20"
##   [6] "0019-03-20" "0021-03-20" "0022-03-20" "0023-03-20" "0024-03-20"
##  [11] "0001-03-20" "0002-03-20" "0003-03-20" "0004-03-20" "0005-03-20"
##  [16] "0006-03-20" "0007-03-20" "0008-03-20" "0009-03-20" "0010-03-20"
##  [21] "0011-03-20" "0012-03-20" "0013-03-20" "0014-03-20" "0015-03-20"
##  [26] "0016-03-20" "0017-03-20" "0018-03-20" "0019-03-20" "0020-03-20"
##  [31] "0021-03-20" "0022-03-20" "0023-03-20" "0020-02-20" "0021-02-20"
##  [36] "0022-02-20" "0023-02-20" "0024-02-20" "0025-02-20" "0026-02-20"
##  [41] "0027-02-20" "0028-02-20" "0029-02-20" "0001-03-20" "0002-03-20"
##  [46] "0003-03-20" "0004-03-20" "0005-03-20" "0006-03-20" "0007-03-20"
##  [51] "0008-03-20" "0009-03-20" "0010-03-20" "0011-03-20" "0012-03-20"
##  [56] "0013-03-20" "0014-03-20" "0015-03-20" "0016-03-20" "0017-03-20"
##  [61] "0018-03-20" "0019-03-20" "0020-03-20" "0021-03-20" "0022-03-20"
##  [66] "0023-03-20" "0031-01-20" "0022-02-20" "0023-02-20" "0024-02-20"
##  [71] "0025-02-20" "0026-02-20" "0027-02-20" "0028-02-20" "0029-02-20"
##  [76] "0001-03-20" "0002-03-20" "0003-03-20" "0004-03-20" "0005-03-20"
##  [81] "0006-03-20" "0007-03-20" "0008-03-20" "0009-03-20" "0010-03-20"
##  [86] "0011-03-20" "0012-03-20" "0013-03-20" "0014-03-20" "0015-03-20"
##  [91] "0016-03-20" "0017-03-20" "0018-03-20" "0019-03-20" "0020-03-20"
##  [96] "0021-03-20" "0022-03-20" "0023-03-20" "0001-02-20" "0025-02-20"
## [101] "0026-02-20" "0027-02-20" "0028-02-20" "0029-02-20" "0001-03-20"
## [106] "0002-03-20" "0003-03-20" "0004-03-20" "0005-03-20" "0006-03-20"
## [111] "0007-03-20" "0008-03-20" "0009-03-20" "0010-03-20" "0011-03-20"
## [116] "0012-03-20" "0013-03-20" "0014-03-20" "0015-03-20" "0016-03-20"
## [121] "0017-03-20" "0018-03-20" "0019-03-20" "0020-03-20" "0021-03-20"
## [126] "0022-03-20" "0023-03-20" "0021-01-20" "0025-01-20" "0027-01-20"
## [131] "0031-01-20" "0001-02-20" "0002-02-20" "0003-02-20" "0006-02-20"
## [136] "0011-02-20" "0013-02-20" "0014-02-20" "0021-02-20" "0022-02-20"
## [141] "0025-02-20" "0027-02-20" "0028-02-20" "0029-02-20" "0001-03-20"
## [146] "0002-03-20" "0003-03-20" "0004-03-20" "0005-03-20" "0006-03-20"
## [151] "0007-03-20" "0008-03-20" "0009-03-20" "0010-03-20" "0011-03-20"
## [156] "0012-03-20" "0013-03-20" "0014-03-20" "0015-03-20" "0016-03-20"
## [161] "0017-03-20" "0018-03-20" "0019-03-20" "0020-03-20" "0021-03-20"
## [166] "0022-03-20" "0023-03-20" "0028-01-20" "0029-01-20" "0031-01-20"
## [171] "0001-02-20" "0002-02-20" "0003-02-20" "0004-02-20" "0007-02-20"
## [176] "0008-02-20" "0012-02-20" "0026-02-20" "0027-02-20" "0028-02-20"
## [181] "0029-02-20" "0001-03-20" "0002-03-20" "0003-03-20" "0004-03-20"
## [186] "0005-03-20" "0006-03-20" "0007-03-20" "0008-03-20" "0009-03-20"
## [191] "0010-03-20" "0011-03-20" "0012-03-20" "0013-03-20" "0014-03-20"
## [196] "0015-03-20" "0016-03-20" "0017-03-20" "0018-03-20" "0019-03-20"
## [201] "0020-03-20" "0021-03-20" "0022-03-20" "0023-03-20" "0029-01-20"
## [206] "0030-01-20" "0031-01-20" "0008-02-20" "0017-02-20" "0026-02-20"
## [211] "0027-02-20" "0028-02-20" "0029-02-20" "0001-03-20" "0002-03-20"
## [216] "0003-03-20" "0004-03-20" "0005-03-20" "0006-03-20" "0007-03-20"
## [221] "0008-03-20" "0009-03-20" "0010-03-20" "0011-03-20" "0012-03-20"
## [226] "0013-03-20" "0014-03-20" "0015-03-20" "0016-03-20" "0017-03-20"
## [231] "0018-03-20" "0019-03-20" "0020-03-20" "0021-03-20" "0022-03-20"
## [236] "0023-03-20" "0020-01-20" "0024-01-20" "0026-01-20" "0027-01-20"
## [241] "0031-01-20" "0001-02-20" "0002-02-20" "0004-02-20" "0005-02-20"
## [246] "0006-02-20" "0007-02-20" "0009-02-20" "0010-02-20" "0011-02-20"
## [251] "0016-02-20" "0017-02-20" "0018-02-20" "0019-02-20" "0020-02-20"
## [256] "0021-02-20" "0022-02-20" "0023-02-20" "0024-02-20" "0025-02-20"
## [261] "0026-02-20" "0027-02-20" "0028-02-20" "0029-02-20" "0001-03-20"
## [266] "0002-03-20" "0003-03-20" "0004-03-20" "0005-03-20" "0006-03-20"
## [271] "0007-03-20" "0008-03-20" "0009-03-20" "0010-03-20" "0011-03-20"
## [276] "0012-03-20" "0013-03-20" "0014-03-20" "0015-03-20" "0016-03-20"
## [281] "0017-03-20" "0018-03-20" "0019-03-20" "0020-03-20" "0021-03-20"
## [286] "0022-03-20" "0023-03-20" "0026-02-20" "0028-02-20" "0029-02-20"
## [291] "0001-03-20" "0002-03-20" "0003-03-20" "0004-03-20" "0005-03-20"
## [296] "0006-03-20" "0007-03-20" "0008-03-20" "0009-03-20" "0010-03-20"
## [301] "0011-03-20" "0012-03-20" "0013-03-20" "0014-03-20" "0015-03-20"
## [306] "0016-03-20" "0017-03-20" "0018-03-20" "0019-03-20" "0020-03-20"
## [311] "0021-03-20" "0022-03-20" "0023-03-20"

Correlation Matrix

corr <- round(cor(co[,2:3]), 1)
corr
##        Cases Deaths
## Cases    1.0    0.7
## Deaths   0.7    1.0
# Compute a matrix of correlation p-values
p.mat <- cor_pmat(co[,2:3])
p.mat
##               Cases       Deaths
## Cases  0.000000e+00 3.232661e-55
## Deaths 3.232661e-55 0.000000e+00
# Visualize the correlation matrix
# method = "square" (default)
ggcorrplot(corr)

# method = "circle"
ggcorrplot(corr, method = "circle")

# Add correlation coefficients
# argument lab = TRUE
ggcorrplot(corr, hc.order = TRUE, type = "lower",
           lab = TRUE)

Treemap Analysis

#Treemap Analysis of Top Countries Cases and Death
ggplot(co, aes(area = Cases, fill = Deaths, label = GeoId,
                    subgroup = Countries.and.territories)) +
  geom_treemap() +
  geom_treemap_subgroup_border() +
  geom_treemap_subgroup_text(place = "centre", grow = T, alpha = .9, colour =
                               "White", fontface = "italic", min.size = 0) +
  geom_treemap_text(colour = "Red", place = "topleft", reflow = T)

Linear regression plot

# Linear regression Analysis
lm<-lm(formula = Cases~Deaths,data = co)
lm
## 
## Call:
## lm(formula = Cases ~ Deaths, data = co)
## 
## Coefficients:
## (Intercept)       Deaths  
##      305.13        10.07
summary(lm)
## 
## Call:
## lm(formula = Cases ~ Deaths, data = co)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1958.0  -304.1  -262.5    36.6  6834.1 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 305.1344    52.4189   5.821 1.46e-08 ***
## Deaths       10.0743     0.5213  19.326  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 871.7 on 311 degrees of freedom
## Multiple R-squared:  0.5457, Adjusted R-squared:  0.5442 
## F-statistic: 373.5 on 1 and 311 DF,  p-value: < 2.2e-16
# Linear regression plot
a<-ggplot(data = co,aes(Cases,Deaths,fill=Countries.and.territories))+
  geom_point()+
  geom_smooth(method = "lm")
a
## `geom_smooth()` using formula 'y ~ x'

Bangladeshi covid-19 Outbreak 2020

# country Analysis
#Bangladesh 
t1<-co%>%filter(Countries.and.territories=="Bangladesh")%>%
  group_by(DateRep,Cases,Deaths,Countries.and.territories,GeoId)
datatable(t1,caption = 't1')
#Pie Chart about total case and Death 
PieDonut(t1,aes(Cases,Deaths),explode=1,explodeDonut=TRUE,title = "Bangladesh covid-19 Total Cases and Death")
## Warning: Ignoring unknown aesthetics: explode

PieDonut(t1,aes(Cases,Deaths),explode=3,r1=0.9,explodeDonut=TRUE,title="Bangladesh covid-19 Total Cases and Death",star=3*pi/2,labelposition=0)
## Warning: Ignoring unknown aesthetics: explode

#Correlation Matrix
corr2 <- round(cor(t1[,2:3]), 1)
corr2
##        Cases Deaths
## Cases    1.0    0.9
## Deaths   0.9    1.0
# Compute a matrix of correlation p-values
p.mat2 <- cor_pmat(t1[,2:3])
p.mat2
##               Cases       Deaths
## Cases  0.000000e+00 5.325786e-05
## Deaths 5.325786e-05 0.000000e+00
# Visualize the correlation matrix
# method = "square" (default)
ggcorrplot(corr2)

# method = "circle"
ggcorrplot(corr2, method = "circle")

# Add correlation coefficients
# argument lab = TRUE
ggcorrplot(corr2, hc.order = TRUE, type = "lower",
           lab = TRUE)

# Treemap Analysis
tr1<-ggplot(t1, aes(area = Cases, fill = Deaths,label = GeoId)) +
  geom_treemap() +
  geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
                    grow = TRUE)
tr1

# Line Diagram
l1<-ggplot(data = t1, aes(Cases,Deaths,fill= Deaths))+
  geom_line()
l1

# Regression plot
reg1<-ggplot(data = t1,aes(Cases,Deaths),colour=Deaths)+
  geom_point()+
  geom_smooth(method = "lm")
reg1
## `geom_smooth()` using formula 'y ~ x'

# covid-19 Death Outbreak in Bangladesh
death1<-ggplot(data = t1, aes(x = Cases, y = Deaths, color = Deaths, size = Deaths)) + 
  geom_path() + 
  geom_point() + 
  facet_wrap(~ DateRep)+
  ggtitle("Covid-19 Death Outbreak in Banglaesh")
death1
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

# covid-19 Case Outbreak in Bangladesh
Case1<-ggplot(data = t1, aes(x = Cases, y = Deaths, color = Cases, size = Cases)) + 
  geom_path() + 
  geom_point() + 
  facet_wrap(~ DateRep)+
  ggtitle("Covid-19 Case Outbreak in Banglaesh")
Case1
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

# forecasting of Death
Death.arima<-auto.arima(t1$Deaths)
Death.arima
## Series: t1$Deaths 
## ARIMA(0,1,0) 
## 
## sigma^2 estimated as 0.8889:  log likelihood=-12.24
## AIC=26.48   AICc=27.05   BIC=26.68
#Forecasting
Death_model_forecast_Bangladesh<-forecast(Death.arima,h=11)
Death_model_forecast_Bangladesh
##    Point Forecast        Lo 80    Hi 80      Lo 95     Hi 95
## 11              4  2.791741597 5.208258  2.1521282  5.847872
## 12              4  2.291264579 5.708735  1.3867147  6.613285
## 13              4  1.907235057 6.092765  0.7993922  7.200608
## 14              4  1.583483194 6.416517  0.3042565  7.695744
## 15              4  1.298252076 6.701748 -0.1319669  8.131967
## 16              4  1.040383435 6.959617 -0.5263429  8.526343
## 17              4  0.803248745 7.196751 -0.8890091  8.889009
## 18              4  0.582529159 7.417471 -1.2265706  9.226571
## 19              4  0.375224790 7.624775 -1.5436153  9.543615
## 20              4  0.179151444 7.820849 -1.8434836  9.843484
## 21              4 -0.007339773 8.007340 -2.1286973 10.128697
#Forecast plot
plot(Death_model_forecast_Bangladesh,col = "orange")

# forecasting of Case
case.arima_Bangladesh<-auto.arima(t1$Cases)
case.arima_Bangladesh
## Series: t1$Cases 
## ARIMA(0,1,0) with drift 
## 
## Coefficients:
##        drift
##       4.0000
## s.e.  0.8012
## 
## sigma^2 estimated as 6.5:  log likelihood=-20.66
## AIC=45.33   AICc=47.33   BIC=45.72
#Forecasting
Case_model_forecast_Bangladesh<-forecast(case.arima_Bangladesh,h=11)
Case_model_forecast_Bangladesh
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 11             43 39.73267 46.26733 38.00305 47.99695
## 12             47 42.37930 51.62070 39.93325 54.06675
## 13             51 45.34082 56.65918 42.34503 59.65497
## 14             55 48.46534 61.53466 45.00611 64.99389
## 15             59 51.69403 66.30597 47.82649 70.17351
## 16             63 54.99671 71.00329 50.76003 75.23997
## 17             67 58.35546 75.64454 53.77932 80.22068
## 18             71 61.75860 80.24140 56.86650 85.13350
## 19             75 65.19802 84.80198 60.00916 89.99084
## 20             79 68.66780 89.33220 63.19827 94.80173
## 21             83 72.16350 93.83650 66.42700 99.57300
#Forecast plot
plot2<-plot(Case_model_forecast_Bangladesh,col = "orange")

plot2
## $mean
## Time Series:
## Start = 11 
## End = 21 
## Frequency = 1 
##  [1] 43 47 51 55 59 63 67 71 75 79 83
## 
## $lower
## Time Series:
## Start = 11 
## End = 21 
## Frequency = 1 
##         80%      95%
## 11 39.73267 38.00305
## 12 42.37930 39.93325
## 13 45.34082 42.34503
## 14 48.46534 45.00611
## 15 51.69403 47.82649
## 16 54.99671 50.76003
## 17 58.35546 53.77932
## 18 61.75860 56.86650
## 19 65.19802 60.00916
## 20 68.66780 63.19827
## 21 72.16350 66.42700
## 
## $upper
## Time Series:
## Start = 11 
## End = 21 
## Frequency = 1 
##         80%      95%
## 11 46.26733 47.99695
## 12 51.62070 54.06675
## 13 56.65918 59.65497
## 14 61.53466 64.99389
## 15 66.30597 70.17351
## 16 71.00329 75.23997
## 17 75.64454 80.22068
## 18 80.24140 85.13350
## 19 84.80198 89.99084
## 20 89.33220 94.80173
## 21 93.83650 99.57300