Analyzing data from COVID19 R package

Does reported deaths match actual deaths?

Introduction

The idea behind this post was to play and discover some of the info contained in the COVID19 R package which collects data across several governmental sources.This package is being developed by the Guidotti and Ardia from COVID19 Data Hub.

Later, I will add to the analysis the historical track record of deaths over last years for some european countries and try to address if deaths by COVID19 are being reported accurately. This data is collected in The Human Mortality Database.

Altough it may seem a bit overkill, it was such an intensive Tidyverse exercise that I decided to show pretty much all the code right here because that is what this post is about: I don’t intend to perform a really deep analysis but to show a kind of simple way to tackle this problem using R and the Tidyverse toolkit.

You might pick up a couple of tricks like the use of split_group() + map() to manipulate each group freely, using the {{}} (bang bang operator) to write programatic dplyr code, some custom plotting with plotly or the recently discovered package ggtext by @ClausWilke.

Playing with COVID19 package

Let’s start by loading data from COVID19 package with covid19 function. It contains lots of information, but I will keep things simple and work only with Country, Date, Population and Deaths variables.

I wanted to focus mainly on the most populated countries of the world because some of them are among the most affected by the virus, so I created a function for that as I will use it more than once.

Starting with a basic plot. You have already seen this one a thousand of times.

What about the countries most affected by the virus in deaths relative to the population? Pretty basic too.

Now, the pandemic didn’t explode in each country at the same time. Because of the exponential nature of the problem, it is also useful to display the information relative to the day certain number of confirmed cases or deaths are reached. I will use a couple of functions for that:

Here I’m showing in logarithmic scale the evolution of (cumulative) deaths since the first day 1 death per million people were counted:

It is also useful to look at the current trend: How is the evolution of the daily new deaths? Also, using a rolling average will smooth the lines and we will be able to see the patterns more clearly. Again defining the functions first:

I’m showing here the smoothed daily deaths per million population to have a better sense of the pandemic current state in each country.

Looking into the Human Mortality Database

Now we will add to the analysis the track record of deaths from last years for some european countries. I’m trying to calibrate if reported deaths due to COVID match real deaths data.

This is the weekly evolution of deaths over the past few years, being highlighted in orange the actual deaths in 2020.

To calculate the excess ratio, comparing the cumulative deaths from this and previous years is needed.

Lastly, I will plot the excess of deaths of this year compared to the mean of previous years and to the official COVID deaths.

It seems like certain countries are having some trouble with the reports, doesn’t it? For the next take, I’ll try to get fresh data from more countries, including some non european ones, to see how are dealing with numbers in Asia and America.

And that’s all for now folks!

Pablo Cánovas
Pablo Cánovas
Data Scientist at Repsol

Data Scientist, formerly physicist | Tidyverse believer, piping life | Hanging out at TypeThePipe

Related