dates and lubridate

A couple of simple exercises to reprise the lubridate toolkit. We’ll also be using our familiar tidy tools–specifically, dplyr and purrr.

First–excess mortality is a concept public health uses to measure the net effect of a pandemic/war some exogenous shock to mortality data, after adjusting for the regular pattern of deaths observed for some geographic unit.

We’ll load some data

library(tidyverse)
library(magrittr)
library(wbstats)

t1 <- "https://github.com/akarlinsky/world_mortality/raw/main/world_mortality.csv" %>% 
  read_csv %>% 
  filter(
    time_unit %>% 
      equals("weekly")
  )

We’ll use the World Banks’s lovely API to load some national population estimates

t_pop <- wbstats::wb_data(
  "SP.POP.TOTL", 
  country = t1$iso3c %>% unique
) %>% 
  select(
    iso3c, 
    country, 
    date, 
    SP.POP.TOTL
  ) %>% 
  rename(
    year = date, 
    pop = SP.POP.TOTL
  )

Exercises:

  1. Generate a new variable t1$date which is the first day of every week indicated by the variables t1$year and t1$time

  2. Estimate country specific regression models predicting weekly deaths with a factor week predictor and a numeric year predictor, for the years 2015-2019. Then join the predicted deaths from these models to the weeks in the years 2020-2024.

  3. For the anglo-sphere countries, depict within and post-pandemic excess mortality, by country.