Example 1: Analyse intervention and mobility data

# library(covidPeru); library(readr)
library(covid19viz)
# library(cdcper)
library(tidyverse)
library(lubridate)
theme_set(theme_bw())


# analysis time limits --------------------------------------------------------------

min_analysis_date <- ymd(20200301)
max_analysis_date <- Sys.Date()

# covid19viz R package ----------------------------------------------------

# _import intervention data ------------------------------------------------

unesco <- read_unesco_education()
# acaps <- read_acaps_governments()

# no data in ACAPS
# acaps %>% filter(ISO3=="PER")

unesco_peru <- unesco %>% 
  filter(ISO=="PER") %>% 
  mutate(Date=dmy(Date)) %>% 
  group_by(Status) %>% 
  summarise(date_min=min(Date),
            date_max=max(Date)) %>% 
  rename(intervention_label=Status) %>% 
  mutate(intervention=case_when(
    intervention_label=="Closed due to COVID-19" ~ "closed",
    intervention_label=="Partially open" ~ "partial"
  ))
# unesco_peru

# _unite intervention data -------------------------------------------------

interventions <- tibble(
  date_min = ymd(20200628), 
  date_max = ymd(20200709),
  intervention_label = "Seroprevalence study",
  intervention = "seroprev"
) %>% 
  union_all(
    unesco_peru %>% 
      mutate(date_max=if_else(date_max==max(date_max),
                              max_analysis_date,
                              date_max))
  )
interventions
#> # A tibble: 3 x 4
#>   date_min   date_max   intervention_label     intervention
#>   <date>     <date>     <chr>                  <chr>       
#> 1 2020-06-28 2020-07-09 Seroprevalence study   seroprev    
#> 2 2020-03-16 2020-06-30 Closed due to COVID-19 closed      
#> 3 2020-07-01 2020-09-20 Partially open         partial

# interventions %>% 
#   writexl::write_xlsx("table/02-seroprev-supp-table05.xlsx")

Example 2: Compare event rates among countries

Collect data

library(covid19viz)
name source sum_data pop_est lastcensus rate
United States active 3988265 313973000 2010 12702.57315
United Kingdom active 348770 62262000 2011 5601.65109
Peru active 130616 29546963 2007 4420.62353
Brazil active 454815 198739269 2010 2288.50092
Russia active 170100 140041247 2010 1214.64214
India active 1010824 1166079220 2011 866.85706
Peru confirmed 756412 29546963 2007 25600.32989
Brazil confirmed 4528240 198739269 2010 22784.82769
United States confirmed 6764970 313973000 2010 21546.34316
Russia confirmed 1092915 140041247 2010 7804.23642
United Kingdom confirmed 392845 62262000 2011 6309.54675
India confirmed 5400619 1166079220 2011 4631.43405
Peru deaths 31283 29546963 2007 1058.75518
Brazil deaths 136532 198739269 2010 686.99055
United Kingdom deaths 41848 62262000 2011 672.12746
United States deaths 199259 313973000 2010 634.63737
Russia deaths 19270 140041247 2010 137.60232
India deaths 86752 1166079220 2011 74.39632
Peru recovered 594513 29546963 2007 20120.95118
Brazil recovered 3936893 198739269 2010 19809.33622
United States recovered 2577446 313973000 2010 8209.13263
Russia recovered 903545 140041247 2010 6451.99196
India recovered 4303043 1166079220 2011 3690.18067
United Kingdom recovered 2227 62262000 2011 35.76821