---
title: "Avoiding_thousands_of_deaths"
author: "Duncan Golicher"
date: "10/04/2021"
output: html_document
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(mgcv)
```


```{r, message=FALSE}
library(COVID19)
wb <- c("gdp" = "NY.GDP.MKTP.CD", "hosp_beds" = "SH.MED.BEDS.ZS", 
        "Over65" = "SP.POP.65UP.TO.ZS", 
        "deaths_cd" = "SH.DTH.COMM.ZS",
        "mortality" ="SP.DYN.AMRT.MA",
        "Infant_deaths"="SH.DTH.IMRT",
        "Under_5_deaths" = "SH.DTH.MORT",
        "Suicide" = "SH.STA.SUIC.P5"
        )
gmr <- "https://www.gstatic.com/covid19/mobility/Global_Mobility_Report.csv"
d  <- covid19(wb = wb)
d %>% filter(date< Sys.Date()-7) -> d
d %>% group_by(iso_alpha_3) -> d
d %>%arrange(date) %>% mutate(New_cases = confirmed - lag(confirmed, default = first(confirmed))) -> d
d %>% mutate(New_deaths = deaths - lag(deaths, default = first(deaths))) %>% arrange(deaths) -> d
d %>% mutate(New_tests = tests - lag(tests, default = first(tests))) %>% arrange(tests) -> d
```

```{r}

d %>% filter(administrative_area_level_1 =="United Kingdom") %>% filter(date > Sys.Date() -100)-> UK

UK %>% summarise(cases=sum(New_cases),deaths= sum(New_deaths)) %>% mutate(deaths/cases)
```

