COVID-19/All-cause deaths/Scripts

The following Python scripts were used to produce charts. They are small and very uncomplicated, very straightforward.

plotHmd.py
Usage:
 * plotHmd.py stmf.csv USA DTotal
 * plotHmd.py stmf.csv USA D0_14
 * plotHmd.py stmf.csv USA D0_14 3

To obtain stmf.csv, go to mpidr.shinyapps.io/stmortality and at the bottom of the left pane click on the icon to the right of "CSV".

Country codes: AUS (Australia), AUT (Austria), BEL (Belgium), BGR (Bulgaria), CAN (Canada), CHE (Switzerland), CHL (Chile), CZE (Czechia), DEUTNP (Germany), DNK (Denmark), ESP (Spain), EST (Estonia), FIN (Finland), FRATNP (France), GBRTENW (England and Wales), GBR_NIR (Northern Ireland), GBR_SCO (Scotland), GRC (Greece), HRV (Croatia), HUN (Hungary), ISL (Iceland), ISR (Israel), ITA (Italy), KOR (Republic of Korea), LTU (Lithuania), LUX (Luxembourg), LVA (Latvia), NLD (Netherlands), NOR (Norway), NZL_NP (New Zealand), POL (Poland), PRT (Portugal), RUS (Russia), SVK (Slovakia), SVN (Slovenia), SWE (Sweden), TWN (Taiwan), USA (U.S.). See also ISO 3166-1 alpha-3; note that some codes in stmf.csv have custom suffix such as the custom codes for parts of the United Kingdom (GBRTENW, etc.) or FRATNP instead of FRA. See also HMD-countries-codes.pdf, mortality.org; however, this list contains multiple codes absent from stmf.csv, such as FRACNP and UKR.

Field codes: D0_14 (deaths for 0-14y), D15_64 (deaths for 15-64y), D65_74 (deaths for 65-74y), D75_84 (deaths for 75-84y), D85p (deaths for 85+y), DTotal (deaths total).

The script drops last two data points to prevent the worst effect of registration delay; for some countries, the last two weeks were obviously very badly affected by registration delay.

plotHmdPerYear.py
Usage: similar to plotHmd.py.

plotHmdPerSeason.py
Usage: similar to plotHmd.py.

plotHmdExcessDeathPercPerYear.py
Usage (similar to plotHmd.py).
 * plotHmdExcessDeathPercPerYear.py stmf.csv BGR DTotal 5

Rationale for using minimum of a range of years as the baseline: visual inspection of the weekly charts shows that significant year-specific variation occurs in the upward direction but not in the downward direction. Thus, the year for which as little year-specific variation occurred as possible is taken to be the baseline; if we took the average, we would include previous year-specific upward variation into the baseline.

plotUsCdc.py
Usage:
 * plotUsCdc.py Excess_Deaths_Associated_with_COVID-19.csv "New York City"

To obtain Excess_Deaths_Associated_with_COVID-19.csv:
 * 1) Visit CDC.
 * 2) In section "Download Data:", click on "National and State Estimates of Excess Deaths".
 * 3) Save file "Excess_Deaths_Associated_with_COVID-19.csv", which contains data for all jurisdictions.

plotWmd.py
Usage:
 * plotWmd.py world_mortality.csv PER 3
 * plotWmd.py world_mortality.csv PER --ep 3

Moving average via awk
You can calculate the 7-day moving average using awk on Windows:
 * echo 1, 0, 4, 5, 18, 15, 28, 26, 64, 77, 101 | awk -F, -vn=7 "{for(i=1;i<=NF; i++) {s+=i>n?$i-$(i-n):$i; if(i>=n){printf \"%.0f, \", s/n}else{printf \", \"}}}"

You can put the result into clipboard:
 * echo 1, 0, 4, 5, 18, 15, 28, 26, 64, 77, 101 | awk -F, -vn=7 "{for(i=1;i<=NF; i++) {s+=i>n?$i-$(i-n):$i; if(i>=n){printf \"%.0f, \", s/n}else{printf \", \"}}}" | clip

You can do the calculation on Linux:
 * echo 1, 0, 4, 5, 18, 15, 28, 26, 64, 77, 101 | awk -F, -vn=7 '{for(i=1;i<=NF; i++) {s+=i>n?$i-$(i-n):$i; if(i>=n){printf "%.0f, ", s/n}else{printf ", "}}}'

If you are on Linux or a modern Mac, you already have awk. For Windows, you can install awk from ezwinports or GnuWin32 project.