library(lubridate)
library(plotly)
library(tidyverse)
covid <- read.csv("https://raw.githubusercontent.com/laxmimerit/Covid-19-Preprocessed-Dataset/master/preprocessed/country_daywise.csv")
names(covid)
## [1] "Date" "Country" "Confirmed" "Deaths"
## [5] "Recovered" "Active" "New.Cases" "New.Recovered"
## [9] "New.Deaths"
str(covid)
## 'data.frame': 73152 obs. of 9 variables:
## $ Date : chr "2020-01-23" "2020-01-24" "2020-01-25" "2020-01-26" ...
## $ Country : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
## $ Confirmed : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Deaths : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Recovered : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Active : int 0 0 0 0 0 0 0 0 0 0 ...
## $ New.Cases : int 0 0 0 0 0 0 0 0 0 0 ...
## $ New.Recovered: int 0 0 0 0 0 0 0 0 0 0 ...
## $ New.Deaths : int 0 0 0 0 0 0 0 0 0 0 ...
covid$Date <- ymd(covid$Date)
str(covid)
## 'data.frame': 73152 obs. of 9 variables:
## $ Date : Date, format: "2020-01-23" "2020-01-24" ...
## $ Country : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
## $ Confirmed : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Deaths : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Recovered : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Active : int 0 0 0 0 0 0 0 0 0 0 ...
## $ New.Cases : int 0 0 0 0 0 0 0 0 0 0 ...
## $ New.Recovered: int 0 0 0 0 0 0 0 0 0 0 ...
## $ New.Deaths : int 0 0 0 0 0 0 0 0 0 0 ...
covid <- arrange(covid, Date)
tail(covid)
## Date Country Confirmed Deaths Recovered Active New.Cases
## 73147 2021-02-06 Venezuela 129643 1228 121569 6846 412
## 73148 2021-02-06 Vietnam 1985 35 1468 482 9
## 73149 2021-02-06 West Bank and Gaza 162029 1870 152120 8039 470
## 73150 2021-02-06 Yemen 2127 615 1428 84 3
## 73151 2021-02-06 Zambia 61427 839 53410 7178 1000
## 73152 2021-02-06 Zimbabwe 34487 1316 28383 4788 156
## New.Recovered New.Deaths
## 73147 475 5
## 73148 3 0
## 73149 430 3
## 73150 1 0
## 73151 1365 11
## 73152 238 13
daywise <- read.csv("https://raw.githubusercontent.com/laxmimerit/Covid-19-Preprocessed-Dataset/master/preprocessed/daywise.csv")
head(daywise)
## Date Confirmed Deaths Recovered Active New.Cases Deaths...100.Cases
## 1 2020-01-23 655 18 32 605 99 2.75
## 2 2020-01-24 941 26 39 876 287 2.76
## 3 2020-01-25 1433 42 42 1349 494 2.93
## 4 2020-01-26 2118 56 56 2006 685 2.64
## 5 2020-01-27 2927 82 65 2780 809 2.80
## 6 2020-01-28 5578 131 108 5339 2653 2.35
## Recovered...100.Cases Deaths...100.Recovered No..of.Countries
## 1 4.89 56.25 8
## 2 4.14 66.67 9
## 3 2.93 100.00 11
## 4 2.64 100.00 13
## 5 2.22 126.15 16
## 6 1.94 121.30 16
daywise$Date <- ymd(daywise$Date)
daywise <- arrange(daywise, Date)
head(daywise)
## Date Confirmed Deaths Recovered Active New.Cases Deaths...100.Cases
## 1 2020-01-23 655 18 32 605 99 2.75
## 2 2020-01-24 941 26 39 876 287 2.76
## 3 2020-01-25 1433 42 42 1349 494 2.93
## 4 2020-01-26 2118 56 56 2006 685 2.64
## 5 2020-01-27 2927 82 65 2780 809 2.80
## 6 2020-01-28 5578 131 108 5339 2653 2.35
## Recovered...100.Cases Deaths...100.Recovered No..of.Countries
## 1 4.89 56.25 8
## 2 4.14 66.67 9
## 3 2.93 100.00 11
## 4 2.64 100.00 13
## 5 2.22 126.15 16
## 6 1.94 121.30 16
plot_ly(daywise, x =~Date, y = ~Confirmed, type = "scatter", mode = "lines")
fig <- plot_ly(daywise, x=~Date)
fig <- fig %>% add_trace(y=~Confirmed, name = "Confirmed",
mode = "lines", type = "scatter")
fig
fig <- fig %>% add_trace(y=~Recovered, name = "Recovered",
mode = "lines", type = "scatter")
fig
fig <- fig %>% add_trace(y=~Deaths, name = "Deaths",
mode = "lines", type = "scatter")
fig
plot_ly(daywise, x =~Date, y = ~Deaths, type = "scatter", mode = "lines")
latest <- covid %>% filter(Date == max(Date)) %>% arrange(desc(Confirmed))
top10 <- latest %>% slice(1:10)
top10$prop <- (top10$Deaths / top10$Confirmed)*100
top10 # Maiores proporções de letalidade
## Date Country Confirmed Deaths Recovered Active New.Cases
## 1 2021-02-06 US 26917787 462169 0 26455618 104015
## 2 2021-02-06 India 10826363 154996 10522601 148766 12059
## 3 2021-02-06 Brazil 9447165 230034 8428992 788139 0
## 4 2021-02-06 United Kingdom 3941273 112305 10182 3818786 18363
## 5 2021-02-06 Russia 3907653 75010 3398545 434098 16379
## 6 2021-02-06 France 3376266 78940 238899 3058427 20588
## 7 2021-02-06 Spain 2941990 61386 150376 2730228 0
## 8 2021-02-06 Italy 2625098 91003 2107061 427034 13439
## 9 2021-02-06 Turkey 2524786 26685 2412505 85596 7897
## 10 2021-02-06 Germany 2285003 61551 2041988 181464 8632
## New.Recovered New.Deaths prop
## 1 0 2614 1.716965
## 2 11805 78 1.431653
## 3 32844 0 2.434953
## 4 88 828 2.849460
## 5 22546 490 1.919567
## 6 1144 191 2.338086
## 7 0 0 2.086547
## 8 15138 385 3.466652
## 9 8089 108 1.056921
## 10 8820 227 2.693694
top10$Reality <- (top10$Confirmed * top10$prop)
top10 # Realidade de casos estimados calculados com base na letalidade
## Date Country Confirmed Deaths Recovered Active New.Cases
## 1 2021-02-06 US 26917787 462169 0 26455618 104015
## 2 2021-02-06 India 10826363 154996 10522601 148766 12059
## 3 2021-02-06 Brazil 9447165 230034 8428992 788139 0
## 4 2021-02-06 United Kingdom 3941273 112305 10182 3818786 18363
## 5 2021-02-06 Russia 3907653 75010 3398545 434098 16379
## 6 2021-02-06 France 3376266 78940 238899 3058427 20588
## 7 2021-02-06 Spain 2941990 61386 150376 2730228 0
## 8 2021-02-06 Italy 2625098 91003 2107061 427034 13439
## 9 2021-02-06 Turkey 2524786 26685 2412505 85596 7897
## 10 2021-02-06 Germany 2285003 61551 2041988 181464 8632
## New.Recovered New.Deaths prop Reality
## 1 0 2614 1.716965 46216900
## 2 11805 78 1.431653 15499600
## 3 32844 0 2.434953 23003400
## 4 88 828 2.849460 11230500
## 5 22546 490 1.919567 7501000
## 6 1144 191 2.338086 7894000
## 7 0 0 2.086547 6138600
## 8 15138 385 3.466652 9100300
## 9 8089 108 1.056921 2668500
## 10 8820 227 2.693694 6155100
plot_ly(top10, x=~Country, y=~Confirmed, type = "bar", name = "Confirmed cases")
plot_ly(top10, x=~Country, y=~Reality, type = "bar", name = "Confirmed cases")
factor(top10$Country, levels = c(as.character(top10$Country)))
## [1] US India Brazil United Kingdom Russia
## [6] France Spain Italy Turkey Germany
## 10 Levels: US India Brazil United Kingdom Russia France Spain Italy ... Germany
top10$Country <- factor(top10$Country, levels = c(as.character(top10$Country))) # Ordenar
plot_ly(top10, x=~Country, y=~Confirmed, type = "bar", name = "Confirmed cases")
br <- covid %>% filter(Country == "Brazil") %>% arrange(Date)
fig1 <- plot_ly(br, x=~Date, y=~Confirmed, type ="scatter", mode = "lines", name = "Confirmed Cases")
fig2 <- plot_ly(br, x=~Date, y=~Recovered, type ="scatter", mode = "lines", name = "Recovered Cases")
fig3 <- plot_ly(br, x=~Date, y=~Deaths, type ="scatter", mode = "lines", name = "Death Cases")
subplot(fig1, fig2, fig3, nrows = 1, shareX = F)
cor(br$Confirmed, br$Deaths) # Correlação entre o número de mortos e o número de
## [1] 0.9897017
br$letalidade <- (br$Deaths / br$Confirmed)*100 # Calcular a letalidade
fig4 <- plot_ly(br, x=~Date, y=~letalidade, type ="scatter", mode = "lines", name = "Letalidade")
fig4 # Evolução da taxa de letalidade da Covid
fig5 <- plot_ly(br, x=~Date, y=~New.Cases, type ="scatter", mode = "lines", name = "Novos casos")
fig5 # Evolução do número de casos: Note a primeira onda e a segunda onda
subplot(fig4, fig5, nrows = 1, shareX = F)
# O período de alta letalidade não corresponde ao período de alta do número de internações. A alta letalidade pode então ser explicada pelo fato de que no início da pandemia se testava muito pouco
str(top10)
## 'data.frame': 10 obs. of 11 variables:
## $ Date : Date, format: "2021-02-06" "2021-02-06" ...
## $ Country : Factor w/ 10 levels "US","India","Brazil",..: 1 2 3 4 5 6 7 8 9 10
## $ Confirmed : int 26917787 10826363 9447165 3941273 3907653 3376266 2941990 2625098 2524786 2285003
## $ Deaths : int 462169 154996 230034 112305 75010 78940 61386 91003 26685 61551
## $ Recovered : int 0 10522601 8428992 10182 3398545 238899 150376 2107061 2412505 2041988
## $ Active : int 26455618 148766 788139 3818786 434098 3058427 2730228 427034 85596 181464
## $ New.Cases : int 104015 12059 0 18363 16379 20588 0 13439 7897 8632
## $ New.Recovered: int 0 11805 32844 88 22546 1144 0 15138 8089 8820
## $ New.Deaths : int 2614 78 0 828 490 191 0 385 108 227
## $ prop : num 1.72 1.43 2.43 2.85 1.92 ...
## $ Reality : num 46216900 15499600 23003400 11230500 7501000 ...
plot_ly(data = top10, x=~Confirmed, y=~Deaths, type = "scatter", mode = "markers",
color =~Country, colors = heat.colors(n=10),
size =~Confirmed, marker = list(size=~1e-4*Deaths))
head(top10)
## Date Country Confirmed Deaths Recovered Active New.Cases
## 1 2021-02-06 US 26917787 462169 0 26455618 104015
## 2 2021-02-06 India 10826363 154996 10522601 148766 12059
## 3 2021-02-06 Brazil 9447165 230034 8428992 788139 0
## 4 2021-02-06 United Kingdom 3941273 112305 10182 3818786 18363
## 5 2021-02-06 Russia 3907653 75010 3398545 434098 16379
## 6 2021-02-06 France 3376266 78940 238899 3058427 20588
## New.Recovered New.Deaths prop Reality
## 1 0 2614 1.716965 46216900
## 2 11805 78 1.431653 15499600
## 3 32844 0 2.434953 23003400
## 4 88 828 2.849460 11230500
## 5 22546 490 1.919567 7501000
## 6 1144 191 2.338086 7894000
fig6 <- plot_ly(top10, labels =~Country, values =~Confirmed, type = "pie",
textinfo = "label+percent")
fig6 # Casos confirmados
fig7 <- plot_ly(top10, labels =~Country, values =~Deaths, type = "pie",
textinfo = "label+percent")
fig7 # Mortes
fig8 <- plot_ly(top10, labels =~ Country,
values =~Deaths,
textinfo = "label+percent")
fig8 <- fig8 %>% add_pie(hole = 0.5)
fig8
library(covid19.analytics)
ag <- covid19.data(case = "aggregated")
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ts <- covid19.data(case = "ts-confirmed")
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
tsALL <- covid19.data(case = "ts-ALL")
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
report.summary(Nentries = 10,
graphical.output = F) # Faz um resumo
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
## ################################################################################
## ##### TS-CONFIRMED Cases -- Data dated: 2021-02-08 :: 2021-02-09 16:28:00
## ################################################################################
## Number of Countries/Regions reported: 192
## Number of Cities/Provinces reported: 85
## Unique number of distinct geographical locations combined: 273
## --------------------------------------------------------------------------------
## Worldwide ts-confirmed Totals: 106478046
## --------------------------------------------------------------------------------
## Country.Region Province.State Totals GlobalPerc LastDayChange t-2 t-3 t-7 t-14 t-30
## 1 US 27097095 25.45 89727 89581 104015 114437 146597 213281
## 2 India 10847304 10.19 9110 11831 12059 11039 12689 16311
## 3 Brazil 9524640 8.95 0 77475 0 54096 61963 29792
## 4 United Kingdom 3959784 3.72 14104 15845 18262 16840 20088 54940
## 5 Russia 3939162 3.70 15701 15808 16379 16406 17982 22540
## 6 France 3327305 3.12 4317 19715 19188 22659 21860 15801
## 7 Spain 2989085 2.81 47095 0 0 29064 36435 0
## 8 Italy 2644707 2.48 7969 11640 13439 9651 10584 18625
## 9 Turkey 2539559 2.39 8103 6670 7897 7795 7103 9138
## 10 Germany 2296323 2.16 4650 6670 8632 7690 9387 948
## --------------------------------------------------------------------------------
## Global Perc. Average: 0.37 (sd: 1.81)
## Global Perc. Average in top 10 : 6.5 (sd: 7.24)
## --------------------------------------------------------------------------------
## ================================================================================
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
## ################################################################################
## ##### TS-DEATHS Cases -- Data dated: 2021-02-08 :: 2021-02-09 16:28:01
## ################################################################################
## Number of Countries/Regions reported: 31
## Number of Cities/Provinces reported: 9
## Unique number of distinct geographical locations combined: 38
## --------------------------------------------------------------------------------
## Worldwide ts-deaths Totals: 364653
## --------------------------------------------------------------------------------
## Country.Region Province.State Totals Perc LastDayChange t-2 t-3 t-7 t-14 t-30
## 1 Brazil 231534 2.43 0 1500 0 1210 1214 469
## 2 Argentina 49398 2.49 227 61 125 177 219 78
## 3 Belgium 21423 2.95 34 37 57 49 65 40
## 4 Bolivia 10864 4.74 68 43 66 74 54 25
## 5 Bulgaria 9420 4.19 89 20 9 36 36 29
## 6 Bangladesh 8221 1.53 16 15 8 12 14 25
## 7 Austria 8032 1.89 20 18 21 69 64 36
## 8 Bosnia and Herzegovina 4813 3.88 38 0 0 13 28 25
## 9 Burma 3177 2.25 9 0 0 0 13 20
## 10 Azerbaijan 3161 1.37 3 2 3 5 7 19
## --------------------------------------------------------------------------------
## --------------------------------------------------------------------------------
## ================================================================================
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
## ################################################################################
## ##### TS-RECOVERED Cases -- Data dated: 2021-02-08 :: 2021-02-09 16:28:02
## ################################################################################
## Number of Countries/Regions reported: 192
## Number of Cities/Provinces reported: 69
## Unique number of distinct geographical locations combined: 258
## --------------------------------------------------------------------------------
## Worldwide ts-recovered Totals: 59382167
## --------------------------------------------------------------------------------
## Country.Region Province.State Totals LastDayChange t-2 t-3 t-7 t-14 t-30
## 1 India 10548521 14016 11904 11805 14225 13320 16959
## 2 Brazil 8478818 10836 38990 32844 55720 31321 25926
## 3 Russia 3434163 15834 19784 22546 21680 23525 23766
## 4 Turkey 2429273 -11433 28201 8089 8639 8108 8103
## 5 Italy 2133523 15082 11380 15138 18976 19256 11174
## 6 Germany 2054340 1684 10668 8820 19082 21997 20701
## 7 Colombia 2034228 6895 5002 11390 16668 15710 11455
## 8 Argentina 1786178 7213 6906 8297 8769 8028 7420
## 9 Mexico 1501580 11503 7939 9987 10734 12784 7168
## 10 South Africa 1363947 3743 19707 4879 12482 13253 9656
## --------------------------------------------------------------------------------
## --------------------------------------------------------------------------------
## ================================================================================
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## ############################################################################################################################################
## ##### AGGREGATED Data -- ORDERED BY CONFIRMED Cases -- Data dated: 2021-02-09 :: 2021-02-09 16:28:02
## ############################################################################################################################################
## Number of Countries/Regions reported: 192
## Number of Cities/Provinces reported: 576
## Unique number of distinct geographical locations combined: 3970
## --------------------------------------------------------------------------------------------------------------------------------------------
## Location Confirmed Perc.Confirmed Deaths Perc.Deaths Recovered Perc.Recovered Active Perc.Active
## 1 England, United Kingdom 3469231 3.26 99411 2.87 0 0.00 3369820 97.13
## 2 France 3327305 3.13 79030 2.38 208925 6.28 3039350 91.35
## 3 Turkey 2539559 2.39 26900 1.06 2429273 95.66 83386 3.28
## 4 Maharashtra, India 2046287 1.92 51325 2.51 1958971 95.73 35991 1.76
## 5 Argentina 1985501 1.86 49398 2.49 1786178 89.96 149925 7.55
## 6 Sao Paulo, Brazil 1849334 1.74 54614 2.95 1604022 86.74 190698 10.31
## 7 Poland 1552686 1.46 39132 2.52 1312856 84.55 200698 12.93
## 8 South Africa 1477511 1.39 46473 3.15 1363947 92.31 67091 4.54
## 9 Iran 1473756 1.38 58536 3.97 1260045 85.50 155175 10.53
## 10 Indonesia 1166079 1.10 31763 2.72 963028 82.59 171288 14.69
## ============================================================================================================================================
## ############################################################################################################################################
## ##### AGGREGATED Data -- ORDERED BY DEATHS Cases -- Data dated: 2021-02-09 :: 2021-02-09 16:28:02
## ############################################################################################################################################
## Number of Countries/Regions reported: 192
## Number of Cities/Provinces reported: 576
## Unique number of distinct geographical locations combined: 3970
## --------------------------------------------------------------------------------------------------------------------------------------------
## Location Confirmed Perc.Confirmed Deaths Perc.Deaths Recovered Perc.Recovered Active Perc.Active
## 1 England, United Kingdom 3469231 3.26 99411 2.87 0 0.00 3369820 97.13
## 2 France 3327305 3.13 79030 2.38 208925 6.28 3039350 91.35
## 3 Iran 1473756 1.38 58536 3.97 1260045 85.50 155175 10.53
## 4 Sao Paulo, Brazil 1849334 1.74 54614 2.95 1604022 86.74 190698 10.31
## 5 Maharashtra, India 2046287 1.92 51325 2.51 1958971 95.73 35991 1.76
## 6 Argentina 1985501 1.86 49398 2.49 1786178 89.96 149925 7.55
## 7 South Africa 1477511 1.39 46473 3.15 1363947 92.31 67091 4.54
## 8 Poland 1552686 1.46 39132 2.52 1312856 84.55 200698 12.93
## 9 Indonesia 1166079 1.10 31763 2.72 963028 82.59 171288 14.69
## 10 Rio de Janeiro, Brazil 537986 0.51 30597 5.69 499782 92.90 7607 1.41
## ============================================================================================================================================
## ############################################################################################################################################
## ##### AGGREGATED Data -- ORDERED BY RECOVERED Cases -- Data dated: 2021-02-09 :: 2021-02-09 16:28:02
## ############################################################################################################################################
## Number of Countries/Regions reported: 192
## Number of Cities/Provinces reported: 576
## Unique number of distinct geographical locations combined: 3970
## --------------------------------------------------------------------------------------------------------------------------------------------
## Location Confirmed Perc.Confirmed Deaths Perc.Deaths Recovered Perc.Recovered Active Perc.Active
## 1 Turkey 2539559 2.39 26900 1.06 2429273 95.66 83386 3.28
## 2 Maharashtra, India 2046287 1.92 51325 2.51 1958971 95.73 35991 1.76
## 3 Argentina 1985501 1.86 49398 2.49 1786178 89.96 149925 7.55
## 4 Sao Paulo, Brazil 1849334 1.74 54614 2.95 1604022 86.74 190698 10.31
## 5 South Africa 1477511 1.39 46473 3.15 1363947 92.31 67091 4.54
## 6 Poland 1552686 1.46 39132 2.52 1312856 84.55 200698 12.93
## 7 Iran 1473756 1.38 58536 3.97 1260045 85.50 155175 10.53
## 8 Indonesia 1166079 1.10 31763 2.72 963028 82.59 171288 14.69
## 9 Karnataka, India 942846 0.89 12239 1.30 924654 98.07 5953 0.63
## 10 Czechia 1037405 0.97 17333 1.67 922223 88.90 97849 9.43
## ============================================================================================================================================
## ############################################################################################################################################
## ##### AGGREGATED Data -- ORDERED BY ACTIVE Cases -- Data dated: 2021-02-09 :: 2021-02-09 16:28:03
## ############################################################################################################################################
## Number of Countries/Regions reported: 192
## Number of Cities/Provinces reported: 576
## Unique number of distinct geographical locations combined: 3970
## --------------------------------------------------------------------------------------------------------------------------------------------
## Location Confirmed Perc.Confirmed Deaths Perc.Deaths Recovered Perc.Recovered Active Perc.Active
## 1 England, United Kingdom 3469231 3.26 99411 2.87 0 0.00 3369820 97.13
## 2 France 3327305 3.13 79030 2.38 208925 6.28 3039350 91.35
## 3 Los Angeles, California, US 1149346 1.08 18146 1.58 0 0.00 1131200 98.42
## 4 Lima, Peru 536546 0.50 18525 3.45 0 0.00 518021 96.55
## 5 Catalonia, Spain 531520 0.50 9624 1.81 26203 4.93 495693 93.26
## 6 Madrid, Spain 546700 0.51 12924 2.36 40736 7.45 493040 90.18
## 7 Maricopa, Arizona, US 488687 0.46 7979 1.63 0 0.00 480708 98.37
## 8 Ciudad de Mexico, Mexico 503290 0.47 23883 4.75 0 0.00 479407 95.25
## 9 Cook, Illinois, US 461118 0.43 9024 1.96 0 0.00 452094 98.04
## 10 Andalusia, Spain 443758 0.42 6937 1.56 10671 2.40 426150 96.03
## ============================================================================================================================================
## Confirmed Deaths Recovered Active
## Totals
## 106464844 2301168 56786014 NA
## Average
## 26817.34 579.64 14303.78 NA
## Standard Deviation
## 133435.14 3324.95 95713.24 NA
##
##
## * Statistical estimators computed considering 3970 independent reported entries
##
##
## ********************************************************************************
## ******************************** OVERALL SUMMARY********************************
## ********************************************************************************
## **** Time Series Worldwide TOTS ****
## ts-confirmed ts-deaths ts-recovered
## 106478046 364653 59382167
## 0.34% 55.77%
## **** Time Series Worldwide AVGS ****
## ts-confirmed ts-deaths ts-recovered
## 390029.47 9855.49 230163.44
## 2.53% 59.01%
## **** Time Series Worldwide SDS ****
## ts-confirmed ts-deaths ts-recovered
## 1921683.49 38487.41 926655.25
## 2% 48.22%
##
##
## * Statistical estimators computed considering 273/38/258 independent reported entries per case-type
## ********************************************************************************
tots.per.location(ts, geo.loc = "BRAZIL")
## [1] "BRAZIL"
## BRAZIL -- 9524640
## =============================== running models...===============================
## Linear Regression (lm):
##
## Call:
## lm(formula = y.var ~ x.var)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1077841 -549127 -51294 415005 1868946
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1895394.5 74767.7 -25.35 <2e-16 ***
## x.var 26448.7 336.6 78.58 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 731100 on 382 degrees of freedom
## Multiple R-squared: 0.9417, Adjusted R-squared: 0.9416
## F-statistic: 6175 on 1 and 382 DF, p-value: < 2.2e-16
##
## --------------------------------------------------------------------------------
## Linear Regression (lm):
##
## Call:
## lm(formula = y.var ~ x.var)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.2171 -2.0139 0.6935 2.5404 3.3063
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.880250 0.290591 16.79 <2e-16 ***
## x.var 0.038195 0.001308 29.20 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.842 on 382 degrees of freedom
## Multiple R-squared: 0.6906, Adjusted R-squared: 0.6898
## F-statistic: 852.5 on 1 and 382 DF, p-value: < 2.2e-16
##
## --------------------------------------------------------------------------------
## GLM using Family [1] "poisson" :
##
## Call:
## glm(formula = y.var ~ x.var, family = family)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -992.0 -805.7 -205.8 470.8 877.4
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.244e+01 1.075e-04 115739 <2e-16 ***
## x.var 1.019e-02 3.524e-07 28919 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 1.312e+09 on 383 degrees of freedom
## Residual deviance: 1.726e+08 on 382 degrees of freedom
## AIC: 172606808
##
## Number of Fisher Scoring iterations: 5
##
## --------------------------------------------------------------------------------
tots.per.location(ts, geo.loc = c("BRAZIL", "US"))
## [1] "BRAZIL"
## [1] "US"
## BRAZIL -- 9524640
## =============================== running models...===============================
## Linear Regression (lm):
##
## Call:
## lm(formula = y.var ~ x.var)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1077841 -549127 -51294 415005 1868946
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1895394.5 74767.7 -25.35 <2e-16 ***
## x.var 26448.7 336.6 78.58 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 731100 on 382 degrees of freedom
## Multiple R-squared: 0.9417, Adjusted R-squared: 0.9416
## F-statistic: 6175 on 1 and 382 DF, p-value: < 2.2e-16
##
## --------------------------------------------------------------------------------
## Linear Regression (lm):
##
## Call:
## lm(formula = y.var ~ x.var)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.2171 -2.0139 0.6935 2.5404 3.3063
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.880250 0.290591 16.79 <2e-16 ***
## x.var 0.038195 0.001308 29.20 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.842 on 382 degrees of freedom
## Multiple R-squared: 0.6906, Adjusted R-squared: 0.6898
## F-statistic: 852.5 on 1 and 382 DF, p-value: < 2.2e-16
##
## --------------------------------------------------------------------------------
## GLM using Family [1] "poisson" :
##
## Call:
## glm(formula = y.var ~ x.var, family = family)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -992.0 -805.7 -205.8 470.8 877.4
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.244e+01 1.075e-04 115739 <2e-16 ***
## x.var 1.019e-02 3.524e-07 28919 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 1.312e+09 on 383 degrees of freedom
## Residual deviance: 1.726e+08 on 382 degrees of freedom
## AIC: 172606808
##
## Number of Fisher Scoring iterations: 5
##
## --------------------------------------------------------------------------------
## US -- 27097095
## =============================== running models...===============================
## Linear Regression (lm):
##
## Call:
## lm(formula = y.var ~ x.var)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3690182 -2464488 -921740 2154489 8194018
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5061326 327460 -15.46 <2e-16 ***
## x.var 62407 1474 42.34 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3202000 on 382 degrees of freedom
## Multiple R-squared: 0.8243, Adjusted R-squared: 0.8238
## F-statistic: 1792 on 1 and 382 DF, p-value: < 2.2e-16
##
## --------------------------------------------------------------------------------
## Linear Regression (lm):
##
## Call:
## lm(formula = y.var ~ x.var)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.8158 -1.4727 0.3736 2.1916 3.3002
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.44541 0.27101 27.47 <2e-16 ***
## x.var 0.03178 0.00122 26.05 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.65 on 382 degrees of freedom
## Multiple R-squared: 0.6398, Adjusted R-squared: 0.6389
## F-statistic: 678.6 on 1 and 382 DF, p-value: < 2.2e-16
##
## --------------------------------------------------------------------------------
## GLM using Family [1] "poisson" :
##
## Call:
## glm(formula = y.var ~ x.var, family = family)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1146.84 -326.04 22.44 154.77 650.80
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.280e+01 8.016e-05 159691 <2e-16 ***
## x.var 1.160e-02 2.569e-07 45155 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 3083433058 on 383 degrees of freedom
## Residual deviance: 104468990 on 382 degrees of freedom
## AIC: 104474903
##
## Number of Fisher Scoring iterations: 5
##
## --------------------------------------------------------------------------------
## GLM using Family Family: Gamma Link function: log :
##
## Call:
## glm(formula = y.var ~ x.var, family = family)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -4.6091 -0.5355 -0.1356 0.5714 0.7801
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.159e+01 6.680e-02 173.49 <2e-16 ***
## x.var 1.664e-02 3.007e-04 55.34 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Gamma family taken to be 0.4266553)
##
## Null deviance: 1693.64 on 383 degrees of freedom
## Residual deviance: 954.66 on 382 degrees of freedom
## AIC: 11994
##
## Number of Fisher Scoring iterations: 20
##
## --------------------------------------------------------------------------------
growth.rate(ts, geo.loc = "BRAZIL")
## [1] "BRAZIL"
## Processing... BRAZIL
## $Changes
## geo.loc 2020-01-23 2020-01-24 2020-01-25 2020-01-26 2020-01-27 2020-01-28
## 1 BRAZIL 0 0 0 0 0 0
## 2020-01-29 2020-01-30 2020-01-31 2020-02-01 2020-02-02 2020-02-03 2020-02-04
## 1 0 0 0 0 0 0 0
## 2020-02-05 2020-02-06 2020-02-07 2020-02-08 2020-02-09 2020-02-10 2020-02-11
## 1 0 0 0 0 0 0 0
## 2020-02-12 2020-02-13 2020-02-14 2020-02-15 2020-02-16 2020-02-17 2020-02-18
## 1 0 0 0 0 0 0 0
## 2020-02-19 2020-02-20 2020-02-21 2020-02-22 2020-02-23 2020-02-24 2020-02-25
## 1 0 0 0 0 0 0 0
## 2020-02-26 2020-02-27 2020-02-28 2020-02-29 2020-03-01 2020-03-02 2020-03-03
## 1 1 0 0 1 0 0 0
## 2020-03-04 2020-03-05 2020-03-06 2020-03-07 2020-03-08 2020-03-09 2020-03-10
## 1 2 0 9 0 7 5 6
## 2020-03-11 2020-03-12 2020-03-13 2020-03-14 2020-03-15 2020-03-16 2020-03-17
## 1 7 14 99 0 11 38 121
## 2020-03-18 2020-03-19 2020-03-20 2020-03-21 2020-03-22 2020-03-23 2020-03-24
## 1 51 249 172 228 525 378 323
## 2020-03-25 2020-03-26 2020-03-27 2020-03-28 2020-03-29 2020-03-30 2020-03-31
## 1 307 431 432 487 352 323 1138
## 2020-04-01 2020-04-02 2020-04-03 2020-04-04 2020-04-05 2020-04-06 2020-04-07
## 1 1119 1208 1012 1304 770 1031 1873
## 2020-04-08 2020-04-09 2020-04-10 2020-04-11 2020-04-12 2020-04-13 2020-04-14
## 1 2136 1922 1546 1089 1465 1238 1832
## 2020-04-15 2020-04-16 2020-04-17 2020-04-18 2020-04-19 2020-04-20 2020-04-21
## 1 3058 2105 3257 2976 1996 2089 2336
## 2020-04-22 2020-04-23 2020-04-24 2020-04-25 2020-04-26 2020-04-27 2020-04-28
## 1 2678 4279 4007 5281 3776 4346 5789
## 2020-04-29 2020-04-30 2020-05-01 2020-05-02 2020-05-03 2020-05-04 2020-05-05
## 1 6450 7502 5015 4898 4726 6794 6835
## 2020-05-06 2020-05-07 2020-05-08 2020-05-09 2020-05-10 2020-05-11 2020-05-12
## 1 11156 9162 11121 9167 6638 6895 8620
## 2020-05-13 2020-05-14 2020-05-15 2020-05-16 2020-05-17 2020-05-18 2020-05-19
## 1 11923 13028 17126 13220 7569 14288 16517
## 2020-05-20 2020-05-21 2020-05-22 2020-05-23 2020-05-24 2020-05-25 2020-05-26
## 1 19694 18508 20803 16508 15813 11687 16324
## 2020-05-27 2020-05-28 2020-05-29 2020-05-30 2020-05-31 2020-06-01 2020-06-02
## 1 20599 26417 26928 33274 16409 11598 28936
## 2020-06-03 2020-06-04 2020-06-05 2020-06-06 2020-06-07 2020-06-08 2020-06-09
## 1 28633 30925 30830 27075 18912 15654 32091
## 2020-06-10 2020-06-11 2020-06-12 2020-06-13 2020-06-14 2020-06-15 2020-06-16
## 1 32913 30412 25982 21704 17110 20647 34918
## 2020-06-17 2020-06-18 2020-06-19 2020-06-20 2020-06-21 2020-06-22 2020-06-23
## 1 32188 22765 54771 34666 15762 23129 39436
## 2020-06-24 2020-06-25 2020-06-26 2020-06-27 2020-06-28 2020-06-29 2020-06-30
## 1 42725 39483 46860 38693 30476 24052 33846
## 2020-07-01 2020-07-02 2020-07-03 2020-07-04 2020-07-05 2020-07-06 2020-07-07
## 1 46712 48105 42223 37923 26051 20229 45305
## 2020-07-08 2020-07-09 2020-07-10 2020-07-11 2020-07-12 2020-07-13 2020-07-14
## 1 44571 42619 45048 39023 24831 20286 41857
## 2020-07-15 2020-07-16 2020-07-17 2020-07-18 2020-07-19 2020-07-20 2020-07-21
## 1 39924 45403 34177 28532 23529 20257 41008
## 2020-07-22 2020-07-23 2020-07-24 2020-07-25 2020-07-26 2020-07-27 2020-07-28
## 1 67860 59961 55891 51147 24578 23284 40816
## 2020-07-29 2020-07-30 2020-07-31 2020-08-01 2020-08-02 2020-08-03 2020-08-04
## 1 69074 57837 52383 45392 25800 16641 51603
## 2020-08-05 2020-08-06 2020-08-07 2020-08-08 2020-08-09 2020-08-10 2020-08-11
## 1 57152 53139 50230 49970 23010 22048 52160
## 2020-08-12 2020-08-13 2020-08-14 2020-08-15 2020-08-16 2020-08-17 2020-08-18
## 1 55155 60091 50644 41576 23101 19373 47784
## 2020-08-19 2020-08-20 2020-08-21 2020-08-22 2020-08-23 2020-08-24 2020-08-25
## 1 49298 45323 30355 50032 23421 17078 47134
## 2020-08-26 2020-08-27 2020-08-28 2020-08-29 2020-08-30 2020-08-31 2020-09-01
## 1 47161 44235 43412 41350 16158 45961 42659
## 2020-09-02 2020-09-03 2020-09-04 2020-09-05 2020-09-06 2020-09-07 2020-09-08
## 1 46934 43773 50163 31199 14521 10273 14279
## 2020-09-09 2020-09-10 2020-09-11 2020-09-12 2020-09-13 2020-09-14 2020-09-15
## 1 35816 40557 43718 33523 14768 15155 36653
## 2020-09-16 2020-09-17 2020-09-18 2020-09-19 2020-09-20 2020-09-21 2020-09-22
## 1 36820 36303 39797 33057 16389 13411 33324
## 2020-09-23 2020-09-24 2020-09-25 2020-09-26 2020-09-27 2020-09-28 2020-09-29
## 1 0 66338 31911 28378 14318 13155 32058
## 2020-09-30 2020-10-01 2020-10-02 2020-10-03 2020-10-04 2020-10-05 2020-10-06
## 1 33413 36157 0 59741 8456 11946 41906
## 2020-10-07 2020-10-08 2020-10-09 2020-10-10 2020-10-11 2020-10-12 2020-10-13
## 1 31553 27750 27444 26749 12342 8429 10220
## 2020-10-14 2020-10-15 2020-10-16 2020-10-17 2020-10-18 2020-10-19 2020-10-20
## 1 27235 28523 30914 24062 0 26365 23227
## 2020-10-21 2020-10-22 2020-10-23 2020-10-24 2020-10-25 2020-10-26 2020-10-27
## 1 24818 24858 30026 26979 13493 15726 29787
## 2020-10-28 2020-10-29 2020-10-30 2020-10-31 2020-11-01 2020-11-02 2020-11-03
## 1 28629 26106 22282 18947 10100 8501 11843
## 2020-11-04 2020-11-05 2020-11-06 2020-11-07 2020-11-08 2020-11-09 2020-11-10
## 1 23976 0 41156 22380 10554 10917 23973
## 2020-11-11 2020-11-12 2020-11-13 2020-11-14 2020-11-15 2020-11-16 2020-11-17
## 1 48655 33922 29070 38307 14134 13371 35294
## 2020-11-18 2020-11-19 2020-11-20 2020-11-21 2020-11-22 2020-11-23 2020-11-24
## 1 34091 35918 38397 32622 18615 16207 31100
## 2020-11-25 2020-11-26 2020-11-27 2020-11-28 2020-11-29 2020-11-30 2020-12-01
## 1 47898 37614 34130 51922 24468 21138 50909
## 2020-12-02 2020-12-03 2020-12-04 2020-12-05 2020-12-06 2020-12-07 2020-12-08
## 1 49863 50434 46884 43209 26363 20371 51088
## 2020-12-09 2020-12-10 2020-12-11 2020-12-12 2020-12-13 2020-12-14 2020-12-15
## 1 53453 53347 54428 43900 21825 25193 42889
## 2020-12-16 2020-12-17 2020-12-18 2020-12-19 2020-12-20 2020-12-21 2020-12-22
## 1 70574 69826 52544 50177 25445 25019 55202
## 2020-12-23 2020-12-24 2020-12-25 2020-12-26 2020-12-27 2020-12-28 2020-12-29
## 1 46696 58428 24615 17246 18479 20548 58718
## 2020-12-30 2020-12-31 2021-01-01 2021-01-02 2021-01-03 2021-01-04 2021-01-05
## 1 55649 56773 24605 15827 17341 20006 56648
## 2021-01-06 2021-01-07 2021-01-08 2021-01-09 2021-01-10 2021-01-11 2021-01-12
## 1 63430 87843 52035 62290 29792 25822 64025
## 2021-01-13 2021-01-14 2021-01-15 2021-01-16 2021-01-17 2021-01-18 2021-01-19
## 1 60899 67758 69198 61567 33040 23671 62094
## 2021-01-20 2021-01-21 2021-01-22 2021-01-23 2021-01-24 2021-01-25 2021-01-26
## 1 64385 59119 56552 62334 28323 26816 61963
## 2021-01-27 2021-01-28 2021-01-29 2021-01-30 2021-01-31 2021-02-01 2021-02-02
## 1 63520 61811 59826 58462 27756 24591 54096
## 2021-02-03 2021-02-04 2021-02-05 2021-02-06 2021-02-07 2021-02-08
## 1 56002 56873 50872 0 77475 0
##
## $Growth.Rate
## geo.loc 2020-01-24 2020-01-25 2020-01-26 2020-01-27 2020-01-28 2020-01-29
## 1 BRAZIL NaN NaN NaN NaN NaN NaN
## 2020-01-30 2020-01-31 2020-02-01 2020-02-02 2020-02-03 2020-02-04 2020-02-05
## 1 NaN NaN NaN NaN NaN NaN NaN
## 2020-02-06 2020-02-07 2020-02-08 2020-02-09 2020-02-10 2020-02-11 2020-02-12
## 1 NaN NaN NaN NaN NaN NaN NaN
## 2020-02-13 2020-02-14 2020-02-15 2020-02-16 2020-02-17 2020-02-18 2020-02-19
## 1 NaN NaN NaN NaN NaN NaN NaN
## 2020-02-20 2020-02-21 2020-02-22 2020-02-23 2020-02-24 2020-02-25 2020-02-26
## 1 NaN NaN NaN NaN NaN NaN NA
## 2020-02-27 2020-02-28 2020-02-29 2020-03-01 2020-03-02 2020-03-03 2020-03-04
## 1 0 NaN NA 0 NaN NaN NA
## 2020-03-05 2020-03-06 2020-03-07 2020-03-08 2020-03-09 2020-03-10 2020-03-11
## 1 0 NA 0 NA 0.7142857 1.2 1.166667
## 2020-03-12 2020-03-13 2020-03-14 2020-03-15 2020-03-16 2020-03-17 2020-03-18
## 1 2 7.071429 0 NA 3.454545 3.184211 0.4214876
## 2020-03-19 2020-03-20 2020-03-21 2020-03-22 2020-03-23 2020-03-24 2020-03-25
## 1 4.882353 0.6907631 1.325581 2.302632 0.72 0.8544974 0.9504644
## 2020-03-26 2020-03-27 2020-03-28 2020-03-29 2020-03-30 2020-03-31 2020-04-01
## 1 1.403909 1.00232 1.127315 0.7227926 0.9176136 3.52322 0.983304
## 2020-04-02 2020-04-03 2020-04-04 2020-04-05 2020-04-06 2020-04-07 2020-04-08
## 1 1.079535 0.8377483 1.288538 0.5904908 1.338961 1.816683 1.140416
## 2020-04-09 2020-04-10 2020-04-11 2020-04-12 2020-04-13 2020-04-14 2020-04-15
## 1 0.8998127 0.8043704 0.7043984 1.345271 0.8450512 1.479806 1.669214
## 2020-04-16 2020-04-17 2020-04-18 2020-04-19 2020-04-20 2020-04-21 2020-04-22
## 1 0.6883584 1.547268 0.9137243 0.6706989 1.046593 1.118238 1.146404
## 2020-04-23 2020-04-24 2020-04-25 2020-04-26 2020-04-27 2020-04-28 2020-04-29
## 1 1.597834 0.9364337 1.317944 0.7150161 1.150953 1.332029 1.114182
## 2020-04-30 2020-05-01 2020-05-02 2020-05-03 2020-05-04 2020-05-05 2020-05-06
## 1 1.163101 0.6684884 0.97667 0.9648836 1.437579 1.006035 1.632187
## 2020-05-07 2020-05-08 2020-05-09 2020-05-10 2020-05-11 2020-05-12 2020-05-13
## 1 0.8212621 1.213818 0.8242964 0.7241191 1.038716 1.250181 1.383179
## 2020-05-14 2020-05-15 2020-05-16 2020-05-17 2020-05-18 2020-05-19 2020-05-20
## 1 1.092678 1.314553 0.7719257 0.5725416 1.8877 1.156005 1.192347
## 2020-05-21 2020-05-22 2020-05-23 2020-05-24 2020-05-25 2020-05-26 2020-05-27
## 1 0.9397786 1.124 0.7935394 0.9578992 0.7390754 1.396766 1.261884
## 2020-05-28 2020-05-29 2020-05-30 2020-05-31 2020-06-01 2020-06-02 2020-06-03
## 1 1.282441 1.019344 1.235665 0.4931478 0.7068072 2.494913 0.9895286
## 2020-06-04 2020-06-05 2020-06-06 2020-06-07 2020-06-08 2020-06-09 2020-06-10
## 1 1.080047 0.9969281 0.878203 0.6985042 0.8277284 2.050019 1.025615
## 2020-06-11 2020-06-12 2020-06-13 2020-06-14 2020-06-15 2020-06-16 2020-06-17
## 1 0.9240118 0.8543338 0.8353475 0.7883339 1.206721 1.69119 0.9218168
## 2020-06-18 2020-06-19 2020-06-20 2020-06-21 2020-06-22 2020-06-23 2020-06-24
## 1 0.7072511 2.40593 0.6329262 0.4546818 1.46739 1.705046 1.083401
## 2020-06-25 2020-06-26 2020-06-27 2020-06-28 2020-06-29 2020-06-30 2020-07-01
## 1 0.9241194 1.18684 0.8257149 0.787636 0.7892112 1.407201 1.380134
## 2020-07-02 2020-07-03 2020-07-04 2020-07-05 2020-07-06 2020-07-07 2020-07-08
## 1 1.029821 0.8777258 0.8981598 0.6869446 0.7765153 2.239607 0.9837987
## 2020-07-09 2020-07-10 2020-07-11 2020-07-12 2020-07-13 2020-07-14 2020-07-15
## 1 0.9562047 1.056993 0.8662538 0.636317 0.8169627 2.063344 0.953819
## 2020-07-16 2020-07-17 2020-07-18 2020-07-19 2020-07-20 2020-07-21 2020-07-22
## 1 1.137236 0.7527476 0.8348304 0.824653 0.8609376 2.024387 1.654799
## 2020-07-23 2020-07-24 2020-07-25 2020-07-26 2020-07-27 2020-07-28 2020-07-29
## 1 0.8835986 0.9321225 0.9151205 0.4805365 0.9473513 1.752963 1.692327
## 2020-07-30 2020-07-31 2020-08-01 2020-08-02 2020-08-03 2020-08-04 2020-08-05
## 1 0.8373194 0.9057005 0.8665407 0.5683821 0.645 3.100955 1.107533
## 2020-08-06 2020-08-07 2020-08-08 2020-08-09 2020-08-10 2020-08-11 2020-08-12
## 1 0.9297837 0.9452568 0.9948238 0.4604763 0.9581921 2.365747 1.057419
## 2020-08-13 2020-08-14 2020-08-15 2020-08-16 2020-08-17 2020-08-18 2020-08-19
## 1 1.089493 0.8427884 0.8209462 0.5556331 0.8386217 2.466526 1.031684
## 2020-08-20 2020-08-21 2020-08-22 2020-08-23 2020-08-24 2020-08-25 2020-08-26
## 1 0.9193679 0.6697483 1.648229 0.4681204 0.7291747 2.759925 1.000573
## 2020-08-27 2020-08-28 2020-08-29 2020-08-30 2020-08-31 2020-09-01 2020-09-02
## 1 0.9379572 0.9813948 0.9525016 0.3907618 2.844473 0.9281565 1.100213
## 2020-09-03 2020-09-04 2020-09-05 2020-09-06 2020-09-07 2020-09-08 2020-09-09
## 1 0.9326501 1.14598 0.6219524 0.4654316 0.7074582 1.389954 2.508299
## 2020-09-10 2020-09-11 2020-09-12 2020-09-13 2020-09-14 2020-09-15 2020-09-16
## 1 1.132371 1.07794 0.7668009 0.4405334 1.026205 2.418542 1.004556
## 2020-09-17 2020-09-18 2020-09-19 2020-09-20 2020-09-21 2020-09-22 2020-09-23
## 1 0.9859587 1.096245 0.8306405 0.49578 0.8182928 2.484826 0
## 2020-09-24 2020-09-25 2020-09-26 2020-09-27 2020-09-28 2020-09-29 2020-09-30
## 1 NA 0.4810365 0.8892858 0.5045458 0.9187736 2.436944 1.042267
## 2020-10-01 2020-10-02 2020-10-03 2020-10-04 2020-10-05 2020-10-06 2020-10-07
## 1 1.082124 0 NA 0.1415443 1.412725 3.507952 0.7529471
## 2020-10-08 2020-10-09 2020-10-10 2020-10-11 2020-10-12 2020-10-13 2020-10-14
## 1 0.8794726 0.988973 0.9746757 0.4614004 0.6829525 1.212481 2.664873
## 2020-10-15 2020-10-16 2020-10-17 2020-10-18 2020-10-19 2020-10-20 2020-10-21
## 1 1.047292 1.083827 0.7783528 0 NA 0.8809786 1.068498
## 2020-10-22 2020-10-23 2020-10-24 2020-10-25 2020-10-26 2020-10-27 2020-10-28
## 1 1.001612 1.207901 0.8985213 0.5001297 1.165493 1.894124 0.961124
## 2020-10-29 2020-10-30 2020-10-31 2020-11-01 2020-11-02 2020-11-03 2020-11-04
## 1 0.9118726 0.8535203 0.8503276 0.5330659 0.8416832 1.39313 2.024487
## 2020-11-05 2020-11-06 2020-11-07 2020-11-08 2020-11-09 2020-11-10 2020-11-11
## 1 0 NA 0.5437846 0.4715818 1.034395 2.195933 2.029575
## 2020-11-12 2020-11-13 2020-11-14 2020-11-15 2020-11-16 2020-11-17 2020-11-18
## 1 0.6971945 0.856966 1.31775 0.3689665 0.9460167 2.639593 0.9659149
## 2020-11-19 2020-11-20 2020-11-21 2020-11-22 2020-11-23 2020-11-24 2020-11-25
## 1 1.053592 1.069018 0.8495976 0.5706272 0.870642 1.918924 1.540129
## 2020-11-26 2020-11-27 2020-11-28 2020-11-29 2020-11-30 2020-12-01 2020-12-02
## 1 0.7852937 0.9073749 1.521301 0.4712453 0.8639039 2.408411 0.9794535
## 2020-12-03 2020-12-04 2020-12-05 2020-12-06 2020-12-07 2020-12-08 2020-12-09
## 1 1.011451 0.929611 0.921615 0.6101275 0.7727118 2.507879 1.046293
## 2020-12-10 2020-12-11 2020-12-12 2020-12-13 2020-12-14 2020-12-15 2020-12-16
## 1 0.9980169 1.020264 0.8065701 0.4971526 1.154318 1.702417 1.645504
## 2020-12-17 2020-12-18 2020-12-19 2020-12-20 2020-12-21 2020-12-22 2020-12-23
## 1 0.9894012 0.7524991 0.954952 0.5071048 0.983258 2.206403 0.8459114
## 2020-12-24 2020-12-25 2020-12-26 2020-12-27 2020-12-28 2020-12-29 2020-12-30
## 1 1.251242 0.4212877 0.7006297 1.071495 1.111965 2.857602 0.9477332
## 2020-12-31 2021-01-01 2021-01-02 2021-01-03 2021-01-04 2021-01-05 2021-01-06
## 1 1.020198 0.4333926 0.6432432 1.095659 1.153682 2.831551 1.119722
## 2021-01-07 2021-01-08 2021-01-09 2021-01-10 2021-01-11 2021-01-12 2021-01-13
## 1 1.384881 0.5923636 1.197079 0.478279 0.8667427 2.479475 0.9511753
## 2021-01-14 2021-01-15 2021-01-16 2021-01-17 2021-01-18 2021-01-19 2021-01-20
## 1 1.112629 1.021252 0.8897222 0.5366511 0.7164346 2.62321 1.036896
## 2021-01-21 2021-01-22 2021-01-23 2021-01-24 2021-01-25 2021-01-26 2021-01-27
## 1 0.9182108 0.9565791 1.102242 0.4543748 0.9467924 2.310673 1.025128
## 2021-01-28 2021-01-29 2021-01-30 2021-01-31 2021-02-01 2021-02-02 2021-02-03
## 1 0.9730951 0.967886 0.9772005 0.4747699 0.8859706 2.199829 1.035234
## 2021-02-04 2021-02-05 2021-02-06 2021-02-07 2021-02-08 NA
## 1 1.015553 0.8944842 0 NA 0 NA
totals.plt(tsALL)
totals.plt(tsALL, c("BRAZIL"))
## [1] "BRAZIL"
# S = Pessoas saudáveis, mas vulneráveis
# I = Infectados
# R = Recuperados
sirbr <- generate.SIR.model(ts, "BRAZIL",
tfinal = 600, # Quantidade de períodos de interesse
t1 = 2021-02-01, # Colocar a data de interesse para parar a análise
fatality.rate = 0.01,
tot.population = 209500000,
interactiveFig = T)
## ################################################################################
## ################################################################################
## [1] "BRAZIL"
## Processing... BRAZIL
## [1] 0 0 0 0 0 0 0 0 0
## [10] 0 0 0 0 0 0 0 0 0
## [19] 0 0 0 0 0 0 0 0 0
## [28] 0 0 0 0 0 0 0 0 1
## [37] 1 1 2 2 2 2 4 4 13
## [46] 13 20 25 31 38 52 151 151 162
## [55] 200 321 372 621 793 1021 1546 1924 2247
## [64] 2554 2985 3417 3904 4256 4579 5717 6836 8044
## [73] 9056 10360 11130 12161 14034 16170 18092 19638 20727
## [82] 22192 23430 25262 28320 30425 33682 36658 38654 40743
## [91] 43079 45757 50036 54043 59324 63100 67446 73235 79685
## [100] 87187 92202 97100 101826 108620 115455 126611 135773 146894
## [109] 156061 162699 169594 178214 190137 203165 220291 233511 241080
## [118] 255368 271885 291579 310087 330890 347398 363211 374898 391222
## [127] 411821 438238 465166 498440 514849 526447 555383 584016 614941
## [136] 645771 672846 691758 707412 739503 772416 802828 828810 850514
## [145] 867624 888271 923189 955377 978142 1032913 1067579 1083341 1106470
## [154] 1145906 1188631 1228114 1274974 1313667 1344143 1368195 1402041 1448753
## [163] 1496858 1539081 1577004 1603055 1623284 1668589 1713160 1755779 1800827
## [172] 1839850 1864681 1884967 1926824 1966748 2012151 2046328 2074860 2098389
## [181] 2118646 2159654 2227514 2287475 2343366 2394513 2419091 2442375 2483191
## [190] 2552265 2610102 2662485 2707877 2733677 2750318 2801921 2859073 2912212
## [199] 2962442 3012412 3035422 3057470 3109630 3164785 3224876 3275520 3317096
## [208] 3340197 3359570 3407354 3456652 3501975 3532330 3582362 3605783 3622861
## [217] 3669995 3717156 3761391 3804803 3846153 3862311 3908272 3950931 3997865
## [226] 4041638 4091801 4123000 4137521 4147794 4162073 4197889 4238446 4282164
## [235] 4315687 4330455 4345610 4382263 4419083 4455386 4495183 4528240 4544629
## [244] 4558040 4591364 4591364 4657702 4689613 4717991 4732309 4745464 4777522
## [253] 4810935 4847092 4847092 4906833 4915289 4927235 4969141 5000694 5028444
## [262] 5055888 5082637 5094979 5103408 5113628 5140863 5169386 5200300 5224362
## [271] 5224362 5250727 5273954 5298772 5323630 5353656 5380635 5394128 5409854
## [280] 5439641 5468270 5494376 5516658 5535605 5545705 5554206 5566049 5590025
## [289] 5590025 5631181 5653561 5664115 5675032 5699005 5747660 5781582 5810652
## [298] 5848959 5863093 5876464 5911758 5945849 5981767 6020164 6052786 6071401
## [307] 6087608 6118708 6166606 6204220 6238350 6290272 6314740 6335878 6386787
## [316] 6436650 6487084 6533968 6577177 6603540 6623911 6674999 6728452 6781799
## [325] 6836227 6880127 6901952 6927145 6970034 7040608 7110434 7162978 7213155
## [334] 7238600 7263619 7318821 7365517 7423945 7448560 7465806 7484285 7504833
## [343] 7563551 7619200 7675973 7700578 7716405 7733746 7753752 7810400 7873830
## [352] 7961673 8013708 8075998 8105790 8131612 8195637 8256536 8324294 8393492
## [361] 8455059 8488099 8511770 8573864 8638249 8697368 8753920 8816254 8844577
## [370] 8871393 8933356 8996876 9058687 9118513 9176975 9204731 9229322 9283418
## [379] 9339420 9396293 9447165 9447165 9524640 9524640
## [1] 50
## [1] 38 52 151 151 162 200 321 372 621
## [10] 793 1021 1546 1924 2247 2554 2985 3417 3904
## [19] 4256 4579 5717 6836 8044 9056 10360 11130 12161
## [28] 14034 16170 18092 19638 20727 22192 23430 25262 28320
## [37] 30425 33682 36658 38654 40743 43079 45757 50036 54043
## [46] 59324 63100 67446 73235 79685 87187 92202 97100 101826
## [55] 108620 115455 126611 135773 146894 156061 162699 169594 178214
## [64] 190137 203165 220291 233511 241080 255368 271885 291579 310087
## [73] 330890 347398 363211 374898 391222 411821 438238 465166 498440
## [82] 514849 526447 555383 584016 614941 645771 672846 691758 707412
## [91] 739503 772416 802828 828810 850514 867624 888271 923189 955377
## [100] 978142 1032913 1067579 1083341 1106470 1145906 1188631 1228114 1274974
## [109] 1313667 1344143 1368195 1402041 1448753 1496858 1539081 1577004 1603055
## [118] 1623284 1668589 1713160 1755779 1800827 1839850 1864681 1884967 1926824
## [127] 1966748 2012151 2046328 2074860 2098389 2118646 2159654 2227514 2287475
## [136] 2343366 2394513 2419091 2442375 2483191 2552265 2610102 2662485 2707877
## [145] 2733677 2750318 2801921 2859073 2912212 2962442 3012412 3035422 3057470
## [154] 3109630 3164785 3224876 3275520 3317096 3340197 3359570 3407354 3456652
## [163] 3501975 3532330 3582362 3605783 3622861 3669995 3717156 3761391 3804803
## [172] 3846153 3862311 3908272 3950931 3997865 4041638 4091801 4123000 4137521
## [181] 4147794 4162073 4197889 4238446 4282164 4315687 4330455 4345610 4382263
## [190] 4419083 4455386 4495183 4528240 4544629 4558040 4591364 4591364 4657702
## [199] 4689613 4717991 4732309 4745464 4777522 4810935 4847092 4847092 4906833
## [208] 4915289 4927235 4969141 5000694 5028444 5055888 5082637 5094979 5103408
## [217] 5113628 5140863 5169386 5200300 5224362 5224362 5250727 5273954 5298772
## [226] 5323630 5353656 5380635 5394128 5409854 5439641 5468270 5494376 5516658
## [235] 5535605 5545705 5554206 5566049 5590025 5590025 5631181 5653561 5664115
## [244] 5675032 5699005 5747660 5781582 5810652 5848959 5863093 5876464 5911758
## [253] 5945849 5981767 6020164 6052786 6071401 6087608 6118708 6166606 6204220
## [262] 6238350 6290272 6314740 6335878 6386787 6436650 6487084 6533968 6577177
## [271] 6603540 6623911 6674999 6728452 6781799 6836227 6880127 6901952 6927145
## [280] 6970034 7040608 7110434 7162978 7213155 7238600 7263619 7318821 7365517
## [289] 7423945 7448560 7465806 7484285 7504833 7563551 7619200 7675973 7700578
## [298] 7716405 7733746 7753752 7810400 7873830 7961673 8013708 8075998 8105790
## [307] 8131612 8195637 8256536 8324294 8393492 8455059 8488099 8511770 8573864
## [316] 8638249 8697368 8753920 8816254 8844577 8871393 8933356 8996876 9058687
## [325] 9118513 9176975 9204731 9229322 9283418 9339420 9396293 9447165 9447165
## [334] 9524640 9524640
## ------------------------ Parameters used to create model ------------------------
## Region: BRAZIL
## Time interval to consider: t0=50 - t1=2018 ; tfinal=600
## t0: 2020-03-12 -- t1: NA
## Number of days considered for initial guess: 335
## Fatality rate: 0.01
## Population of the region: 209500000
## --------------------------------------------------------------------------------
## [1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"
## beta gamma
## 0.03885245 0.00000000
## R0 = Inf
## Max nbr of infected: 209409795.63 ( 99.96 %)
## Max nbr of casualties, assuming 1% fatality rate: 2094097.96
## Max reached at day : 600 ==> 2021-11-02
## ================================================================================
library(covid19.analytics)
library(tidyverse)
library(prophet)
library(lubridate)
tsc <- covid19.data(case = "ts-confirmed") # Time-Series Covid
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## --------------------------------------------------------------------------------
tscBR <- tsc %>% filter(Country.Region == "Brazil")
tscBR <- data.frame(t(tscBR))
tscBR <- cbind(rownames(tscBR), data.frame(tscBR, row.names = NULL))
colnames(tscBR) <- c("Date", "Confirmed")
tscBR <- tscBR[-c(1:4),]
tscBR$Date <- ymd(tscBR$Date)
str(tscBR)
## 'data.frame': 384 obs. of 2 variables:
## $ Date : Date, format: "2020-01-22" "2020-01-23" ...
## $ Confirmed: chr "0" "0" "0" "0" ...
tscBR$Confirmed <- as.numeric(tscBR$Confirmed)
ds <- tscBR$Date
y <- tscBR$Confirmed
df <- data.frame(ds, y) # Criando nosso conjunto de dados no formato correto
options(scipen = 9999)
m <- prophet(df) # Fazendo a nossa previsão
future <- make_future_dataframe(m, periods = 28) # Criando uma previsão para os próximos 28 dias com base na média de crescimento
forecast <- predict(m, future)
plot(m, forecast) # Plotar a nossa previsão
dyplot.prophet(m, forecast) # Interativo
prophet_plot_components(m, forecast)
pred <- forecast$yhat[1:384]
actual <- m$history$y
plot(actual, pred)
abline(lm(pred~actual), col = "red")
summary(lm(pred~actual))
##
## Call:
## lm(formula = pred ~ actual)
##
## Residuals:
## Min 1Q Median 3Q Max
## -84720 -9482 -985 7537 145794
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 336.2589695 2123.0534223 0.158 0.874
## actual 0.9998948 0.0004827 2071.297 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 28580 on 382 degrees of freedom
## Multiple R-squared: 0.9999, Adjusted R-squared: 0.9999
## F-statistic: 4.29e+06 on 1 and 382 DF, p-value: < 0.00000000000000022
library(coronabr)
#dados2 <- get_corona_br(by_uf = T) parou de funcionar =/
#dados <- get_corona_minsaude() muito lento
dados <- read.csv("https://raw.githubusercontent.com/OxCGRT/covid-policy-tracker/master/data/OxCGRT_latest.csv")
dados <- dados %>% filter(CountryName == "Brazil")
dados$Date <- ymd(dados$Date)
dados[is.na(dados)] <- 0
names(dados)
## [1] "CountryName"
## [2] "CountryCode"
## [3] "RegionName"
## [4] "RegionCode"
## [5] "Jurisdiction"
## [6] "Date"
## [7] "C1_School.closing"
## [8] "C1_Flag"
## [9] "C2_Workplace.closing"
## [10] "C2_Flag"
## [11] "C3_Cancel.public.events"
## [12] "C3_Flag"
## [13] "C4_Restrictions.on.gatherings"
## [14] "C4_Flag"
## [15] "C5_Close.public.transport"
## [16] "C5_Flag"
## [17] "C6_Stay.at.home.requirements"
## [18] "C6_Flag"
## [19] "C7_Restrictions.on.internal.movement"
## [20] "C7_Flag"
## [21] "C8_International.travel.controls"
## [22] "E1_Income.support"
## [23] "E1_Flag"
## [24] "E2_Debt.contract.relief"
## [25] "E3_Fiscal.measures"
## [26] "E4_International.support"
## [27] "H1_Public.information.campaigns"
## [28] "H1_Flag"
## [29] "H2_Testing.policy"
## [30] "H3_Contact.tracing"
## [31] "H4_Emergency.investment.in.healthcare"
## [32] "H5_Investment.in.vaccines"
## [33] "H6_Facial.Coverings"
## [34] "H6_Flag"
## [35] "H7_Vaccination.policy"
## [36] "H7_Flag"
## [37] "M1_Wildcard"
## [38] "ConfirmedCases"
## [39] "ConfirmedDeaths"
## [40] "StringencyIndex"
## [41] "StringencyIndexForDisplay"
## [42] "StringencyLegacyIndex"
## [43] "StringencyLegacyIndexForDisplay"
## [44] "GovernmentResponseIndex"
## [45] "GovernmentResponseIndexForDisplay"
## [46] "ContainmentHealthIndex"
## [47] "ContainmentHealthIndexForDisplay"
## [48] "EconomicSupportIndex"
## [49] "EconomicSupportIndexForDisplay"
dados <- dados[,c(3,4,6,38,39)]
dados <- dados[c(1:10962),]
dados <- dados %>%
dplyr::mutate(ConfirmedDeaths = ifelse(ConfirmedDeaths == 0, NA, ConfirmedDeaths)) %>%
tidyr::fill(ConfirmedDeaths, .direction = c("up"))
dados$RegionCode <- substring(dados[,2],4,nchar(dados[,2]))
dados[is.na(dados)] <- 0
dados <- dados %>% filter(Date != max(Date)) # Remover a última data que ainda não foi analisada
linha <- dados %>% mutate(RegionCode = fct_reorder(RegionCode, -ConfirmedDeaths, first)) %>%
ggplot(aes(x = Date, y = ConfirmedDeaths, color = RegionCode)) +
geom_line()
linha <- linha + theme_bw()
linha
ggplotly(linha)
dados %>%
filter(RegionCode == "RS") %>%
ggplot(aes(Date, ConfirmedDeaths)) +
geom_line() +
geom_smooth(se = 0, col = "red")
library(tidyverse)
library(geobr)
library(sf)
library(ggspatial)
dados2 <- dados
dados2 <- dados2 %>% filter(Date == max(Date))
dados2 <- dados2 %>% arrange(RegionCode, desc = T)
dados2$RegionCode <- as.character(dados2$RegionCode)
BrasilMap <- read_state(code_state = "all", year = 2010)
##
|
| | 0%
|
|=== | 4%
|
|===== | 7%
|
|======== | 11%
|
|========== | 15%
|
|============= | 19%
|
|================ | 22%
|
|================== | 26%
|
|===================== | 30%
|
|======================= | 33%
|
|========================== | 37%
|
|============================= | 41%
|
|=============================== | 44%
|
|================================== | 48%
|
|==================================== | 52%
|
|======================================= | 56%
|
|========================================= | 59%
|
|============================================ | 63%
|
|=============================================== | 67%
|
|================================================= | 70%
|
|==================================================== | 74%
|
|====================================================== | 78%
|
|========================================================= | 81%
|
|============================================================ | 85%
|
|============================================================== | 89%
|
|================================================================= | 93%
|
|=================================================================== | 96%
|
|======================================================================| 100%
BrasilMap <- BrasilMap %>% arrange(abbrev_state, desc = T)
cbind(BrasilMap$abbrev_state, dados2$RegionCode)
## [,1] [,2]
## [1,] "AC" "AC"
## [2,] "AL" "AL"
## [3,] "AM" "AM"
## [4,] "AP" "AP"
## [5,] "BA" "BA"
## [6,] "CE" "CE"
## [7,] "DF" "DF"
## [8,] "ES" "ES"
## [9,] "GO" "GO"
## [10,] "MA" "MA"
## [11,] "MG" "MG"
## [12,] "MS" "MS"
## [13,] "MT" "MT"
## [14,] "PA" "PA"
## [15,] "PB" "PB"
## [16,] "PE" "PE"
## [17,] "PI" "PI"
## [18,] "PR" "PR"
## [19,] "RJ" "RJ"
## [20,] "RN" "RN"
## [21,] "RO" "RO"
## [22,] "RR" "RR"
## [23,] "RS" "RS"
## [24,] "SC" "SC"
## [25,] "SE" "SE"
## [26,] "SP" "SP"
## [27,] "TO" "TO"
BrasilMapDF <- cbind(BrasilMap, dados2)
BrasilMapDF <- BrasilMapDF[,c(6, 7, 8, 9, 10)]
colnames(BrasilMapDF) <- c("Nome da região", "Estado", "Data", "Confirmados", "Mortos", "geom")
BrasilMapDF <- st_as_sf(BrasilMapDF)
summary(BrasilMapDF)
## Nome da região Estado Data Confirmados
## Length:27 Length:27 Min. :2021-02-08 Min. : 50694
## Class :character Class :character 1st Qu.:2021-02-08 1st Qu.: 143367
## Mode :character Mode :character Median :2021-02-08 Median : 271542
## Mean :2021-02-08 Mean : 353633
## 3rd Qu.:2021-02-08 3rd Qu.: 462309
## Max. :2021-02-08 Max. :1851776
## Mortos geom
## Min. : 893 MULTIPOLYGON :27
## 1st Qu.: 2929 epsg:4674 : 0
## Median : 5244 +proj=long...: 0
## Mean : 8599
## 3rd Qu.:10422
## Max. :54663
BrasilMapDF$categoria_casos <- cut(BrasilMapDF$Confirmados,
breaks = c(0, 100000, 150000, 200000, 250000, 300000, 400000, 500000, 600000, Inf),
labels = c("Menos de 100000", "100000 a 150000", "150000 a 200000", "200000 a 250000",
"250000 a 300000", "300000 a 400000", "400000 a 500000", "500000 a 600000" ,"Mais de 600000"))
BrasilMapDF %>% ggplot(aes(fill = categoria_casos)) + geom_sf() +
scale_fill_manual(values = c("#ffdcdc", "#ffb4b6", "#ff8d90", "#ff6669", "#dc0005", "#b40004", "#8d0003", "#3f0001")) +
geom_sf_text(aes(label = Estado), check_overlap = T, size = 2.5, col = "white") +
annotation_scale(location = "br", height = unit(0.2, "cm")) +
annotation_north_arrow(location = "tr",
style = north_arrow_nautical,
height = unit(1.5, "cm"),
width = unit(1.5, "cm")) +
labs(title = "Covid-19 Brasil",
fill = "Casos confirmados") +
theme_bw()
BrasilMapDF$Mortos
## [1] 893 2814 9116 1083 10412 10612 4631 6012 7710 4787 15967 3024
## [13] 5244 7824 4158 10508 3131 10432 30700 3340 2369 896 11028 6557
## [25] 2834 54663 1425
BrasilMapDF$categoria_mortes <- cut(BrasilMapDF$Mortos,
breaks = c(0, 1000, 3000, 5000, 10000, 15000, 35000, Inf),
labels = c("Menos de 1000", "1000 a 3000", "3000 a 5000", "5000 a 10000",
"10000 a 15000", "15000 a 35000", "Mais de 35000"))
BrasilMapDF %>% ggplot(aes(fill = categoria_mortes)) + geom_sf() +
scale_fill_manual(values = c("#ffdcdc", "#ffb4b6", "#ff8d90", "#ff6669", "#dc0005", "#b40004", "#8d0003", "#3f0001")) +
geom_sf_text(aes(label = Estado), check_overlap = T, size = 2.5, col = "white") +
annotation_scale(location = "br", height = unit(0.2, "cm")) +
annotation_north_arrow(location = "tr",
style = north_arrow_nautical,
height = unit(1.5, "cm"),
width = unit(1.5, "cm")) +
labs(title = "Covid-19 Brasil",
fill = "Casos confirmados") +
theme_bw()
library(oxcgrt)
library(magrittr)
library(tidyverse)
library(lubridate)
# Dados Covid Mundo
x <- get_json_time(from = "2020-01-01", to = "2021-02-01")
TS <- get_data(x)
TSBR <- TS %>% filter(country_code == "BRA")
tail(TSBR)
## # A tibble: 6 x 8
## date_value country_code stringency_actu~ stringency stringency_lega~
## <date> <chr> <dbl> <dbl> <dbl>
## 1 2021-01-27 BRA NA 72.7 NA
## 2 2021-01-28 BRA NA 72.7 NA
## 3 2021-01-29 BRA NA 72.7 NA
## 4 2021-01-30 BRA NA 72.7 NA
## 5 2021-01-31 BRA NA 72.7 NA
## 6 2021-02-01 BRA NA 72.7 NA
## # ... with 3 more variables: stringency_legacy_disp <dbl>, confirmed <int>,
## # deaths <int>
br_politicas <- get_json_actions(ccode = "BR", from = NULL, to = "2021-01-20")
br_politicas_df <- as.data.frame(get_data(br_politicas))
br_politicas_lista <- get_data(json = get_json_actions(ccode = "BR",
from = NULL,
to = "2021-01-20"))
calculate_subindices(df = br_politicas_lista$policyActions)
## # A tibble: 20 x 10
## policy_type_code policy_type_dis~ policyvalue policyvalue_act~ flagged
## <chr> <chr> <int> <int> <lgl>
## 1 C1 School closing 3 3 FALSE
## 2 C2 Workplace closi~ 3 3 FALSE
## 3 C3 Cancel public e~ 2 2 FALSE
## 4 C4 Restrictions on~ 4 4 FALSE
## 5 C5 Close public tr~ 2 2 FALSE
## 6 C6 Stay at home re~ 2 2 FALSE
## 7 C7 Restrictions on~ 2 2 FALSE
## 8 C8 International t~ 1 1 NA
## 9 E1 Income support 0 0 NA
## 10 E2 Debt/contract r~ 0 0 NA
## 11 E3 Fiscal measures 0 0 NA
## 12 E4 International s~ 0 0 NA
## 13 H1 Public informat~ 2 2 TRUE
## 14 H2 Testing policy 1 1 NA
## 15 H3 Contact tracing 2 2 NA
## 16 H4 Emergency inves~ 0 0 NA
## 17 H5 Investment in v~ 0 0 NA
## 18 H6 Facial Coverings 4 4 TRUE
## 19 H7 Vaccination pol~ 3 3 TRUE
## 20 H8 Protection of e~ 1 1 TRUE
## # ... with 5 more variables: is_general <lgl>, notes <chr>,
## # flag_value_display_field <chr>, policy_value_display_field <chr>,
## # score <dbl>
CS <- calculate_subindices(df = br_politicas_lista$policyActions)
calculate_gov_response(df = CS)
## [1] 63.39286
calculate_containment_health(df = CS)
## [1] 73.95833
calculate_stringency(df = CS)
## [1] 72.68519
calculate_economic_support(df = CS)
## [1] 0
calculate_indices(df = CS)
## # A tibble: 4 x 2
## index values
## <chr> <dbl>
## 1 Government Response Index 63.4
## 2 Containment and Health Index 74.0
## 3 Stringency Index 72.7
## 4 Economic Support Index 0
TSBR <- TS %>% filter(country_code == "BRA")
TSBR <- as.data.frame(TSBR)
TSBR$date_value <- ymd(TSBR$date_value)
TSBR[is.na(TSBR)] <- 0
TSBR2 <- mutate(TSBR, novos_casos = as.numeric(confirmed - lag(confirmed)))
TSBR2[is.na(TSBR2)] <- 0
scaleFactor <- max(TSBR2$novos_casos) / max(TSBR2$stringency)
ggplot(TSBR2, aes(x=TSBR2$date_value)) +
geom_line(aes(y = TSBR2$novos_casos/scaleFactor), col = "red", lwd = 1) +
geom_line(aes(y = TSBR2$stringency), col = "blue", lwd = 1) +
labs(title = "Casos X Políticas Brasil", y = "Novos Casos", x = "Tempo") +
scale_y_continuous(name="Stringency",
sec.axis=sec_axis(~.*scaleFactor, name="Novos Casos")) +
theme_bw(base_size = 10) +
theme(text = element_text(family= "Times New Roman", face="bold"),
plot.title = element_text(hjust = 0.5),
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red"))
TSBR <- TS %>% filter(country_code == "BRA")
TSBR <- as.data.frame(TSBR)
TSBR$date_value <- ymd(TSBR$date_value)
TSBR[is.na(TSBR)] <- 0
TSBR2 <- mutate(TSBR, novas_mortes = as.numeric(deaths - lag(deaths)))
TSBR2[is.na(TSBR2)] <- 0
plot(TSBR2$novas_mortes)
summary(TSBR2$novas_mortes)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 78 555 567 956 2497
scaleFactor <- max(TSBR2$novas_mortes) / max(TSBR2$stringency)
plotly <- ggplot(TSBR2, aes(x=TSBR2$date_value)) +
geom_line(aes(y = TSBR2$novas_mortes/scaleFactor), col = "red", lwd = 1) +
geom_line(aes(y = TSBR2$stringency), col = "blue", lwd = 1) +
labs(title = "Casos X Políticas", y = "Novos Casos", x = "Tempo") +
scale_y_continuous(name="Stringency",
sec.axis=sec_axis(~.*scaleFactor, name="Novos Casos")) +
theme_bw(base_size = 10) +
theme(text = element_text(family= "Times New Roman", face="bold"),
plot.title = element_text(hjust = 0.5),
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red"))
library(plotly)
ggplotly(plotly)
summary(lm(novas_mortes ~ stringency, data = TSBR2))
##
## Call:
## lm(formula = novas_mortes ~ stringency, data = TSBR2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -730.22 -243.70 9.47 229.48 1772.02
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -70.2967 43.9623 -1.599 0.111
## stringency 10.9406 0.6869 15.927 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 362.8 on 395 degrees of freedom
## Multiple R-squared: 0.3911, Adjusted R-squared: 0.3895
## F-statistic: 253.7 on 1 and 395 DF, p-value: < 0.00000000000000022
TSUSA <- TS %>% filter(country_code == "USA")
TSUSA <- as.data.frame(TSUSA)
TSUSA$date_value <- ymd(TSUSA$date_value)
TSUSA[is.na(TSUSA)] <- 0
TSUSA2 <- mutate(TSUSA, novos_casos = as.numeric(confirmed - lag(confirmed)))
TSUSA2[is.na(TSUSA2)] <- 0
scaleFactor <- max(TSUSA2$novos_casos) / max(TSUSA2$stringency)
options(scipen=10000)
ggplot(TSUSA2, aes(x=TSUSA2$date_value)) +
geom_line(aes(y = TSUSA2$novos_casos/scaleFactor), col = "red", lwd = 1) +
geom_line(aes(y = TSUSA2$stringency), col = "blue", lwd = 1) +
labs(title = "Casos X Políticas", y = "Novos Casos", x = "Tempo") +
scale_y_continuous(name="Stringency",
sec.axis=sec_axis(~.*scaleFactor, name="Novos Casos")) +
theme_bw(base_size = 10) +
theme(text = element_text(family= "Times New Roman", face="bold"),
plot.title = element_text(hjust = 0.5),
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red"))
TSCAN <- TS %>% filter(country_code == "FRA")
TSCAN <- as.data.frame(TSCAN)
TSCAN$date_value <- ymd(TSCAN$date_value)
TSCAN[is.na(TSCAN)] <- 0
TSCAN2 <- mutate(TSCAN, novos_casos = as.numeric(confirmed - lag(confirmed)))
TSCAN2[is.na(TSCAN2)] <- 0
scaleFactor <- max(TSCAN2$novos_casos) / max(TSCAN2$stringency)
ggplot(TSCAN2, aes(x=TSCAN2$date_value)) +
geom_line(aes(y = TSCAN2$novos_casos/scaleFactor), col = "red", lwd = 1) +
geom_line(aes(y = TSCAN2$stringency), col = "blue", lwd = 1) +
labs(title = "Casos X Políticas CANDA", y = "Novos Casos", x = "Tempo") +
scale_y_continuous(name="Stringency",
sec.axis=sec_axis(~.*scaleFactor, name="Novos Casos")) +
theme_bw(base_size = 10) +
theme(text = element_text(family= "Times New Roman", face="bold"),
plot.title = element_text(hjust = 0.5),
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red"))
estados <- read.csv("https://raw.githubusercontent.com/OxCGRT/covid-policy-tracker/master/data/OxCGRT_latest.csv")
estados2 <- estados %>% filter(CountryName == "Brazil")
estados2$Date <- ymd(estados2$Date)
estados2[is.na(estados2)] <- 0
names(estados2)
## [1] "CountryName"
## [2] "CountryCode"
## [3] "RegionName"
## [4] "RegionCode"
## [5] "Jurisdiction"
## [6] "Date"
## [7] "C1_School.closing"
## [8] "C1_Flag"
## [9] "C2_Workplace.closing"
## [10] "C2_Flag"
## [11] "C3_Cancel.public.events"
## [12] "C3_Flag"
## [13] "C4_Restrictions.on.gatherings"
## [14] "C4_Flag"
## [15] "C5_Close.public.transport"
## [16] "C5_Flag"
## [17] "C6_Stay.at.home.requirements"
## [18] "C6_Flag"
## [19] "C7_Restrictions.on.internal.movement"
## [20] "C7_Flag"
## [21] "C8_International.travel.controls"
## [22] "E1_Income.support"
## [23] "E1_Flag"
## [24] "E2_Debt.contract.relief"
## [25] "E3_Fiscal.measures"
## [26] "E4_International.support"
## [27] "H1_Public.information.campaigns"
## [28] "H1_Flag"
## [29] "H2_Testing.policy"
## [30] "H3_Contact.tracing"
## [31] "H4_Emergency.investment.in.healthcare"
## [32] "H5_Investment.in.vaccines"
## [33] "H6_Facial.Coverings"
## [34] "H6_Flag"
## [35] "H7_Vaccination.policy"
## [36] "H7_Flag"
## [37] "M1_Wildcard"
## [38] "ConfirmedCases"
## [39] "ConfirmedDeaths"
## [40] "StringencyIndex"
## [41] "StringencyIndexForDisplay"
## [42] "StringencyLegacyIndex"
## [43] "StringencyLegacyIndexForDisplay"
## [44] "GovernmentResponseIndex"
## [45] "GovernmentResponseIndexForDisplay"
## [46] "ContainmentHealthIndex"
## [47] "ContainmentHealthIndexForDisplay"
## [48] "EconomicSupportIndex"
## [49] "EconomicSupportIndexForDisplay"
RS <- estados2 %>% filter(RegionName == "Rio Grande do Sul")
RS <- RS[c(1:369),]
RS2 <- RS[,c(1,2,3,6,38,39,40)]
RS3 <- RS2 %>%
dplyr::mutate(ConfirmedDeaths = ifelse(ConfirmedDeaths == 0, NA, ConfirmedDeaths)) %>%
tidyr::fill(ConfirmedDeaths, .direction = c("down"))
RS3$ConfirmedDeaths
## [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [16] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [31] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [46] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [61] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [76] NA NA NA NA NA NA NA NA NA 1 1 1 2 2 3
## [91] 4 4 5 5 6 7 7 8 9 12 14 15 16 16 18
## [106] 19 19 22 24 24 27 27 27 29 31 34 35 42 45 50
## [121] 51 58 62 65 74 79 87 90 91 95 97 97 97 97 97
## [136] 120 132 142 144 151 161 176 172 180 180 197 197 209 213 213
## [151] 218 218 232 232 245 258 265 265 265 265 301 316 323 337 344
## [166] 350 360 374 387 406 423 430 434 458 477 477 500 540 554 559
## [181] 582 614 636 663 690 715 727 759 791 825 870 919 943 962 995
## [196] 1060 1101 1141 1166 1229 1252 1285 1349 1397 1397 1494 1554 1571 1611 1680
## [211] 1680 1825 1876 1947 1947 2016 2099 2163 2231 2282 2346 2360 2417 2472 2540
## [226] 2584 2631 2647 2689 2744 2822 2881 2948 2993 3046 3062 3102 3161 3235 3275
## [241] 3323 3385 3395 3435 3501 3543 3590 3650 3714 3739 3756 3800 3882 3929 3997
## [256] 4039 4055 4080 4174 4216 4268 4318 4371 4384 4409 4472 4515 4544 4544 4615
## [271] 4627 4648 4648 4782 4782 4852 4898 4908 4952 4989 5035 5068 5100 5135 5141
## [286] 5148 5167 5237 5282 5312 5342 5346 5388 5452 5452 5482 5554 5581 5581 5615
## [301] 5665 5699 5699 5729 5797 5804 5805 5844 5903 5903 5903 5903 5903 5903 5903
## [316] 5903 5903 6125 6215 6215 6219 6314 6356 6410 6447 6447 6494 6494 6524 6639
## [331] 6686 6686 6768 6776 6813 6900 6973 7043 7104 7166 7183 7235 7316 7388 7452
## [346] 7452 7452 7587 7681 7766 7862 7944 8007 8072 8087 8159 8260 8345 8403 8434
## [361] 8452 8492 8536 8680 8680 8872 8917 8934 8954
RS3[is.na(RS3)] <- 0
RS3$ConfirmedDeaths
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [16] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [31] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [46] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [61] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [76] 0 0 0 0 0 0 0 0 0 1 1 1 2 2 3
## [91] 4 4 5 5 6 7 7 8 9 12 14 15 16 16 18
## [106] 19 19 22 24 24 27 27 27 29 31 34 35 42 45 50
## [121] 51 58 62 65 74 79 87 90 91 95 97 97 97 97 97
## [136] 120 132 142 144 151 161 176 172 180 180 197 197 209 213 213
## [151] 218 218 232 232 245 258 265 265 265 265 301 316 323 337 344
## [166] 350 360 374 387 406 423 430 434 458 477 477 500 540 554 559
## [181] 582 614 636 663 690 715 727 759 791 825 870 919 943 962 995
## [196] 1060 1101 1141 1166 1229 1252 1285 1349 1397 1397 1494 1554 1571 1611 1680
## [211] 1680 1825 1876 1947 1947 2016 2099 2163 2231 2282 2346 2360 2417 2472 2540
## [226] 2584 2631 2647 2689 2744 2822 2881 2948 2993 3046 3062 3102 3161 3235 3275
## [241] 3323 3385 3395 3435 3501 3543 3590 3650 3714 3739 3756 3800 3882 3929 3997
## [256] 4039 4055 4080 4174 4216 4268 4318 4371 4384 4409 4472 4515 4544 4544 4615
## [271] 4627 4648 4648 4782 4782 4852 4898 4908 4952 4989 5035 5068 5100 5135 5141
## [286] 5148 5167 5237 5282 5312 5342 5346 5388 5452 5452 5482 5554 5581 5581 5615
## [301] 5665 5699 5699 5729 5797 5804 5805 5844 5903 5903 5903 5903 5903 5903 5903
## [316] 5903 5903 6125 6215 6215 6219 6314 6356 6410 6447 6447 6494 6494 6524 6639
## [331] 6686 6686 6768 6776 6813 6900 6973 7043 7104 7166 7183 7235 7316 7388 7452
## [346] 7452 7452 7587 7681 7766 7862 7944 8007 8072 8087 8159 8260 8345 8403 8434
## [361] 8452 8492 8536 8680 8680 8872 8917 8934 8954
RS3 <- mutate(RS3, novas_mortes = as.numeric(ConfirmedDeaths - lag(ConfirmedDeaths)))
RS3$novas_mortes
## [1] NA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [19] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [37] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [55] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [73] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1
## [91] 1 0 1 0 1 1 0 1 1 3 2 1 1 0 2 1 0 3
## [109] 2 0 3 0 0 2 2 3 1 7 3 5 1 7 4 3 9 5
## [127] 8 3 1 4 2 0 0 0 0 23 12 10 2 7 10 15 -4 8
## [145] 0 17 0 12 4 0 5 0 14 0 13 13 7 0 0 0 36 15
## [163] 7 14 7 6 10 14 13 19 17 7 4 24 19 0 23 40 14 5
## [181] 23 32 22 27 27 25 12 32 32 34 45 49 24 19 33 65 41 40
## [199] 25 63 23 33 64 48 0 97 60 17 40 69 0 145 51 71 0 69
## [217] 83 64 68 51 64 14 57 55 68 44 47 16 42 55 78 59 67 45
## [235] 53 16 40 59 74 40 48 62 10 40 66 42 47 60 64 25 17 44
## [253] 82 47 68 42 16 25 94 42 52 50 53 13 25 63 43 29 0 71
## [271] 12 21 0 134 0 70 46 10 44 37 46 33 32 35 6 7 19 70
## [289] 45 30 30 4 42 64 0 30 72 27 0 34 50 34 0 30 68 7
## [307] 1 39 59 0 0 0 0 0 0 0 0 222 90 0 4 95 42 54
## [325] 37 0 47 0 30 115 47 0 82 8 37 87 73 70 61 62 17 52
## [343] 81 72 64 0 0 135 94 85 96 82 63 65 15 72 101 85 58 31
## [361] 18 40 44 144 0 192 45 17 20
plot(RS3$novas_mortes)
RS3[is.na(RS3)] <- 0
scaleFactor <- max(RS3$novas_mortes, na.rm=T) / max(RS3$StringencyIndex)
RS3 %>% arrange(novas_mortes, desc = F) %>% tail(10)
## CountryName CountryCode RegionName Date ConfirmedCases
## 360 Brazil BRA Rio Grande do Sul 2020-12-16 388704
## 361 Brazil BRA Rio Grande do Sul 2020-07-24 57007
## 362 Brazil BRA Rio Grande do Sul 2020-12-22 416000
## 363 Brazil BRA Rio Grande do Sul 2020-11-25 306335
## 364 Brazil BRA Rio Grande do Sul 2020-09-30 190572
## 365 Brazil BRA Rio Grande do Sul 2020-12-13 376590
## 366 Brazil BRA Rio Grande do Sul 2020-12-29 438458
## 367 Brazil BRA Rio Grande do Sul 2020-07-30 66473
## 368 Brazil BRA Rio Grande do Sul 2020-12-31 449674
## 369 Brazil BRA Rio Grande do Sul 2020-11-13 271340
## ConfirmedDeaths StringencyIndex novas_mortes
## 360 7862 65.74 96
## 361 1494 79.63 97
## 362 8260 65.74 101
## 363 6639 62.96 115
## 364 4782 66.67 134
## 365 7587 65.74 135
## 366 8680 62.96 144
## 367 1825 71.30 145
## 368 8872 62.96 192
## 369 6125 62.96 222
ggplot(RS3, aes(x=RS3$Date)) +
geom_line(aes(y = RS3$novas_mortes/scaleFactor), col = "red", lwd = 1) +
geom_line(aes(y = RS3$StringencyIndex), col = "blue", lwd = 1) +
labs(title = "Casos X Políticas Rio Grande do Sul", y = "Novos Casos", x = "Tempo") +
scale_y_continuous(name="Stringency",
sec.axis=sec_axis(~.*scaleFactor, name="Novas Mortes")) +
theme_bw(base_size = 10) +
theme(text = element_text(family= "Times New Roman", face="bold"),
plot.title = element_text(hjust = 0.5),
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red"))
library(geobr)
library(sf)
library(gganimate)
library(gifski)
library(av)
library(gapminder)
library(ggthemes)
library(RColorBrewer)
library(gapminder)
library(gstat)
library(fields)
library(ggspatial)
rsmap <- read_state(code_state = "RS", year = 2010, showProgress = F)
plot(rsmap)
RS4 <- RS3
geom <- rep(rsmap[,6], 369)
geom <- as.data.frame(geom)
geom <- t(geom)
RS5 <- cbind(RS4, geom)
RS5 <- st_as_sf(RS5)
str(RS5)
## Classes 'sf' and 'data.frame': 369 obs. of 9 variables:
## $ CountryName : chr "Brazil" "Brazil" "Brazil" "Brazil" ...
## $ CountryCode : chr "BRA" "BRA" "BRA" "BRA" ...
## $ RegionName : chr "Rio Grande do Sul" "Rio Grande do Sul" "Rio Grande do Sul" "Rio Grande do Sul" ...
## $ Date : Date, format: "2020-01-01" "2020-01-02" ...
## $ ConfirmedCases : num 0 0 0 0 0 0 0 0 0 0 ...
## $ ConfirmedDeaths: num 0 0 0 0 0 0 0 0 0 0 ...
## $ StringencyIndex: num 0 0 0 0 0 0 0 0 0 0 ...
## $ novas_mortes : num 0 0 0 0 0 0 0 0 0 0 ...
## $ 1 :sfc_MULTIPOLYGON of length 369; first list element: List of 1
## ..$ :List of 2
## .. ..$ : num [1:5636, 1:2] -51.9 -51.9 -51.9 -51.9 -51.9 ...
## .. ..$ : num [1:4, 1:2] -51.9 -51.9 -51.9 -51.9 -27.5 ...
## ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
## - attr(*, "sf_column")= chr "1"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA
## ..- attr(*, "names")= chr [1:8] "CountryName" "CountryCode" "RegionName" "Date" ...
mapa <- RS5 %>% ggplot() +
geom_sf(aes(fill = StringencyIndex)) +
scale_fill_gradient(low = "lightblue", high = "Blue") +
annotation_north_arrow(location = "tr",
style = north_arrow_nautical,
height = unit(1.5, "cm"),
width = unit(1.5, "cm")) +
theme_bw() +
theme(text=element_text(family= "Times New Roman",
face="bold"), plot.title = element_text(hjust = 0.5)) +
labs(title = "Políticas de enfrentamento a pandemia no RS",
x = "Longitude",
y = "Latitude") +
guides(fill = guide_legend(title = "Política Pública", reverse=T))
mapa
animação <- mapa + geom_text(data= RS5, aes(y=-26, x=-56, label=as.character(Date)),
check_overlap = TRUE,
size=5,
fontface="bold") + transition_manual(Date)
animação # Markedown não reproduz animação
AM <- estados2 %>% filter(RegionName == "Amazonas")
AM <- AM[c(1:369),]
AM <- AM[,c(1,2,3,6,38,39,40)]
AM <- AM %>%
dplyr::mutate(ConfirmedDeaths = ifelse(ConfirmedDeaths == 0, NA, ConfirmedDeaths)) %>%
tidyr::fill(ConfirmedDeaths, .direction = c("down"))
AM$ConfirmedDeaths
## [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [16] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [31] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [46] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [61] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [76] NA NA NA NA NA NA NA NA NA 1 1 1 1 1 1
## [91] 3 3 3 7 12 14 19 23 30 40 50 53 62 62 90
## [106] 106 124 145 161 182 185 193 207 234 255 287 304 320 351 380
## [121] 425 476 501 548 584 649 751 806 874 962 1004 1004 1004 1004 1004
## [136] 1235 1375 1413 1433 1491 1561 1744 1669 1758 1758 1781 1781 1891 1964 2011
## [151] 2047 2047 2071 2071 2102 2138 2183 2183 2183 2183 2315 2363 2400 2429 2465
## [166] 2492 2512 2549 2579 2605 2624 2650 2657 2671 2686 2686 2731 2739 2772 2780
## [181] 2792 2823 2843 2862 2887 2918 2929 2938 2952 2967 2985 3008 3023 3039 3048
## [196] 3063 3080 3095 3118 3129 3149 3146 3169 3183 3183 3199 3210 3217 3224 3236
## [211] 3236 3252 3268 3278 3278 3288 3299 3317 3335 3345 3364 3359 3384 3405 3417
## [226] 3435 3455 3463 3483 3505 3524 3537 3551 3556 3557 3563 3578 3588 3600 3616
## [241] 3629 3634 3639 3649 3661 3798 3828 3841 3841 3847 3849 3855 3862 3874 3883
## [256] 3888 3892 3898 3907 3920 3931 3950 3956 3959 3964 3967 3984 3992 3992 4022
## [271] 4027 4031 4031 4156 4156 4162 4169 4176 4185 4193 4202 4215 4222 4235 4239
## [286] 4247 4254 4268 4289 4305 4325 4332 4350 4363 4363 4372 4426 4433 4446 4460
## [301] 4478 4491 4491 4516 4543 4555 4565 4573 4588 4588 4588 4588 4588 4588 4588
## [316] 4588 4588 4655 4693 4693 4697 4723 4728 4741 4761 4761 4779 4779 4797 4826
## [331] 4856 4856 4876 4885 4894 4896 4912 4932 4936 4946 4951 4964 4969 4973 4978
## [346] 4978 4978 5001 5011 5026 5036 5049 5062 5076 5085 5094 5111 5133 5151 5161
## [361] 5173 5190 5206 5232 5232 5285 5295 5325 5345
AM[is.na(AM)] <- 0
AM$ConfirmedDeaths
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [16] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [31] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [46] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [61] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [76] 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1
## [91] 3 3 3 7 12 14 19 23 30 40 50 53 62 62 90
## [106] 106 124 145 161 182 185 193 207 234 255 287 304 320 351 380
## [121] 425 476 501 548 584 649 751 806 874 962 1004 1004 1004 1004 1004
## [136] 1235 1375 1413 1433 1491 1561 1744 1669 1758 1758 1781 1781 1891 1964 2011
## [151] 2047 2047 2071 2071 2102 2138 2183 2183 2183 2183 2315 2363 2400 2429 2465
## [166] 2492 2512 2549 2579 2605 2624 2650 2657 2671 2686 2686 2731 2739 2772 2780
## [181] 2792 2823 2843 2862 2887 2918 2929 2938 2952 2967 2985 3008 3023 3039 3048
## [196] 3063 3080 3095 3118 3129 3149 3146 3169 3183 3183 3199 3210 3217 3224 3236
## [211] 3236 3252 3268 3278 3278 3288 3299 3317 3335 3345 3364 3359 3384 3405 3417
## [226] 3435 3455 3463 3483 3505 3524 3537 3551 3556 3557 3563 3578 3588 3600 3616
## [241] 3629 3634 3639 3649 3661 3798 3828 3841 3841 3847 3849 3855 3862 3874 3883
## [256] 3888 3892 3898 3907 3920 3931 3950 3956 3959 3964 3967 3984 3992 3992 4022
## [271] 4027 4031 4031 4156 4156 4162 4169 4176 4185 4193 4202 4215 4222 4235 4239
## [286] 4247 4254 4268 4289 4305 4325 4332 4350 4363 4363 4372 4426 4433 4446 4460
## [301] 4478 4491 4491 4516 4543 4555 4565 4573 4588 4588 4588 4588 4588 4588 4588
## [316] 4588 4588 4655 4693 4693 4697 4723 4728 4741 4761 4761 4779 4779 4797 4826
## [331] 4856 4856 4876 4885 4894 4896 4912 4932 4936 4946 4951 4964 4969 4973 4978
## [346] 4978 4978 5001 5011 5026 5036 5049 5062 5076 5085 5094 5111 5133 5151 5161
## [361] 5173 5190 5206 5232 5232 5285 5295 5325 5345
AM <- mutate(AM, novas_mortes = as.numeric(ConfirmedDeaths - lag(ConfirmedDeaths)))
AM$novas_mortes
## [1] NA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [19] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [37] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [55] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [73] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
## [91] 2 0 0 4 5 2 5 4 7 10 10 3 9 0 28 16 18 21
## [109] 16 21 3 8 14 27 21 32 17 16 31 29 45 51 25 47 36 65
## [127] 102 55 68 88 42 0 0 0 0 231 140 38 20 58 70 183 -75 89
## [145] 0 23 0 110 73 47 36 0 24 0 31 36 45 0 0 0 132 48
## [163] 37 29 36 27 20 37 30 26 19 26 7 14 15 0 45 8 33 8
## [181] 12 31 20 19 25 31 11 9 14 15 18 23 15 16 9 15 17 15
## [199] 23 11 20 -3 23 14 0 16 11 7 7 12 0 16 16 10 0 10
## [217] 11 18 18 10 19 -5 25 21 12 18 20 8 20 22 19 13 14 5
## [235] 1 6 15 10 12 16 13 5 5 10 12 137 30 13 0 6 2 6
## [253] 7 12 9 5 4 6 9 13 11 19 6 3 5 3 17 8 0 30
## [271] 5 4 0 125 0 6 7 7 9 8 9 13 7 13 4 8 7 14
## [289] 21 16 20 7 18 13 0 9 54 7 13 14 18 13 0 25 27 12
## [307] 10 8 15 0 0 0 0 0 0 0 0 67 38 0 4 26 5 13
## [325] 20 0 18 0 18 29 30 0 20 9 9 2 16 20 4 10 5 13
## [343] 5 4 5 0 0 23 10 15 10 13 13 14 9 9 17 22 18 10
## [361] 12 17 16 26 0 53 10 30 20
plot(AM$novas_mortes)
AM[is.na(AM)] <- 0
scaleFactor <- max(AM$novas_mortes, na.rm=T) / max(AM$StringencyIndex)
AM %>% arrange(novas_mortes, desc = F) %>% tail(10)
## CountryName CountryCode RegionName Date ConfirmedCases
## 360 Brazil BRA Amazonas 2020-05-09 11925
## 361 Brazil BRA Amazonas 2020-05-23 29867
## 362 Brazil BRA Amazonas 2020-05-06 9243
## 363 Brazil BRA Amazonas 2020-05-27 33508
## 364 Brazil BRA Amazonas 2020-09-30 139326
## 365 Brazil BRA Amazonas 2020-06-09 51234
## 366 Brazil BRA Amazonas 2020-09-02 121793
## 367 Brazil BRA Amazonas 2020-05-16 19677
## 368 Brazil BRA Amazonas 2020-05-21 28802
## 369 Brazil BRA Amazonas 2020-05-15 17181
## ConfirmedDeaths StringencyIndex novas_mortes
## 360 962 81.02 88
## 361 1758 82.41 89
## 362 751 81.02 102
## 363 1891 79.63 110
## 364 4156 66.20 125
## 365 2315 76.39 132
## 366 3798 65.28 137
## 367 1375 82.41 140
## 368 1744 82.41 183
## 369 1235 82.41 231
ggplot(AM, aes(x=AM$Date)) +
geom_line(aes(y = AM$novas_mortes/scaleFactor), col = "red", lwd = 1) +
geom_line(aes(y = AM$StringencyIndex), col = "blue", lwd = 1) +
labs(title = "Casos X Políticas", y = "Novos Casos", x = "Tempo") +
scale_y_continuous(name="Stringency",
sec.axis=sec_axis(~.*scaleFactor, name="Novas Mortes")) +
theme_bw(base_size = 10) +
theme(text = element_text(family= "Times New Roman", face="bold"),
plot.title = element_text(hjust = 0.5),
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red"))
br <- estados2[,c(1,2,3,6,38,39,40)]
br2 <- br %>% filter(Date == "2020-12-01") # data escolhida aleatoriamente
br2 <- br2[-28,]
brmap <- read_state(code_state = "all", year = 2010, showProgress = F)
plot(brmap)
br2 <- br2 %>% arrange(RegionName, desc = T)
brmap2 <- brmap %>% arrange(name_state, desc = T)
br3 <- cbind(br2, brmap2)
br3 <- st_as_sf(br3)
br3$Categoria <- cut(br3$StringencyIndex, breaks = c(0, 30 , 40 ,50, 60, 70, 80, 90, 100),
labels = c("0 a 30", "30 a 40 ", "40 a 50", "50 a 60", "60 a 70",
"70 a 80", "80 a 90", "90 a 100"))
br3 %>% ggplot() +
geom_sf(aes(fill = StringencyIndex)) +
scale_fill_gradient2(low = "red", high = "darkblue", midpoint = 60) +
geom_sf_text(aes(label = abbrev_state), check_overlap = T, size = 2.5) +
annotation_scale(location = "br", height = unit(0.2, "cm")) +
annotation_north_arrow(location = "tr",
style = north_arrow_nautical,
height = unit(1.5, "cm"),
width = unit(1.5, "cm")) +
labs(title = "Políticas Públicas",
fill = "Índice de Políticas",
x = "", y = "") +
theme_bw()