• Rebuilt: the healthspan-lifespan gap for 185 countries, 2000 to 2021, from public WHO and UN data and the 2025 paper’s methods text, since its code is not public.
  • Held: Africa has the narrowest gap, and the gap widens by 2100: 20.2% here, against the paper’s 22%.
  • Did not hold: the exact values, which differ with the snapshot year and WHO’s revisions, and the paper’s three disease-burden clusters. The data here split into two.

A 2025 paper in Communications Medicine measured the gap between how long people live and how many of those years they spend in good health. Its data is public, from the WHO and the UN. Its code is not. GapYears rebuilds the analysis from the methods text alone, as a pipeline anyone can rerun, and extends it two years past the paper’s 2019 cutoff.

nix run github:gauranii/GapYears
# copies the code into ./GapYears, pulls live WHO and UN data,
# and rebuilds every table and figure
Healthspan-lifespan gap by country, …
 
 
Gap = life expectancy minus healthy life expectancy, in years. Click a country for the full breakdown. Gray = no data.
Click a country to see its life expectancy, healthy life expectancy, and the gap between them.

How it is built

Twenty-two numbered R scripts, run in order by run_all.R, from the raw downloads to the last robustness check.

nix flake · R + 19 pinned packages · flake.lock
  1. Pull WHO GHO API, WHO GHE bulk xlsx, UN WPP 2024 CSV R/01 · R/04
  2. Build 185 countries × 2000–2021, one tidy table R/02
  3. Analyze Kruskal-Wallis, regression, PCA + k-means R/03 · R/05
  4. Redraw the paper's five figures, from my numbers R/06 – R/10
  5. Check random forest, Boruta, spatial error model, Moran's I, bootstrap k, panel, quantile, LASSO, 2100 projection R/11 – R/22
  6. Export (own step) JSON for the two maps on this page R/21

Reproducible. The whole R environment, R and all 19 packages, is pinned in flake.nix and flake.lock. nix develop opens a shell with exactly that environment, and every number on this page came out of it. Each full run also writes output/session_info.txt, so a result can be traced to the versions that produced it.

Tested. 43 testthat tests guard the parts most likely to break quietly: the WHO API response check, the spreadsheet parser, the country join, the clustering helpers, and invariants on the processed data. GitHub Actions runs nix flake check and the suite on every push, and runs the full pipeline against the live WHO endpoints every Monday, as an early warning that an upstream format changed.

Three walls, and the way around each

The disease data had no API. The country-level disability data the clustering needs is not in WHO’s public API. It sits in a point-and-click results tool. The same numbers turned out to be published as one bulk spreadsheet per year, laid out as a five-level outline of causes. R/04_pull_disease_burden.R downloads them, checks the file size before trusting a cached copy, and reads each row’s outline depth from the column that holds its name.

The standard spatial package would not build. spdep needs sf, which needs GDAL and PROJ, and that stack failed to build in this environment. So Moran’s I is written from the formula in base R, in R/utils_spatial.R:

morans_i <- function(x, w) {
  n <- length(x)
  xbar <- mean(x)
  dev <- x - xbar
  S0 <- sum(w)
  numerator <- sum(w * outer(dev, dev))
  denominator <- sum(dev^2)
  (n / S0) * (numerator / denominator)
}

With no reference implementation to compare against, the test checks an identity instead: on a complete graph with equal weights, Moran’s I is exactly −1/(n−1) for any data at all.

test_that("complete graph with equal weights gives the closed-form answer -1/(n-1)", {
  for (n in c(3, 5, 8)) {
    x <- rnorm(n)
    w <- matrix(1, n, n)
    diag(w) <- 0
    expect_equal(morans_i(x, w), -1 / (n - 1), tolerance = 1e-10)
  }
})

The paper left choices unstated. It does not say which spatial weights its spatial error model used, or what settings its random forest and Boruta checks ran with. Each of these is my own choice, made in the open, and the README lists every one.

Paper against rebuild

Paper August pull October rerun
Global median gap 9.1 years (2019) 9.3 years (2021) 9.9 years (2021)
Narrowest region Africa Africa, median 8.2 Africa, median 8.8
Disease-burden clusters 3 2, by silhouette width 2
Gap change by 2100 +22% +20.2% +17.6%
Spatial-model flips n/a 8 of 183 countries 15 of 183

The shape holds. The exact values do not, and the last column shows why I did not force them to. The August numbers come from the run behind the essays. A fresh clone and nix run on 11 October 2026 found that WHO had revised every one of the 4,070 country-year gap values in the meantime, and the 2100 projection moved by almost three points. Same code, same pinned environment, different upstream data: exactly what a rerunnable pipeline is for.

The regression behind the first map treats every country as independent. Refitting it as a spatial error model, which lets neighbouring countries’ errors move together, changes the verdict for 8 of 183 countries in the August pull. Toggle between the two below.

Gap deviation, plain regression vs. spatial-adjusted, …
Larger than predicted Smaller than predicted Flips between the two models
"Predicted" = this repo's own gap ~ life expectancy + health spending regression. The spatial-adjusted view lets nearby countries' residuals correlate instead of treating each country as independent. Click a country for both classifications; ringed countries are the ones that disagree.
Click a country to compare its plain-regression and spatial-adjusted classification.

The maps read JSON written by R/21_export_json.R, so a rerun only means copying two files to this site, with no page edits.

The write-up

The question behind this project is set out in The Window Stayed Shut. The findings are in three essays: the gap and whether it holds, which diseases take the healthy years, and where the gap is headed by 2100.