Accuracy comparison for LC, PCA-GEE, and PCA-GEE+C

Author

Reza Dastranj

We compare the out-of-sample forecasting accuracy of three models:

  1. Lee–Carter estimated by singular value decomposition (LC),
  2. PCA-GEE without cohort effect (PCA-GEE),
  3. PCA-GEE with cohort effect (PCA-GEE+C).

The test period starts after 2000. We report several error measures: MSE, RMSE, MAE, MAPE, median absolute error, and symmetric MAPE. We also provide summaries by country, gender, age, calendar year, and age group.

Packages and population list

# The HMD data files should be in the same folder as this Rmd file.
# For example: AUS.fltper_1x1.txt, AUS.mltper_1x1.txt, etc.

countries <- c(
  "AUS","AUT","BEL","BGR","CAN","CHE","CZE","DEUTE","DEUTW","DNK",
  "ESP","FIN","FRATNP","GBR_NIR","GBR_NP","GBR_SCO","GBRTENW","HUN",
  "IRL","ISL","ITA","JPN","NLD","NOR","PRT","SVK","SWE","USA"
)

files <- c(
  paste0(countries, ".fltper_1x1.txt"),
  paste0(countries, ".mltper_1x1.txt")
)

missing_files <- files[!file.exists(files)]
if (length(missing_files) > 0) {
  stop(
    "Some mortality files were not found. Please make sure the data files are in the same folder as this Rmd file. Missing files: ",
    paste(missing_files, collapse = ", ")
  )
}

output_dir <- file.path(getwd(), output_dir_name)
dir.create(output_dir, showWarnings = FALSE, recursive = TRUE)

Helper functions

compute_k <- function(M_train, M_full) {
  p <- prcomp(M_train, center = TRUE, scale. = FALSE)
  kt_train <- as.numeric(p$x[, 1])
  h <- nrow(M_full) - nrow(M_train)
  kt_future <- forecast::rwf(kt_train, h = h, drift = TRUE)$mean
  c(kt_train, as.numeric(kt_future))
}

fit_LC <- function(M_train, M_full) {
  alpha <- colMeans(M_train)
  M_centered <- sweep(M_train, 2, alpha, "-")
  sv <- svd(M_centered)
  beta <- sv$v[, 1]
  beta <- beta / sum(beta)
  khat <- sv$u[, 1] * sv$d[1] * sum(sv$v[, 1])
  h <- nrow(M_full) - nrow(M_train)
  k_future <- forecast::rwf(khat, h = h, drift = TRUE)$mean
  k_all <- c(khat, as.numeric(k_future))
  pred <- outer(k_all, beta)
  sweep(pred, 2, alpha, "+")
}

fit_PCA_GEE <- function(M_train, M_full, kt, years, with_cohort = FALSE) {
  Tt <- nrow(M_train)
  fullT <- nrow(M_full)
  ages <- 0:max_age
  n_ages <- length(ages)

  years_all <- years
  years_train <- years_all[1:Tt]
  years_test <- years_all[(Tt + 1):fullT]
  Ttest <- length(years_test)

  df_train <- data.frame(
    year = rep(years_train, times = n_ages),
    age = rep(ages, each = Tt)
  )

  df_train$y <- as.vector(M_train)
  df_train$kt <- rep(kt[1:Tt], times = n_ages)
  df_train$age_factor <- factor(df_train$age, levels = ages)
  df_train$cohort <- df_train$year - df_train$age
  df_train$id <- df_train$age_factor

  if (with_cohort) {
    fml <- y ~ -1 + age_factor + age_factor:kt + cohort
  } else {
    fml <- y ~ -1 + age_factor + age_factor:kt
  }

  model <- geeglm(
    formula = fml,
    id = id,
    waves = year,
    corstr = "ar1",
    data = df_train
  )

  pred_train <- predict(model, newdata = df_train)
  pred_train_mat <- matrix(pred_train, nrow = Tt, ncol = n_ages, byrow = FALSE)

  df_test <- data.frame(
    year = rep(years_test, times = n_ages),
    age = rep(ages, each = Ttest)
  )

  df_test$kt <- rep(kt[(Tt + 1):fullT], times = n_ages)
  df_test$age_factor <- factor(df_test$age, levels = ages)
  df_test$cohort <- df_test$year - df_test$age
  df_test$id <- df_test$age_factor

  pred_test <- predict(model, newdata = df_test)
  pred_test_mat <- matrix(pred_test, nrow = Ttest, ncol = n_ages, byrow = FALSE)

  rbind(pred_train_mat, pred_test_mat)
}

compute_metrics <- function(actual, predicted, mape_eps = 1e-12) {
  err <- actual - predicted
  aerr <- abs(err)
  tibble(
    MSE = mean(err^2, na.rm = TRUE),
    RMSE = sqrt(mean(err^2, na.rm = TRUE)),
    MAE = mean(aerr, na.rm = TRUE),
    MAPE = mean(aerr / pmax(actual, mape_eps), na.rm = TRUE) * 100,
    MedAE = median(aerr, na.rm = TRUE),
    sMAPE = mean(2 * aerr / pmax(abs(actual) + abs(predicted), mape_eps), na.rm = TRUE) * 100
  )
}

make_metrics_long <- function(actual, predicted, country, gender, model, years_test, ages) {
  err <- as.vector(actual - predicted)
  aerr <- abs(err)
  actual_v <- as.vector(actual)
  pred_v <- as.vector(predicted)

  tibble(
    Country = country,
    Gender = gender,
    Model = model,
    Year = rep(years_test, times = length(ages)),
    Age = rep(ages, each = length(years_test)),
    Actual = actual_v,
    Predicted = pred_v,
    Error = err,
    AbsError = aerr,
    SquaredError = err^2,
    APE = aerr / pmax(actual_v, 1e-12) * 100,
    sAPE = 2 * aerr / pmax(abs(actual_v) + abs(pred_v), 1e-12) * 100
  )
}

Fit all models and compute errors

Results <- vector("list", length(files))
CellErrors <- vector("list", length(files))

for (n in seq_along(files)) {

  dat <- HMDHFDplus::readHMD(files[n]) %>% data.table()

  dat <- dat[Year >= start_year & Age <= max_age]
  dat[mx == 0, mx := mx_floor]
  dat[, logmx := log(mx)]
  setorder(dat, Year, Age)

  years <- sort(unique(dat$Year))
  ages <- 0:max_age

  M_full <- matrix(dat$logmx, nrow = length(years), ncol = length(ages), byrow = TRUE)

  Tt <- sum(years <= train_end_year)
  M_train <- M_full[1:Tt, , drop = FALSE]

  kt <- compute_k(M_train, M_full)

  LC_pred <- fit_LC(M_train, M_full)
  PCA_pred <- fit_PCA_GEE(M_train, M_full, kt, years = years, with_cohort = FALSE)
  PCAc_pred <- fit_PCA_GEE(M_train, M_full, kt, years = years, with_cohort = TRUE)

  test_idx <- (Tt + 1):nrow(M_full)
  years_test <- years[test_idx]

  M_test <- exp(M_full[test_idx, , drop = FALSE])
  LC_test <- exp(LC_pred[test_idx, , drop = FALSE])
  PCA_test <- exp(PCA_pred[test_idx, , drop = FALSE])
  PCAc_test <- exp(PCAc_pred[test_idx, , drop = FALSE])

  country <- sub("\\..*", "", files[n])
  gender <- ifelse(grepl("flt", files[n]), "Female", "Male")

  met_LC <- compute_metrics(M_test, LC_test) %>% mutate(Country = country, Gender = gender, Model = "LC")
  met_PCA <- compute_metrics(M_test, PCA_test) %>% mutate(Country = country, Gender = gender, Model = "PCA-GEE")
  met_PCAc <- compute_metrics(M_test, PCAc_test) %>% mutate(Country = country, Gender = gender, Model = "PCA-GEE+C")

  Results[[n]] <- bind_rows(met_LC, met_PCA, met_PCAc)

  CellErrors[[n]] <- bind_rows(
    make_metrics_long(M_test, LC_test, country, gender, "LC", years_test, ages),
    make_metrics_long(M_test, PCA_test, country, gender, "PCA-GEE", years_test, ages),
    make_metrics_long(M_test, PCAc_test, country, gender, "PCA-GEE+C", years_test, ages)
  )

  cat("Finished:", files[n], "\n")
}
Finished: AUS.fltper_1x1.txt 
Finished: AUT.fltper_1x1.txt 
Finished: BEL.fltper_1x1.txt 
Finished: BGR.fltper_1x1.txt 
Finished: CAN.fltper_1x1.txt 
Finished: CHE.fltper_1x1.txt 
Finished: CZE.fltper_1x1.txt 
Finished: DEUTE.fltper_1x1.txt 
Finished: DEUTW.fltper_1x1.txt 
Finished: DNK.fltper_1x1.txt 
Finished: ESP.fltper_1x1.txt 
Finished: FIN.fltper_1x1.txt 
Finished: FRATNP.fltper_1x1.txt 
Finished: GBR_NIR.fltper_1x1.txt 
Finished: GBR_NP.fltper_1x1.txt 
Finished: GBR_SCO.fltper_1x1.txt 
Finished: GBRTENW.fltper_1x1.txt 
Finished: HUN.fltper_1x1.txt 
Finished: IRL.fltper_1x1.txt 
Finished: ISL.fltper_1x1.txt 
Finished: ITA.fltper_1x1.txt 
Finished: JPN.fltper_1x1.txt 
Finished: NLD.fltper_1x1.txt 
Finished: NOR.fltper_1x1.txt 
Finished: PRT.fltper_1x1.txt 
Finished: SVK.fltper_1x1.txt 
Finished: SWE.fltper_1x1.txt 
Finished: USA.fltper_1x1.txt 
Finished: AUS.mltper_1x1.txt 
Finished: AUT.mltper_1x1.txt 
Finished: BEL.mltper_1x1.txt 
Finished: BGR.mltper_1x1.txt 
Finished: CAN.mltper_1x1.txt 
Finished: CHE.mltper_1x1.txt 
Finished: CZE.mltper_1x1.txt 
Finished: DEUTE.mltper_1x1.txt 
Finished: DEUTW.mltper_1x1.txt 
Finished: DNK.mltper_1x1.txt 
Finished: ESP.mltper_1x1.txt 
Finished: FIN.mltper_1x1.txt 
Finished: FRATNP.mltper_1x1.txt 
Finished: GBR_NIR.mltper_1x1.txt 
Finished: GBR_NP.mltper_1x1.txt 
Finished: GBR_SCO.mltper_1x1.txt 
Finished: GBRTENW.mltper_1x1.txt 
Finished: HUN.mltper_1x1.txt 
Finished: IRL.mltper_1x1.txt 
Finished: ISL.mltper_1x1.txt 
Finished: ITA.mltper_1x1.txt 
Finished: JPN.mltper_1x1.txt 
Finished: NLD.mltper_1x1.txt 
Finished: NOR.mltper_1x1.txt 
Finished: PRT.mltper_1x1.txt 
Finished: SVK.mltper_1x1.txt 
Finished: SWE.mltper_1x1.txt 
Finished: USA.mltper_1x1.txt 
MetricsTable <- bind_rows(Results) %>%
  select(Country, Gender, Model, MSE, RMSE, MAE, MAPE, MedAE, sMAPE)

CellErrors <- bind_rows(CellErrors)

write.csv(MetricsTable, file.path(output_dir, "metrics_by_country_gender_model.csv"), row.names = FALSE)
write.csv(CellErrors, file.path(output_dir, "cell_level_errors.csv"), row.names = FALSE)

Main accuracy tables

Aggregate table by model

AggregateTable <- MetricsTable %>%
  group_by(Model) %>%
  summarise(
    MSE = mean(MSE),
    RMSE = mean(RMSE),
    MAE = mean(MAE),
    MAPE = mean(MAPE),
    MedAE = mean(MedAE),
    sMAPE = mean(sMAPE),
    .groups = "drop"
  ) %>%
  arrange(RMSE)

kable(AggregateTable, digits = 6, caption = "Average out-of-sample error by model across all populations.")
Average out-of-sample error by model across all populations.
Model MSE RMSE MAE MAPE MedAE sMAPE
PCA-GEE+C 5.0e-05 0.005822 0.002749 51.68325 0.000491 25.82440
PCA-GEE 5.8e-05 0.006160 0.002948 55.45824 0.000564 26.29992
LC 5.9e-05 0.006212 0.002979 56.22727 0.000581 26.59907

Accuracy by country, gender, and model

kable(
  MetricsTable %>% arrange(Country, Gender, RMSE),
  digits = 6,
  caption = "Out-of-sample error measures by country, gender, and model."
)
Out-of-sample error measures by country, gender, and model.
Country Gender Model MSE RMSE MAE MAPE MedAE sMAPE
AUS Female PCA-GEE 0.000003 0.001760 0.000840 18.13917 0.000139 15.60933
AUS Female LC 0.000003 0.001765 0.000843 18.15613 0.000139 15.62629
AUS Female PCA-GEE+C 0.000003 0.001768 0.000844 18.15878 0.000138 15.61998
AUS Male PCA-GEE+C 0.000035 0.005874 0.002757 24.36315 0.000419 21.18771
AUS Male PCA-GEE 0.000035 0.005877 0.002758 24.36603 0.000419 21.18886
AUS Male LC 0.000036 0.005983 0.002806 24.53608 0.000423 21.34501
AUT Female PCA-GEE 0.000019 0.004401 0.001813 29.29651 0.000190 22.29038
AUT Female LC 0.000019 0.004402 0.001814 29.30243 0.000190 22.29575
AUT Female PCA-GEE+C 0.000020 0.004476 0.001841 29.42044 0.000189 22.34570
AUT Male PCA-GEE 0.000043 0.006556 0.003033 31.19423 0.000595 24.50114
AUT Male LC 0.000043 0.006569 0.003037 31.26339 0.000591 24.54874
AUT Male PCA-GEE+C 0.000044 0.006596 0.003043 31.30414 0.000592 24.54899
BEL Female PCA-GEE+C 0.000004 0.002074 0.000859 23.61309 0.000188 19.77825
BEL Female PCA-GEE 0.000004 0.002077 0.000861 23.64064 0.000186 19.78777
BEL Female LC 0.000004 0.002078 0.000862 23.64248 0.000185 19.78934
BEL Male PCA-GEE 0.000068 0.008232 0.003756 30.05487 0.000406 23.70076
BEL Male PCA-GEE+C 0.000068 0.008234 0.003757 30.05847 0.000406 23.70290
BEL Male LC 0.000068 0.008234 0.003756 30.01054 0.000405 23.67366
BGR Female PCA-GEE 0.000343 0.018524 0.006860 36.90291 0.000211 20.85566
BGR Female PCA-GEE+C 0.000343 0.018525 0.006868 36.90734 0.000211 20.86573
BGR Female LC 0.000345 0.018561 0.006870 36.94488 0.000212 20.86517
BGR Male PCA-GEE+C 0.000368 0.019183 0.008156 41.15113 0.001579 30.03174
BGR Male LC 0.000468 0.021637 0.009372 45.33493 0.001948 32.65454
BGR Male PCA-GEE 0.000471 0.021701 0.009394 45.17173 0.001937 32.58003
CAN Female PCA-GEE+C 0.000002 0.001300 0.000521 12.65795 0.000114 13.85995
CAN Female PCA-GEE 0.000002 0.001302 0.000523 12.64962 0.000115 13.84415
CAN Female LC 0.000002 0.001308 0.000524 12.67808 0.000116 13.87406
CAN Male PCA-GEE+C 0.000051 0.007128 0.003200 17.05188 0.000240 17.33642
CAN Male PCA-GEE 0.000051 0.007163 0.003223 17.10198 0.000242 17.37024
CAN Male LC 0.000053 0.007251 0.003266 17.27878 0.000245 17.51659
CHE Female PCA-GEE+C 0.000009 0.003006 0.001290 44.60221 0.000200 30.01733
CHE Female PCA-GEE 0.000010 0.003108 0.001335 44.46851 0.000198 30.08118
CHE Female LC 0.000010 0.003109 0.001336 44.47296 0.000198 30.08392
CHE Male LC 0.000021 0.004541 0.002316 52.18979 0.000608 33.20875
CHE Male PCA-GEE 0.000021 0.004578 0.002334 51.79566 0.000605 33.10163
CHE Male PCA-GEE+C 0.000021 0.004580 0.002334 51.80092 0.000605 33.10426
CZE Female PCA-GEE+C 0.000066 0.008135 0.003673 32.16916 0.000305 23.83711
CZE Female PCA-GEE 0.000068 0.008231 0.003723 32.37253 0.000313 23.97211
CZE Female LC 0.000068 0.008243 0.003728 32.38258 0.000314 23.98151
CZE Male PCA-GEE+C 0.000086 0.009289 0.004977 32.95564 0.001431 25.74158
CZE Male PCA-GEE 0.000111 0.010548 0.005673 35.24024 0.001603 27.23966
CZE Male LC 0.000119 0.010891 0.005895 36.12877 0.001692 27.77795
DEUTE Female PCA-GEE 0.000009 0.002970 0.001170 22.32219 0.000143 19.45964
DEUTE Female LC 0.000009 0.002995 0.001173 22.28472 0.000143 19.39816
DEUTE Female PCA-GEE+C 0.000010 0.003144 0.001197 21.89810 0.000141 19.28912
DEUTE Male PCA-GEE+C 0.000070 0.008392 0.004531 44.39797 0.001350 33.07191
DEUTE Male LC 0.000081 0.008998 0.004983 49.82527 0.001686 36.22055
DEUTE Male PCA-GEE 0.000084 0.009161 0.004923 45.27126 0.001393 33.68945
DEUTW Female LC 0.000003 0.001783 0.000679 11.96656 0.000118 11.84792
DEUTW Female PCA-GEE 0.000003 0.001791 0.000681 11.96145 0.000116 11.83880
DEUTW Female PCA-GEE+C 0.000003 0.001793 0.000681 11.95816 0.000116 11.83835
DEUTW Male PCA-GEE 0.000043 0.006589 0.003021 18.21203 0.000369 16.92585
DEUTW Male PCA-GEE+C 0.000044 0.006629 0.003034 18.27468 0.000372 16.96946
DEUTW Male LC 0.000045 0.006703 0.003068 18.37621 0.000388 17.07896
DNK Female PCA-GEE+C 0.000015 0.003893 0.002085 58.02374 0.000508 37.89437
DNK Female LC 0.000019 0.004379 0.002243 55.90119 0.000491 37.15908
DNK Female PCA-GEE 0.000020 0.004431 0.002265 55.79156 0.000491 37.14738
DNK Male PCA-GEE+C 0.000086 0.009277 0.005012 72.71736 0.001099 41.65810
DNK Male PCA-GEE 0.000086 0.009292 0.005027 72.80529 0.001097 41.71261
DNK Male LC 0.000087 0.009304 0.005034 72.95714 0.001105 41.78100
ESP Female LC 0.000005 0.002222 0.000900 19.01256 0.000118 17.93273
ESP Female PCA-GEE 0.000005 0.002259 0.000912 18.05992 0.000108 17.12224
ESP Female PCA-GEE+C 0.000005 0.002285 0.000921 18.08697 0.000108 17.12816
ESP Male LC 0.000007 0.002664 0.001407 49.49344 0.000706 31.02755
ESP Male PCA-GEE 0.000007 0.002734 0.001401 45.13244 0.000645 29.58142
ESP Male PCA-GEE+C 0.000008 0.002828 0.001462 45.92623 0.000671 30.00230
FIN Female PCA-GEE+C 0.000008 0.002773 0.001245 36.96410 0.000172 24.27737
FIN Female PCA-GEE 0.000008 0.002856 0.001280 37.14362 0.000173 24.29071
FIN Female LC 0.000008 0.002856 0.001280 37.14353 0.000173 24.29070
FIN Male PCA-GEE+C 0.000029 0.005376 0.002635 36.04450 0.000377 23.76055
FIN Male PCA-GEE 0.000029 0.005377 0.002635 36.05132 0.000377 23.76436
FIN Male LC 0.000029 0.005378 0.002635 36.05127 0.000377 23.76474
FRATNP Female PCA-GEE 0.000002 0.001507 0.000679 18.05973 0.000143 16.62136
FRATNP Female PCA-GEE+C 0.000002 0.001508 0.000679 18.06692 0.000143 16.62287
FRATNP Female LC 0.000002 0.001557 0.000707 18.89178 0.000151 17.35984
FRATNP Male PCA-GEE 0.000009 0.002979 0.001459 22.64393 0.000459 18.93883
FRATNP Male PCA-GEE+C 0.000009 0.003004 0.001469 22.68860 0.000459 18.96551
FRATNP Male LC 0.000011 0.003325 0.001579 24.10631 0.000501 19.87814
GBRTENW Female PCA-GEE 0.000005 0.002183 0.001118 13.52612 0.000107 13.07410
GBRTENW Female PCA-GEE+C 0.000005 0.002183 0.001119 13.52641 0.000107 13.07552
GBRTENW Female LC 0.000005 0.002210 0.001138 13.73624 0.000109 13.26986
GBRTENW Male PCA-GEE 0.000044 0.006649 0.003181 17.63521 0.000234 16.33769
GBRTENW Male PCA-GEE+C 0.000046 0.006754 0.003235 17.76012 0.000233 16.42389
GBRTENW Male LC 0.000053 0.007297 0.003488 18.34678 0.000244 16.98582
GBR_NIR Female PCA-GEE+C 0.000009 0.003040 0.001397 109.18372 0.000330 38.66511
GBR_NIR Female LC 0.000010 0.003085 0.001383 108.23977 0.000326 38.69102
GBR_NIR Female PCA-GEE 0.000010 0.003108 0.001380 108.03537 0.000328 38.74878
GBR_NIR Male LC 0.000133 0.011537 0.005590 101.52211 0.000533 36.11287
GBR_NIR Male PCA-GEE 0.000136 0.011672 0.005663 101.46960 0.000522 36.18745
GBR_NIR Male PCA-GEE+C 0.000145 0.012024 0.005823 102.31189 0.000529 36.30560
GBR_NP Female PCA-GEE 0.000005 0.002126 0.001086 13.24687 0.000115 12.92355
GBR_NP Female PCA-GEE+C 0.000005 0.002127 0.001087 13.24854 0.000115 12.92470
GBR_NP Female LC 0.000005 0.002145 0.001107 13.53826 0.000118 13.20001
GBR_NP Male PCA-GEE 0.000044 0.006669 0.003221 17.97215 0.000256 16.57511
GBR_NP Male PCA-GEE+C 0.000045 0.006712 0.003245 18.02358 0.000256 16.61143
GBR_NP Male LC 0.000055 0.007427 0.003589 18.78006 0.000264 17.31644
GBR_SCO Female PCA-GEE+C 0.000015 0.003921 0.001707 37.14341 0.000298 26.13394
GBR_SCO Female PCA-GEE 0.000017 0.004088 0.001744 36.97169 0.000303 26.23519
GBR_SCO Female LC 0.000017 0.004106 0.001749 37.04204 0.000306 26.25633
GBR_SCO Male LC 0.000062 0.007895 0.004067 41.61041 0.000624 27.69642
GBR_SCO Male PCA-GEE 0.000062 0.007897 0.004068 41.61177 0.000625 27.69776
GBR_SCO Male PCA-GEE+C 0.000066 0.008119 0.004189 41.95047 0.000624 27.83466
HUN Female PCA-GEE+C 0.000025 0.005015 0.002757 52.84042 0.001297 33.37295
HUN Female PCA-GEE 0.000027 0.005200 0.002854 53.22698 0.001319 33.63983
HUN Female LC 0.000028 0.005297 0.002910 54.26633 0.001380 34.09190
HUN Male PCA-GEE+C 0.000037 0.006110 0.003924 59.17372 0.002030 35.66744
HUN Male PCA-GEE 0.000243 0.015583 0.009672 86.15134 0.005002 49.19767
HUN Male LC 0.000245 0.015645 0.009777 88.42400 0.005140 50.06384
IRL Female PCA-GEE+C 0.000092 0.009605 0.004562 55.71807 0.000227 31.74274
IRL Female PCA-GEE 0.000102 0.010079 0.004782 56.89918 0.000228 32.24268
IRL Female LC 0.000102 0.010079 0.004782 56.89092 0.000228 32.24466
IRL Male PCA-GEE 0.000188 0.013698 0.006271 44.60917 0.000530 34.98258
IRL Male LC 0.000189 0.013737 0.006277 44.76096 0.000543 35.12632
IRL Male PCA-GEE+C 0.000193 0.013888 0.006359 44.86797 0.000526 35.05186
ISL Female LC 0.000011 0.003349 0.001729 303.18240 0.000509 78.92926
ISL Female PCA-GEE 0.000012 0.003417 0.001756 288.43594 0.000514 78.42822
ISL Female PCA-GEE+C 0.000018 0.004228 0.002008 273.07303 0.000488 78.55050
ISL Male PCA-GEE+C 0.000047 0.006847 0.003142 720.11909 0.000782 64.94334
ISL Male LC 0.000078 0.008820 0.004722 875.02453 0.000966 69.35285
ISL Male PCA-GEE 0.000078 0.008820 0.004724 876.50383 0.000968 69.34779
ITA Female PCA-GEE+C 0.000004 0.002093 0.000795 12.59997 0.000064 11.77007
ITA Female PCA-GEE 0.000004 0.002106 0.000808 12.70620 0.000064 11.84351
ITA Female LC 0.000004 0.002107 0.000802 12.86738 0.000065 11.96050
ITA Male PCA-GEE+C 0.000017 0.004067 0.002118 25.59221 0.000355 21.97087
ITA Male PCA-GEE 0.000017 0.004075 0.002123 25.59333 0.000354 21.97963
ITA Male LC 0.000017 0.004158 0.002216 27.75781 0.000395 23.24196
JPN Female PCA-GEE+C 0.000008 0.002834 0.001047 20.36020 0.000166 23.89406
JPN Female PCA-GEE 0.000008 0.002909 0.001070 20.19470 0.000164 23.65176
JPN Female LC 0.000010 0.003216 0.001178 20.64944 0.000174 24.13363
JPN Male PCA-GEE 0.000005 0.002214 0.000845 11.62374 0.000161 12.42889
JPN Male PCA-GEE+C 0.000005 0.002216 0.000845 11.67678 0.000160 12.51667
JPN Male LC 0.000005 0.002243 0.000871 12.32131 0.000170 13.12959
NLD Female LC 0.000004 0.002008 0.000831 21.93605 0.000165 17.43974
NLD Female PCA-GEE 0.000004 0.002010 0.000833 21.93691 0.000165 17.44238
NLD Female PCA-GEE+C 0.000004 0.002066 0.000885 22.77710 0.000175 18.03009
NLD Male PCA-GEE 0.000151 0.012301 0.006037 32.41839 0.000365 26.42307
NLD Male LC 0.000152 0.012328 0.006054 32.45435 0.000363 26.43967
NLD Male PCA-GEE+C 0.000160 0.012642 0.006202 33.14475 0.000380 26.91065
NOR Female PCA-GEE+C 0.000016 0.003939 0.001722 56.34110 0.000248 28.80339
NOR Female PCA-GEE 0.000036 0.005958 0.002620 63.99971 0.000320 32.49236
NOR Female LC 0.000036 0.006021 0.002649 64.12331 0.000320 32.60500
NOR Male LC 0.000137 0.011717 0.005730 58.54065 0.000567 34.48354
NOR Male PCA-GEE 0.000137 0.011723 0.005733 58.54834 0.000566 34.47606
NOR Male PCA-GEE+C 0.000140 0.011837 0.005781 58.82999 0.000568 34.61287
PRT Female LC 0.000020 0.004491 0.001772 33.84810 0.000152 22.12851
PRT Female PCA-GEE 0.000020 0.004511 0.001783 33.74908 0.000153 22.10499
PRT Female PCA-GEE+C 0.000021 0.004531 0.001791 33.80374 0.000153 22.13633
PRT Male PCA-GEE 0.000030 0.005493 0.002805 65.71782 0.000932 35.53673
PRT Male PCA-GEE+C 0.000030 0.005495 0.002799 65.74223 0.000922 35.52374
PRT Male LC 0.000030 0.005521 0.002842 69.77151 0.000977 36.70896
SVK Female PCA-GEE+C 0.000028 0.005332 0.002393 46.47908 0.000322 25.15706
SVK Female PCA-GEE 0.000029 0.005420 0.002439 46.72473 0.000323 25.26796
SVK Female LC 0.000030 0.005447 0.002451 46.71563 0.000328 25.25777
SVK Male PCA-GEE+C 0.000183 0.013540 0.007739 45.76792 0.002904 33.69201
SVK Male PCA-GEE 0.000223 0.014919 0.008492 48.42661 0.003139 35.23079
SVK Male LC 0.000224 0.014953 0.008539 48.93506 0.003187 35.47017
SWE Female LC 0.000003 0.001835 0.000752 22.43626 0.000138 20.70708
SWE Female PCA-GEE 0.000003 0.001838 0.000753 22.43117 0.000138 20.70184
SWE Female PCA-GEE+C 0.000004 0.001914 0.000783 22.39885 0.000136 20.74846
SWE Male PCA-GEE+C 0.000024 0.004864 0.002284 23.38881 0.000308 22.99496
SWE Male PCA-GEE 0.000028 0.005261 0.002490 24.11920 0.000329 23.43609
SWE Male LC 0.000028 0.005262 0.002486 24.07261 0.000324 23.42255
USA Female PCA-GEE+C 0.000009 0.003067 0.001172 12.85690 0.000284 13.81577
USA Female PCA-GEE 0.000010 0.003214 0.001224 12.97451 0.000294 14.01128
USA Female LC 0.000012 0.003451 0.001334 13.65536 0.000314 14.69874
USA Male LC 0.000014 0.003732 0.001887 12.94560 0.000399 13.40253
USA Male PCA-GEE 0.000015 0.003815 0.001908 12.35238 0.000393 12.93416
USA Male PCA-GEE+C 0.000016 0.003950 0.001953 12.30013 0.000387 12.82992

Ratio table

A ratio larger than one means the denominator model has smaller error. For example, LC / PCA-GEE > 1 means that PCA-GEE improves over LC for that metric.

RatioTable <- MetricsTable %>%
  pivot_longer(cols = c(MSE, RMSE, MAE, MAPE, MedAE, sMAPE),
               names_to = "ErrorMetric", values_to = "Value") %>%
  select(Country, Gender, Model, ErrorMetric, Value) %>%
  pivot_wider(names_from = Model, values_from = Value) %>%
  mutate(
    `LC / PCA-GEE` = LC / `PCA-GEE`,
    `LC / PCA-GEE+C` = LC / `PCA-GEE+C`,
    `PCA-GEE / PCA-GEE+C` = `PCA-GEE` / `PCA-GEE+C`
  )

kable(
  RatioTable %>% select(Country, Gender, ErrorMetric, `LC / PCA-GEE`, `LC / PCA-GEE+C`, `PCA-GEE / PCA-GEE+C`),
  digits = 8,
  caption = "Error ratios by population and metric. Ratios above one favour the denominator model."
)
Error ratios by population and metric. Ratios above one favour the denominator model.
Country Gender ErrorMetric LC / PCA-GEE LC / PCA-GEE+C PCA-GEE / PCA-GEE+C
AUS Female MSE 1.0051700 0.9963042 0.9911798
AUS Female RMSE 1.0025816 0.9981504 0.9955801
AUS Female MAE 1.0029546 0.9985990 0.9956572
AUS Female MAPE 1.0009348 0.9998539 0.9989202
AUS Female MedAE 1.0018337 1.0035777 1.0017409
AUS Female sMAPE 1.0010870 1.0004039 0.9993176
AUT Female MSE 1.0003176 0.9673751 0.9670679
AUT Female RMSE 1.0001588 0.9835523 0.9833961
AUT Female MAE 1.0002238 0.9852719 0.9850515
AUT Female MAPE 1.0002019 0.9959888 0.9957878
AUT Female MedAE 1.0004849 1.0060447 1.0055572
AUT Female sMAPE 1.0002410 0.9977649 0.9975245
BEL Female MSE 1.0003054 1.0032873 1.0029810
BEL Female RMSE 1.0001527 1.0016423 1.0014894
BEL Female MAE 1.0005734 1.0028832 1.0023085
BEL Female MAPE 1.0000780 1.0012450 1.0011669
BEL Female MedAE 0.9975523 0.9857273 0.9881460
BEL Female sMAPE 1.0000795 1.0005606 1.0004811
BGR Female MSE 1.0039795 1.0039043 0.9999250
BGR Female RMSE 1.0019878 1.0019502 0.9999625
BGR Female MAE 1.0014706 1.0002534 0.9987846
BGR Female MAPE 1.0011372 1.0010171 0.9998801
BGR Female MedAE 1.0039099 1.0019520 0.9980497
BGR Female sMAPE 1.0004558 0.9999731 0.9995175
CAN Female MSE 1.0086807 1.0117676 1.0030604
CAN Female RMSE 1.0043309 1.0058666 1.0015290
CAN Female MAE 1.0014781 1.0053466 1.0038627
CAN Female MAPE 1.0022496 1.0015900 0.9993418
CAN Female MedAE 1.0054362 1.0115550 1.0060858
CAN Female sMAPE 1.0021601 1.0010178 0.9988601
CHE Female MSE 1.0006873 1.0695316 1.0687971
CHE Female RMSE 1.0003436 1.0341816 1.0338264
CHE Female MAE 1.0003695 1.0355410 1.0351585
CHE Female MAPE 1.0001000 0.9971020 0.9970023
CHE Female MedAE 1.0009840 0.9904970 0.9895234
CHE Female sMAPE 1.0000910 1.0022181 1.0021269
CZE Female MSE 1.0029650 1.0267672 1.0237318
CZE Female RMSE 1.0014814 1.0132952 1.0117963
CZE Female MAE 1.0012730 1.0148923 1.0136020
CZE Female MAPE 1.0003103 1.0066343 1.0063220
CZE Female MedAE 1.0048348 1.0313811 1.0264186
CZE Female sMAPE 1.0003918 1.0060578 1.0056638
DEUTE Female MSE 1.0165358 0.9071689 0.8924121
DEUTE Female RMSE 1.0082340 0.9524541 0.9446757
DEUTE Female MAE 1.0030963 0.9802904 0.9772645
DEUTE Female MAPE 0.9983214 1.0176553 1.0193664
DEUTE Female MedAE 0.9997353 1.0171364 1.0174057
DEUTE Female sMAPE 0.9968405 1.0056531 1.0088405
DEUTW Female MSE 0.9912620 0.9883856 0.9970982
DEUTW Female RMSE 0.9956214 0.9941758 0.9985481
DEUTW Female MAE 0.9975789 0.9969170 0.9993365
DEUTW Female MAPE 1.0004273 1.0007023 1.0002749
DEUTW Female MedAE 1.0132972 1.0155391 1.0022125
DEUTW Female sMAPE 1.0007699 1.0008077 1.0000377
DNK Female MSE 0.9765856 1.2650860 1.2954174
DNK Female RMSE 0.9882235 1.1247604 1.1381641
DNK Female MAE 0.9904547 1.0759028 1.0862715
DNK Female MAPE 1.0019650 0.9634194 0.9615299
DNK Female MedAE 0.9991820 0.9656357 0.9664262
DNK Female sMAPE 1.0003152 0.9805965 0.9802876
ESP Female MSE 0.9675491 0.9457366 0.9774559
ESP Female RMSE 0.9836407 0.9724899 0.9886637
ESP Female MAE 0.9869112 0.9773854 0.9903479
ESP Female MAPE 1.0527490 1.0511744 0.9985043
ESP Female MedAE 1.0971542 1.0951652 0.9981872
ESP Female sMAPE 1.0473352 1.0469731 0.9996542
FIN Female MSE 1.0000263 1.0610726 1.0610447
FIN Female RMSE 1.0000131 1.0300838 1.0300702
FIN Female MAE 1.0000119 1.0284243 1.0284121
FIN Female MAPE 0.9999975 1.0048543 1.0048568
FIN Female MedAE 0.9999750 1.0063537 1.0063788
FIN Female sMAPE 0.9999994 1.0005489 1.0005495
FRATNP Female MSE 1.0685122 1.0665198 0.9981354
FRATNP Female RMSE 1.0336887 1.0327245 0.9990672
FRATNP Female MAE 1.0413741 1.0406350 0.9992902
FRATNP Female MAPE 1.0460719 1.0456558 0.9996022
FRATNP Female MedAE 1.0590004 1.0584008 0.9994338
FRATNP Female sMAPE 1.0444297 1.0443344 0.9999088
GBR_NIR Female MSE 0.9855713 1.0301479 1.0452292
GBR_NIR Female RMSE 0.9927594 1.0149620 1.0223645
GBR_NIR Female MAE 1.0022742 0.9901825 0.9879358
GBR_NIR Female MAPE 1.0018920 0.9913544 0.9894824
GBR_NIR Female MedAE 0.9934197 0.9877408 0.9942834
GBR_NIR Female sMAPE 0.9985093 1.0006701 1.0021641
GBR_NP Female MSE 1.0174722 1.0167774 0.9993171
GBR_NP Female RMSE 1.0086983 1.0083538 0.9996585
GBR_NP Female MAE 1.0190439 1.0185716 0.9995365
GBR_NP Female MAPE 1.0219973 1.0218684 0.9998739
GBR_NP Female MedAE 1.0258809 1.0269033 1.0009966
GBR_NP Female sMAPE 1.0213921 1.0213014 0.9999112
GBR_SCO Female MSE 1.0089450 1.0967469 1.0870235
GBR_SCO Female RMSE 1.0044625 1.0472568 1.0426042
GBR_SCO Female MAE 1.0028235 1.0250084 1.0221224
GBR_SCO Female MAPE 1.0019029 0.9972708 0.9953767
GBR_SCO Female MedAE 1.0069368 1.0262409 1.0191712
GBR_SCO Female sMAPE 1.0008058 1.0046832 1.0038742
GBRTENW Female MSE 1.0249333 1.0248823 0.9999502
GBRTENW Female RMSE 1.0123899 1.0123647 0.9999751
GBRTENW Female MAE 1.0174036 1.0173129 0.9999109
GBRTENW Female MAPE 1.0155343 1.0155126 0.9999786
GBRTENW Female MedAE 1.0179558 1.0130441 0.9951749
GBRTENW Female sMAPE 1.0149726 1.0148631 0.9998920
HUN Female MSE 1.0375860 1.1153465 1.0749437
HUN Female RMSE 1.0186197 1.0560997 1.0367949
HUN Female MAE 1.0195438 1.0552421 1.0350139
HUN Female MAPE 1.0195268 1.0269853 1.0073156
HUN Female MedAE 1.0465204 1.0643508 1.0170379
HUN Female sMAPE 1.0134383 1.0215428 1.0079971
IRL Female MSE 1.0001001 1.1012082 1.1010980
IRL Female RMSE 1.0000501 1.0493847 1.0493322
IRL Female MAE 1.0001011 1.0483293 1.0482233
IRL Female MAPE 0.9998548 1.0210497 1.0211980
IRL Female MedAE 1.0003609 1.0071709 1.0068075
IRL Female sMAPE 1.0000612 1.0158119 1.0157497
ISL Female MSE 0.9605385 0.6274322 0.6532088
ISL Female RMSE 0.9800707 0.7921062 0.8082134
ISL Female MAE 0.9850662 0.8614681 0.8745281
ISL Female MAPE 1.0511256 1.1102612 1.0562593
ISL Female MedAE 0.9901621 1.0416512 1.0520006
ISL Female sMAPE 1.0063886 1.0048219 0.9984433
ITA Female MSE 1.0011636 1.0140986 1.0129199
ITA Female RMSE 1.0005816 1.0070246 1.0064392
ITA Female MAE 0.9918877 1.0076448 1.0158860
ITA Female MAPE 1.0126852 1.0212235 1.0084313
ITA Female MedAE 1.0094339 1.0190736 1.0095495
ITA Female sMAPE 1.0098780 1.0161791 1.0062395
JPN Female MSE 1.2225891 1.2878832 1.0534065
JPN Female RMSE 1.1057075 1.1348494 1.0263559
JPN Female MAE 1.1008760 1.1250912 1.0219963
JPN Female MAPE 1.0225178 1.0142062 0.9918714
JPN Female MedAE 1.0598733 1.0504609 0.9911193
JPN Female sMAPE 1.0203736 1.0100264 0.9898594
NLD Female MSE 0.9985215 0.9453804 0.9467802
NLD Female RMSE 0.9992605 0.9723067 0.9730263
NLD Female MAE 0.9978838 0.9395790 0.9415715
NLD Female MAPE 0.9999607 0.9630743 0.9631122
NLD Female MedAE 0.9986410 0.9454217 0.9467083
NLD Female sMAPE 0.9998489 0.9672578 0.9674040
NOR Female MSE 1.0209978 2.3367913 2.2887329
NOR Female RMSE 1.0104444 1.5286567 1.5128559
NOR Female MAE 1.0109785 1.5385881 1.5218801
NOR Female MAPE 1.0019313 1.1381267 1.1359328
NOR Female MedAE 1.0018684 1.2900768 1.2876709
NOR Female sMAPE 1.0034668 1.1319848 1.1280740
PRT Female MSE 0.9914804 0.9824545 0.9908965
PRT Female RMSE 0.9957311 0.9911884 0.9954379
PRT Female MAE 0.9937354 0.9890295 0.9952644
PRT Female MAPE 1.0029339 1.0013123 0.9983831
PRT Female MedAE 0.9943291 0.9950320 1.0007069
PRT Female sMAPE 1.0010640 0.9996463 0.9985839
SVK Female MSE 1.0101863 1.0436351 1.0331115
SVK Female RMSE 1.0050802 1.0215846 1.0164209
SVK Female MAE 1.0047425 1.0240436 1.0192100
SVK Female MAPE 0.9998053 1.0050893 1.0052851
SVK Female MedAE 1.0133401 1.0188280 1.0054157
SVK Female sMAPE 0.9995965 1.0040030 1.0044083
SWE Female MSE 0.9969459 0.9192897 0.9221059
SWE Female RMSE 0.9984718 0.9587959 0.9602635
SWE Female MAE 0.9984346 0.9601850 0.9616904
SWE Female MAPE 1.0002270 1.0016702 1.0014428
SWE Female MedAE 1.0000785 1.0181582 1.0180783
SWE Female sMAPE 1.0002536 0.9980060 0.9977530
USA Female MSE 1.1529243 1.2658896 1.0979815
USA Female RMSE 1.0737431 1.1251176 1.0478461
USA Female MAE 1.0900669 1.1386187 1.0445402
USA Female MAPE 1.0524765 1.0621038 1.0091473
USA Female MedAE 1.0698169 1.1055677 1.0334178
USA Female sMAPE 1.0490648 1.0639107 1.0141516
AUS Male MSE 1.0366207 1.0376329 1.0009765
AUS Male RMSE 1.0181457 1.0186427 1.0004881
AUS Male MAE 1.0175455 1.0178800 1.0003287
AUS Male MAPE 1.0069792 1.0070982 1.0001181
AUS Male MedAE 1.0104801 1.0102678 0.9997900
AUS Male sMAPE 1.0073695 1.0074242 1.0000544
AUT Male MSE 1.0039337 0.9917118 0.9878260
AUT Male RMSE 1.0019649 0.9958473 0.9938944
AUT Male MAE 1.0014570 0.9981056 0.9966534
AUT Male MAPE 1.0022172 0.9986984 0.9964890
AUT Male MedAE 0.9939569 0.9981156 1.0041840
AUT Male sMAPE 1.0019426 0.9999897 0.9980509
BEL Male MSE 1.0006304 1.0001602 0.9995301
BEL Male RMSE 1.0003151 1.0000801 0.9997650
BEL Male MAE 1.0000194 0.9998344 0.9998150
BEL Male MAPE 0.9985250 0.9984056 0.9998805
BEL Male MedAE 0.9987239 0.9986089 0.9998849
BEL Male sMAPE 0.9988566 0.9987663 0.9999096
BGR Male MSE 0.9941701 1.2723245 1.2797855
BGR Male RMSE 0.9970808 1.1279736 1.1312761
BGR Male MAE 0.9976306 1.1491258 1.1518551
BGR Male MAPE 1.0036129 1.1016693 1.0977033
BGR Male MedAE 1.0055736 1.2338504 1.2270115
BGR Male sMAPE 1.0022871 1.0873346 1.0848534
CAN Male MSE 1.0245910 1.0347699 1.0099346
CAN Male RMSE 1.0122208 1.0172364 1.0049550
CAN Male MAE 1.0132936 1.0205164 1.0071280
CAN Male MAPE 1.0103381 1.0133067 1.0029382
CAN Male MedAE 1.0119206 1.0213823 1.0093502
CAN Male sMAPE 1.0084257 1.0103927 1.0019506
CHE Male MSE 0.9838798 0.9832334 0.9993429
CHE Male RMSE 0.9919072 0.9915812 0.9996714
CHE Male MAE 0.9926368 0.9923849 0.9997462
CHE Male MAPE 1.0076094 1.0075071 0.9998985
CHE Male MedAE 1.0048450 1.0049429 1.0000974
CHE Male sMAPE 1.0032361 1.0031563 0.9999204
CZE Male MSE 1.0660419 1.3744565 1.2893081
CZE Male RMSE 1.0324931 1.1723722 1.1354770
CZE Male MAE 1.0391218 1.1843935 1.1398025
CZE Male MAPE 1.0252133 1.0962849 1.0693237
CZE Male MedAE 1.0554564 1.1824960 1.1203646
CZE Male sMAPE 1.0197616 1.0791085 1.0581969
DEUTE Male MSE 0.9646136 1.1496684 1.1918435
DEUTE Male RMSE 0.9821474 1.0722259 1.0917158
DEUTE Male MAE 1.0123156 1.0999526 1.0865708
DEUTE Male MAPE 1.1005939 1.1222421 1.0196695
DEUTE Male MedAE 1.2107072 1.2491575 1.0317585
DEUTE Male sMAPE 1.0751303 1.0952059 1.0186727
DEUTW Male MSE 1.0350288 1.0223724 0.9877719
DEUTW Male RMSE 1.0173637 1.0111243 0.9938672
DEUTW Male MAE 1.0158087 1.0112922 0.9955539
DEUTW Male MAPE 1.0090151 1.0055559 0.9965717
DEUTW Male MedAE 1.0518824 1.0454011 0.9938384
DEUTW Male sMAPE 1.0090461 1.0064527 0.9974299
DNK Male MSE 1.0025509 1.0059619 1.0034023
DNK Male RMSE 1.0012747 1.0029765 1.0016997
DNK Male MAE 1.0014197 1.0043709 1.0029469
DNK Male MAPE 1.0020857 1.0032975 1.0012092
DNK Male MedAE 1.0074135 1.0053181 0.9979200
DNK Male sMAPE 1.0016396 1.0029501 1.0013083
ESP Male MSE 0.9489010 0.8870624 0.9348314
ESP Male RMSE 0.9741155 0.9418399 0.9668668
ESP Male MAE 1.0041485 0.9623773 0.9584014
ESP Male MAPE 1.0966268 1.0776726 0.9827159
ESP Male MedAE 1.0946737 1.0525571 0.9615259
ESP Male sMAPE 1.0488865 1.0341722 0.9859716
FIN Male MSE 1.0000733 1.0006566 1.0005833
FIN Male RMSE 1.0000367 1.0003283 1.0002916
FIN Male MAE 1.0000423 1.0002539 1.0002115
FIN Male MAPE 0.9999986 1.0001877 1.0001891
FIN Male MedAE 0.9999922 1.0000876 1.0000954
FIN Male sMAPE 1.0000162 1.0001764 1.0001601
FRATNP Male MSE 1.2454403 1.2250550 0.9836320
FRATNP Male RMSE 1.1159930 1.1068220 0.9917822
FRATNP Male MAE 1.0816663 1.0746771 0.9935385
FRATNP Male MAPE 1.0645815 1.0624855 0.9980312
FRATNP Male MedAE 1.0909141 1.0903305 0.9994650
FRATNP Male sMAPE 1.0495967 1.0481201 0.9985931
GBR_NIR Male MSE 0.9770449 0.9207098 0.9423414
GBR_NIR Male RMSE 0.9884558 0.9595363 0.9707427
GBR_NIR Male MAE 0.9871477 0.9599973 0.9724960
GBR_NIR Male MAPE 1.0005175 0.9922806 0.9917674
GBR_NIR Male MedAE 1.0207529 1.0073527 0.9868722
GBR_NIR Male sMAPE 0.9979392 0.9946914 0.9967455
GBR_NP Male MSE 1.2405197 1.2245703 0.9871430
GBR_NP Male RMSE 1.1137862 1.1066031 0.9935507
GBR_NP Male MAE 1.1142642 1.1061963 0.9927594
GBR_NP Male MAPE 1.0449535 1.0419714 0.9971462
GBR_NP Male MedAE 1.0336586 1.0324783 0.9988582
GBR_NP Male sMAPE 1.0447255 1.0424414 0.9978138
GBR_SCO Male MSE 0.9993971 0.9455718 0.9461422
GBR_SCO Male RMSE 0.9996985 0.9724052 0.9726984
GBR_SCO Male MAE 0.9997393 0.9708064 0.9710596
GBR_SCO Male MAPE 0.9999672 0.9918936 0.9919261
GBR_SCO Male MedAE 0.9989993 0.9993401 1.0003412
GBR_SCO Male sMAPE 0.9999514 0.9950333 0.9950816
GBRTENW Male MSE 1.2044384 1.1673581 0.9692137
GBRTENW Male RMSE 1.0974691 1.0804435 0.9844865
GBRTENW Male MAE 1.0964854 1.0782514 0.9833705
GBRTENW Male MAPE 1.0403494 1.0330326 0.9929670
GBRTENW Male MedAE 1.0413176 1.0454427 1.0039614
GBRTENW Male sMAPE 1.0396709 1.0342145 0.9947518
HUN Male MSE 1.0079975 6.5577268 6.5056973
HUN Male RMSE 1.0039908 2.5608059 2.5506269
HUN Male MAE 1.0108541 2.4915971 2.4648435
HUN Male MAPE 1.0263799 1.4943121 1.4559054
HUN Male MedAE 1.0276148 2.5320077 2.4639658
HUN Male sMAPE 1.0176060 1.4036286 1.3793439
IRL Male MSE 1.0057477 0.9784318 0.9728402
IRL Male RMSE 1.0028697 0.9891571 0.9863266
IRL Male MAE 1.0009747 0.9870917 0.9861306
IRL Male MAPE 1.0034027 0.9976149 0.9942318
IRL Male MedAE 1.0247835 1.0322735 1.0073089
IRL Male sMAPE 1.0041089 1.0021245 0.9980237
ISL Male MSE 0.9999219 1.6593351 1.6594647
ISL Male RMSE 0.9999610 1.2881518 1.2882021
ISL Male MAE 0.9996564 1.5028374 1.5033539
ISL Male MAPE 0.9983123 1.2151109 1.2171651
ISL Male MedAE 0.9985498 1.2353607 1.2371548
ISL Male sMAPE 1.0000730 1.0678978 1.0678199
ITA Male MSE 1.0412094 1.0451167 1.0037526
ITA Male RMSE 1.0203967 1.0223095 1.0018745
ITA Male MAE 1.0435149 1.0462512 1.0026222
ITA Male MAPE 1.0845720 1.0846192 1.0000436
ITA Male MedAE 1.1156616 1.1137137 0.9982541
ITA Male sMAPE 1.0574314 1.0578533 1.0003989
JPN Male MSE 1.0269112 1.0250167 0.9981551
JPN Male RMSE 1.0133663 1.0124311 0.9990771
JPN Male MAE 1.0302489 1.0306845 1.0004228
JPN Male MAPE 1.0600125 1.0551981 0.9954582
JPN Male MedAE 1.0521639 1.0600131 1.0074601
JPN Male sMAPE 1.0563764 1.0489682 0.9929871
NLD Male MSE 1.0043458 0.9508932 0.9467786
NLD Male RMSE 1.0021706 0.9751375 0.9730255
NLD Male MAE 1.0027675 0.9761352 0.9734412
NLD Male MAPE 1.0011094 0.9791700 0.9780850
NLD Male MedAE 0.9959549 0.9554247 0.9593053
NLD Male sMAPE 1.0006283 0.9824981 0.9818812
NOR Male MSE 0.9990679 0.9798230 0.9807372
NOR Male RMSE 0.9995338 0.9898601 0.9903217
NOR Male MAE 0.9995366 0.9911854 0.9916449
NOR Male MAPE 0.9998687 0.9950817 0.9952124
NOR Male MedAE 1.0011691 0.9983792 0.9972133
NOR Male sMAPE 1.0002171 0.9962636 0.9960474
PRT Male MSE 1.0103037 1.0095486 0.9992526
PRT Male RMSE 1.0051386 1.0047630 0.9996262
PRT Male MAE 1.0129096 1.0152073 1.0022684
PRT Male MAPE 1.0616832 1.0612890 0.9996286
PRT Male MedAE 1.0489672 1.0603160 1.0108190
PRT Male sMAPE 1.0329866 1.0333644 1.0003657
SVK Male MSE 1.0045626 1.2194831 1.2139443
SVK Male RMSE 1.0022787 1.1043021 1.1017914
SVK Male MAE 1.0056149 1.1034754 1.0973141
SVK Male MAPE 1.0104993 1.0692000 1.0580907
SVK Male MedAE 1.0154656 1.0974855 1.0807707
SVK Male sMAPE 1.0067946 1.0527769 1.0456720
SWE Male MSE 1.0002996 1.1705680 1.1702173
SWE Male RMSE 1.0001498 1.0819279 1.0817658
SWE Male MAE 0.9984134 1.0885251 1.0902548
SWE Male MAPE 0.9980685 1.0292364 1.0312282
SWE Male MedAE 0.9840340 1.0493210 1.0663462
SWE Male sMAPE 0.9994222 1.0185950 1.0191838
USA Male MSE 0.9572121 0.8926603 0.9325627
USA Male RMSE 0.9783722 0.9448070 0.9656928
USA Male MAE 0.9891366 0.9662237 0.9768354
USA Male MAPE 1.0480250 1.0524763 1.0042473
USA Male MedAE 1.0146862 1.0314954 1.0165659
USA Male sMAPE 1.0362115 1.0446311 1.0081253
write.csv(RatioTable, file.path(output_dir, "ratio_table.csv"), row.names = FALSE)

Win counts

WinCounts <- MetricsTable %>%
  pivot_longer(cols = c(MSE, RMSE, MAE, MAPE, MedAE, sMAPE),
               names_to = "ErrorMetric", values_to = "Value") %>%
  group_by(Country, Gender, ErrorMetric) %>%
  slice_min(Value, n = 1, with_ties = FALSE) %>%
  ungroup() %>%
  count(ErrorMetric, Model, name = "Number_of_wins") %>%
  arrange(ErrorMetric, desc(Number_of_wins))

kable(WinCounts, caption = "Number of populations for which each model has the lowest error.")
Number of populations for which each model has the lowest error.
ErrorMetric Model Number_of_wins
MAE PCA-GEE+C 28
MAE PCA-GEE 17
MAE LC 11
MAPE PCA-GEE 26
MAPE PCA-GEE+C 26
MAPE LC 4
MSE PCA-GEE+C 27
MSE PCA-GEE 17
MSE LC 12
MedAE PCA-GEE+C 32
MedAE PCA-GEE 15
MedAE LC 9
RMSE PCA-GEE+C 27
RMSE PCA-GEE 17
RMSE LC 12
sMAPE PCA-GEE+C 28
sMAPE PCA-GEE 24
sMAPE LC 4

Win counts by country, gender, and age

For each country, gender, and single age, which model gives the smallest forecasting error over the test years?
For each (Country, Gender, Age, ErrorMetric) combination, the winning model is the one with the smallest error.

AgeMetricsTable <- CellErrors %>%
  group_by(Country, Gender, Age, Model) %>%
  summarise(
    MSE = mean(SquaredError, na.rm = TRUE),
    RMSE = sqrt(mean(SquaredError, na.rm = TRUE)),
    MAE = mean(AbsError, na.rm = TRUE),
    MAPE = mean(APE, na.rm = TRUE),
    MedAE = median(AbsError, na.rm = TRUE),
    sMAPE = mean(sAPE, na.rm = TRUE),
    .groups = "drop"
  )

AgeWinDetails <- AgeMetricsTable %>%
  pivot_longer(
    cols = c(MSE, RMSE, MAE, MAPE, MedAE, sMAPE),
    names_to = "ErrorMetric",
    values_to = "Value"
  ) %>%
  group_by(Country, Gender, Age, ErrorMetric) %>%
  slice_min(Value, n = 1, with_ties = FALSE) %>%
  ungroup() %>%
  arrange(Country, Gender, Age, ErrorMetric)

AgeWinCounts <- AgeWinDetails %>%
  count(ErrorMetric, Model, name = "Number_of_country_gender_age_wins") %>%
  group_by(ErrorMetric) %>%
  mutate(
    Percentage = 100 * Number_of_country_gender_age_wins / sum(Number_of_country_gender_age_wins)
  ) %>%
  ungroup() %>%
  arrange(ErrorMetric, desc(Number_of_country_gender_age_wins))

# Table by age:
# For age 0, count wins over all countries and both genders;
# for age 1, count wins over all countries and both genders; and so on.
# The count is done separately for each error metric.

AgeWinCountsByAgeMetric <- AgeWinDetails %>%
  count(Age, ErrorMetric, Model, name = "Number_of_wins") %>%
  group_by(Age, ErrorMetric) %>%
  mutate(
    Total_comparisons = sum(Number_of_wins),
    Percentage = 100 * Number_of_wins / Total_comparisons
  ) %>%
  ungroup() %>%
  arrange(ErrorMetric, Age, desc(Number_of_wins))

# A wide version
AgeWinCountsByAgeMetricWide <- AgeWinCountsByAgeMetric %>%
  select(Age, ErrorMetric, Model, Number_of_wins) %>%
  pivot_wider(
    names_from = Model,
    values_from = Number_of_wins,
    values_fill = 0
  ) %>%
  arrange(ErrorMetric, Age)

# Detailed table: for each country, gender, and age, count how many error metrics
# are won by each model. Since we use six metrics, the counts are between 0 and 6.
AgeWinCountsByCountryGenderAge <- AgeWinDetails %>%
  count(Country, Gender, Age, Model, name = "Number_of_metric_wins") %>%
  group_by(Country, Gender, Age) %>%
  mutate(
    Percentage = 100 * Number_of_metric_wins / sum(Number_of_metric_wins)
  ) %>%
  ungroup() %>%
  arrange(Country, Gender, Age, desc(Number_of_metric_wins))

# Same information, but separated by error metric. 
AgeWinCountsByMetricCountryGenderAge <- AgeWinDetails %>%
  count(ErrorMetric, Country, Gender, Age, Model, name = "Win") %>%
  arrange(ErrorMetric, Country, Gender, Age, Model)

kable(
  AgeWinCounts,
  digits = 2,
  caption = "Number of country-gender-age combinations for which each model has the lowest error."
)
Number of country-gender-age combinations for which each model has the lowest error.
ErrorMetric Model Number_of_country_gender_age_wins Percentage
MAE PCA-GEE+C 2214 43.45
MAE PCA-GEE 1460 28.65
MAE LC 1422 27.90
MAPE PCA-GEE+C 2251 44.17
MAPE PCA-GEE 1449 28.43
MAPE LC 1396 27.39
MSE PCA-GEE+C 2129 41.78
MSE PCA-GEE 1516 29.75
MSE LC 1451 28.47
MedAE PCA-GEE+C 2202 43.21
MedAE PCA-GEE 1451 28.47
MedAE LC 1443 28.32
RMSE PCA-GEE+C 2129 41.78
RMSE PCA-GEE 1516 29.75
RMSE LC 1451 28.47
sMAPE PCA-GEE+C 2229 43.74
sMAPE LC 1437 28.20
sMAPE PCA-GEE 1430 28.06
kable(
  AgeWinCountsByAgeMetricWide,
  digits = 0,
  caption = "Age-specific win counts by metric. For each age and metric, wins are counted over all countries and both genders."
)
Age-specific win counts by metric. For each age and metric, wins are counted over all countries and both genders.
Age ErrorMetric PCA-GEE+C PCA-GEE LC
0 MAE 32 18 6
1 MAE 18 14 24
2 MAE 19 15 22
3 MAE 21 12 23
4 MAE 18 18 20
5 MAE 21 16 19
6 MAE 24 15 17
7 MAE 19 12 25
8 MAE 19 21 16
9 MAE 18 15 23
10 MAE 20 18 18
11 MAE 13 19 24
12 MAE 20 15 21
13 MAE 18 17 21
14 MAE 14 25 17
15 MAE 19 21 16
16 MAE 20 18 18
17 MAE 23 13 20
18 MAE 16 21 19
19 MAE 21 19 16
20 MAE 19 19 18
21 MAE 19 24 13
22 MAE 19 18 19
23 MAE 16 26 14
24 MAE 15 25 16
25 MAE 18 21 17
26 MAE 21 22 13
27 MAE 18 20 18
28 MAE 19 23 14
29 MAE 21 23 12
30 MAE 19 26 11
31 MAE 21 26 9
32 MAE 25 18 13
33 MAE 26 23 7
34 MAE 33 16 7
35 MAE 30 20 6
36 MAE 26 21 9
37 MAE 27 19 10
38 MAE 30 16 10
39 MAE 29 14 13
40 MAE 26 15 15
41 MAE 29 12 15
42 MAE 28 14 14
43 MAE 30 16 10
44 MAE 28 10 18
45 MAE 28 13 15
46 MAE 31 11 14
47 MAE 34 11 11
48 MAE 33 9 14
49 MAE 29 14 13
50 MAE 32 13 11
51 MAE 27 13 16
52 MAE 29 12 15
53 MAE 25 14 17
54 MAE 24 18 14
55 MAE 24 12 20
56 MAE 29 10 17
57 MAE 25 18 13
58 MAE 21 22 13
59 MAE 25 15 16
60 MAE 28 16 12
61 MAE 28 15 13
62 MAE 25 20 11
63 MAE 26 17 13
64 MAE 27 14 15
65 MAE 26 15 15
66 MAE 26 15 15
67 MAE 26 15 15
68 MAE 23 16 17
69 MAE 25 12 19
70 MAE 26 14 16
71 MAE 23 14 19
72 MAE 20 13 23
73 MAE 22 16 18
74 MAE 27 10 19
75 MAE 26 12 18
76 MAE 28 10 18
77 MAE 26 14 16
78 MAE 30 9 17
79 MAE 29 12 15
80 MAE 25 11 20
81 MAE 29 13 14
82 MAE 28 15 13
83 MAE 28 18 10
84 MAE 31 10 15
85 MAE 27 13 16
86 MAE 25 16 15
87 MAE 27 13 16
88 MAE 27 11 18
89 MAE 25 17 14
90 MAE 24 10 22
0 MAPE 31 17 8
1 MAPE 21 14 21
2 MAPE 18 14 24
3 MAPE 14 18 24
4 MAPE 23 17 16
5 MAPE 20 18 18
6 MAPE 25 13 18
7 MAPE 22 12 22
8 MAPE 19 20 17
9 MAPE 16 19 21
10 MAPE 22 17 17
11 MAPE 18 17 21
12 MAPE 21 10 25
13 MAPE 18 18 20
14 MAPE 15 27 14
15 MAPE 20 19 17
16 MAPE 19 20 17
17 MAPE 20 16 20
18 MAPE 15 19 22
19 MAPE 21 19 16
20 MAPE 19 21 16
21 MAPE 17 22 17
22 MAPE 18 18 20
23 MAPE 15 26 15
24 MAPE 15 24 17
25 MAPE 18 22 16
26 MAPE 19 21 16
27 MAPE 19 20 17
28 MAPE 22 23 11
29 MAPE 21 23 12
30 MAPE 19 27 10
31 MAPE 25 25 6
32 MAPE 26 18 12
33 MAPE 26 25 5
34 MAPE 32 14 10
35 MAPE 32 19 5
36 MAPE 29 19 8
37 MAPE 28 18 10
38 MAPE 32 16 8
39 MAPE 29 14 13
40 MAPE 29 15 12
41 MAPE 30 13 13
42 MAPE 30 13 13
43 MAPE 31 15 10
44 MAPE 29 10 17
45 MAPE 29 13 14
46 MAPE 31 12 13
47 MAPE 33 12 11
48 MAPE 32 10 14
49 MAPE 31 14 11
50 MAPE 32 13 11
51 MAPE 28 14 14
52 MAPE 29 12 15
53 MAPE 24 14 18
54 MAPE 24 18 14
55 MAPE 24 10 22
56 MAPE 29 12 15
57 MAPE 24 20 12
58 MAPE 21 22 13
59 MAPE 26 14 16
60 MAPE 28 15 13
61 MAPE 29 14 13
62 MAPE 26 19 11
63 MAPE 29 16 11
64 MAPE 27 14 15
65 MAPE 30 12 14
66 MAPE 27 13 16
67 MAPE 27 14 15
68 MAPE 25 14 17
69 MAPE 26 11 19
70 MAPE 27 13 16
71 MAPE 23 13 20
72 MAPE 21 12 23
73 MAPE 24 14 18
74 MAPE 26 11 19
75 MAPE 26 12 18
76 MAPE 27 11 18
77 MAPE 25 14 17
78 MAPE 30 9 17
79 MAPE 29 11 16
80 MAPE 25 11 20
81 MAPE 29 14 13
82 MAPE 28 16 12
83 MAPE 26 20 10
84 MAPE 30 10 16
85 MAPE 27 12 17
86 MAPE 25 16 15
87 MAPE 27 14 15
88 MAPE 27 11 18
89 MAPE 25 18 13
90 MAPE 25 10 21
0 MSE 32 17 7
1 MSE 20 14 22
2 MSE 18 14 24
3 MSE 18 11 27
4 MSE 20 13 23
5 MSE 21 15 20
6 MSE 25 13 18
7 MSE 16 15 25
8 MSE 20 18 18
9 MSE 16 16 24
10 MSE 18 18 20
11 MSE 12 18 26
12 MSE 23 11 22
13 MSE 16 16 24
14 MSE 15 25 16
15 MSE 16 22 18
16 MSE 18 19 19
17 MSE 22 13 21
18 MSE 13 24 19
19 MSE 19 21 16
20 MSE 18 21 17
21 MSE 19 25 12
22 MSE 16 21 19
23 MSE 14 28 14
24 MSE 15 26 15
25 MSE 17 21 18
26 MSE 17 22 17
27 MSE 16 21 19
28 MSE 19 24 13
29 MSE 16 25 15
30 MSE 16 28 12
31 MSE 20 25 11
32 MSE 21 20 15
33 MSE 22 25 9
34 MSE 28 18 10
35 MSE 25 22 9
36 MSE 24 21 11
37 MSE 26 18 12
38 MSE 31 17 8
39 MSE 27 16 13
40 MSE 25 17 14
41 MSE 26 14 16
42 MSE 26 16 14
43 MSE 28 17 11
44 MSE 27 13 16
45 MSE 28 13 15
46 MSE 30 12 14
47 MSE 30 14 12
48 MSE 32 10 14
49 MSE 30 15 11
50 MSE 28 16 12
51 MSE 25 17 14
52 MSE 29 15 12
53 MSE 26 14 16
54 MSE 23 16 17
55 MSE 23 13 20
56 MSE 28 9 19
57 MSE 25 19 12
58 MSE 21 22 13
59 MSE 24 16 16
60 MSE 27 15 14
61 MSE 30 14 12
62 MSE 27 18 11
63 MSE 26 17 13
64 MSE 29 13 14
65 MSE 28 13 15
66 MSE 27 16 13
67 MSE 27 16 13
68 MSE 23 14 19
69 MSE 25 14 17
70 MSE 26 14 16
71 MSE 22 15 19
72 MSE 21 12 23
73 MSE 25 14 17
74 MSE 26 12 18
75 MSE 24 14 18
76 MSE 27 13 16
77 MSE 23 16 17
78 MSE 28 12 16
79 MSE 27 14 15
80 MSE 26 13 17
81 MSE 28 15 13
82 MSE 27 17 12
83 MSE 26 19 11
84 MSE 30 11 15
85 MSE 29 12 15
86 MSE 27 14 15
87 MSE 29 12 15
88 MSE 25 13 18
89 MSE 23 18 15
90 MSE 22 11 23
0 MedAE 32 17 7
1 MedAE 18 17 21
2 MedAE 17 12 27
3 MedAE 26 11 19
4 MedAE 17 15 24
5 MedAE 19 7 30
6 MedAE 18 19 19
7 MedAE 22 8 26
8 MedAE 20 18 18
9 MedAE 20 18 18
10 MedAE 17 20 19
11 MedAE 17 17 22
12 MedAE 28 12 16
13 MedAE 17 20 19
14 MedAE 19 22 15
15 MedAE 18 19 19
16 MedAE 19 16 21
17 MedAE 26 13 17
18 MedAE 15 20 21
19 MedAE 18 21 17
20 MedAE 17 22 17
21 MedAE 18 26 12
22 MedAE 20 17 19
23 MedAE 20 24 12
24 MedAE 20 21 15
25 MedAE 15 22 19
26 MedAE 24 19 13
27 MedAE 20 17 19
28 MedAE 24 21 11
29 MedAE 22 21 13
30 MedAE 17 31 8
31 MedAE 23 24 9
32 MedAE 25 17 14
33 MedAE 24 26 6
34 MedAE 29 18 9
35 MedAE 28 20 8
36 MedAE 28 20 8
37 MedAE 28 17 11
38 MedAE 32 14 10
39 MedAE 31 13 12
40 MedAE 29 14 13
41 MedAE 29 12 15
42 MedAE 28 17 11
43 MedAE 27 16 13
44 MedAE 31 8 17
45 MedAE 29 12 15
46 MedAE 29 9 18
47 MedAE 29 13 14
48 MedAE 29 12 15
49 MedAE 28 12 16
50 MedAE 29 14 13
51 MedAE 29 10 17
52 MedAE 33 12 11
53 MedAE 24 14 18
54 MedAE 26 18 12
55 MedAE 26 11 19
56 MedAE 25 11 20
57 MedAE 24 18 14
58 MedAE 22 18 16
59 MedAE 28 12 16
60 MedAE 31 12 13
61 MedAE 29 14 13
62 MedAE 24 19 13
63 MedAE 28 13 15
64 MedAE 25 13 18
65 MedAE 23 19 14
66 MedAE 26 15 15
67 MedAE 23 14 19
68 MedAE 20 18 18
69 MedAE 21 17 18
70 MedAE 22 15 19
71 MedAE 21 16 19
72 MedAE 20 16 20
73 MedAE 25 13 18
74 MedAE 24 13 19
75 MedAE 25 14 17
76 MedAE 26 13 17
77 MedAE 24 18 14
78 MedAE 30 8 18
79 MedAE 28 13 15
80 MedAE 26 12 18
81 MedAE 26 16 14
82 MedAE 27 14 15
83 MedAE 26 20 10
84 MedAE 30 11 15
85 MedAE 28 16 12
86 MedAE 27 13 16
87 MedAE 24 16 16
88 MedAE 25 11 20
89 MedAE 23 22 11
90 MedAE 23 12 21
0 RMSE 32 17 7
1 RMSE 20 14 22
2 RMSE 18 14 24
3 RMSE 18 11 27
4 RMSE 20 13 23
5 RMSE 21 15 20
6 RMSE 25 13 18
7 RMSE 16 15 25
8 RMSE 20 18 18
9 RMSE 16 16 24
10 RMSE 18 18 20
11 RMSE 12 18 26
12 RMSE 23 11 22
13 RMSE 16 16 24
14 RMSE 15 25 16
15 RMSE 16 22 18
16 RMSE 18 19 19
17 RMSE 22 13 21
18 RMSE 13 24 19
19 RMSE 19 21 16
20 RMSE 18 21 17
21 RMSE 19 25 12
22 RMSE 16 21 19
23 RMSE 14 28 14
24 RMSE 15 26 15
25 RMSE 17 21 18
26 RMSE 17 22 17
27 RMSE 16 21 19
28 RMSE 19 24 13
29 RMSE 16 25 15
30 RMSE 16 28 12
31 RMSE 20 25 11
32 RMSE 21 20 15
33 RMSE 22 25 9
34 RMSE 28 18 10
35 RMSE 25 22 9
36 RMSE 24 21 11
37 RMSE 26 18 12
38 RMSE 31 17 8
39 RMSE 27 16 13
40 RMSE 25 17 14
41 RMSE 26 14 16
42 RMSE 26 16 14
43 RMSE 28 17 11
44 RMSE 27 13 16
45 RMSE 28 13 15
46 RMSE 30 12 14
47 RMSE 30 14 12
48 RMSE 32 10 14
49 RMSE 30 15 11
50 RMSE 28 16 12
51 RMSE 25 17 14
52 RMSE 29 15 12
53 RMSE 26 14 16
54 RMSE 23 16 17
55 RMSE 23 13 20
56 RMSE 28 9 19
57 RMSE 25 19 12
58 RMSE 21 22 13
59 RMSE 24 16 16
60 RMSE 27 15 14
61 RMSE 30 14 12
62 RMSE 27 18 11
63 RMSE 26 17 13
64 RMSE 29 13 14
65 RMSE 28 13 15
66 RMSE 27 16 13
67 RMSE 27 16 13
68 RMSE 23 14 19
69 RMSE 25 14 17
70 RMSE 26 14 16
71 RMSE 22 15 19
72 RMSE 21 12 23
73 RMSE 25 14 17
74 RMSE 26 12 18
75 RMSE 24 14 18
76 RMSE 27 13 16
77 RMSE 23 16 17
78 RMSE 28 12 16
79 RMSE 27 14 15
80 RMSE 26 13 17
81 RMSE 28 15 13
82 RMSE 27 17 12
83 RMSE 26 19 11
84 RMSE 30 11 15
85 RMSE 29 12 15
86 RMSE 27 14 15
87 RMSE 29 12 15
88 RMSE 25 13 18
89 RMSE 23 18 15
90 RMSE 22 11 23
0 sMAPE 30 18 8
1 sMAPE 20 14 22
2 sMAPE 21 11 24
3 sMAPE 18 12 26
4 sMAPE 20 15 21
5 sMAPE 20 15 21
6 sMAPE 27 12 17
7 sMAPE 18 14 24
8 sMAPE 20 18 18
9 sMAPE 16 14 26
10 sMAPE 22 16 18
11 sMAPE 11 19 26
12 sMAPE 24 12 20
13 sMAPE 19 18 19
14 sMAPE 17 24 15
15 sMAPE 20 21 15
16 sMAPE 20 18 18
17 sMAPE 22 12 22
18 sMAPE 15 22 19
19 sMAPE 21 19 16
20 sMAPE 21 17 18
21 sMAPE 19 23 14
22 sMAPE 18 18 20
23 sMAPE 17 26 13
24 sMAPE 14 26 16
25 sMAPE 18 21 17
26 sMAPE 20 22 14
27 sMAPE 18 20 18
28 sMAPE 19 23 14
29 sMAPE 21 23 12
30 sMAPE 21 26 9
31 sMAPE 22 25 9
32 sMAPE 26 18 12
33 sMAPE 24 25 7
34 sMAPE 33 16 7
35 sMAPE 30 20 6
36 sMAPE 26 21 9
37 sMAPE 28 19 9
38 sMAPE 31 17 8
39 sMAPE 28 14 14
40 sMAPE 28 14 14
41 sMAPE 30 12 14
42 sMAPE 27 15 14
43 sMAPE 30 15 11
44 sMAPE 28 10 18
45 sMAPE 28 13 15
46 sMAPE 31 11 14
47 sMAPE 32 13 11
48 sMAPE 32 10 14
49 sMAPE 30 14 12
50 sMAPE 30 14 12
51 sMAPE 26 14 16
52 sMAPE 29 12 15
53 sMAPE 24 14 18
54 sMAPE 24 17 15
55 sMAPE 24 11 21
56 sMAPE 29 11 16
57 sMAPE 25 18 13
58 sMAPE 21 21 14
59 sMAPE 25 15 16
60 sMAPE 27 16 13
61 sMAPE 29 14 13
62 sMAPE 26 19 11
63 sMAPE 28 15 13
64 sMAPE 28 14 14
65 sMAPE 28 14 14
66 sMAPE 27 13 16
67 sMAPE 27 14 15
68 sMAPE 24 13 19
69 sMAPE 25 12 19
70 sMAPE 27 13 16
71 sMAPE 24 13 19
72 sMAPE 21 12 23
73 sMAPE 23 15 18
74 sMAPE 26 11 19
75 sMAPE 25 12 19
76 sMAPE 26 12 18
77 sMAPE 25 15 16
78 sMAPE 30 9 17
79 sMAPE 30 11 15
80 sMAPE 25 11 20
81 sMAPE 29 13 14
82 sMAPE 28 15 13
83 sMAPE 27 19 10
84 sMAPE 31 10 15
85 sMAPE 27 12 17
86 sMAPE 25 14 17
87 sMAPE 27 13 16
88 sMAPE 27 11 18
89 sMAPE 25 17 14
90 sMAPE 24 10 22
kable(
  head(AgeWinCountsByCountryGenderAge, 30),
  digits = 2,
  caption = "First rows of the detailed country-gender-age win-count table. The full table is saved as a CSV file."
)
First rows of the detailed country-gender-age win-count table. The full table is saved as a CSV file.
Country Gender Age Model Number_of_metric_wins Percentage
AUS Female 0 PCA-GEE+C 6 100.00
AUS Female 1 LC 6 100.00
AUS Female 2 PCA-GEE 5 83.33
AUS Female 2 LC 1 16.67
AUS Female 3 PCA-GEE 5 83.33
AUS Female 3 LC 1 16.67
AUS Female 4 PCA-GEE 5 83.33
AUS Female 4 LC 1 16.67
AUS Female 5 PCA-GEE+C 4 66.67
AUS Female 5 LC 2 33.33
AUS Female 6 PCA-GEE 3 50.00
AUS Female 6 PCA-GEE+C 3 50.00
AUS Female 7 LC 5 83.33
AUS Female 7 PCA-GEE+C 1 16.67
AUS Female 8 PCA-GEE 3 50.00
AUS Female 8 PCA-GEE+C 2 33.33
AUS Female 8 LC 1 16.67
AUS Female 9 LC 5 83.33
AUS Female 9 PCA-GEE 1 16.67
AUS Female 10 PCA-GEE 6 100.00
AUS Female 11 PCA-GEE 6 100.00
AUS Female 12 LC 5 83.33
AUS Female 12 PCA-GEE+C 1 16.67
AUS Female 13 PCA-GEE 6 100.00
AUS Female 14 PCA-GEE 6 100.00
AUS Female 15 LC 4 66.67
AUS Female 15 PCA-GEE 2 33.33
AUS Female 16 LC 6 100.00
AUS Female 17 LC 6 100.00
AUS Female 18 LC 6 100.00
write.csv(AgeMetricsTable, file.path(output_dir, "metrics_by_country_gender_age_model.csv"), row.names = FALSE)
write.csv(AgeWinDetails, file.path(output_dir, "age_win_details.csv"), row.names = FALSE)
write.csv(AgeWinCounts, file.path(output_dir, "age_win_counts.csv"), row.names = FALSE)
write.csv(AgeWinCountsByAgeMetric, file.path(output_dir, "age_win_counts_by_age_metric_long.csv"), row.names = FALSE)
write.csv(AgeWinCountsByAgeMetricWide, file.path(output_dir, "age_win_counts_by_age_metric_wide.csv"), row.names = FALSE)
write.csv(AgeWinCountsByCountryGenderAge, file.path(output_dir, "age_win_counts_by_country_gender_age.csv"), row.names = FALSE)
write.csv(AgeWinCountsByMetricCountryGenderAge, file.path(output_dir, "age_win_counts_by_metric_country_gender_age.csv"), row.names = FALSE)

Win counts by age group

This coarser table is often easier to discuss in the paper than all 91 single ages.

AgeGroupWinCounts <- AgeWinDetails %>%
  mutate(
    AgeGroup = cut(
      Age,
      breaks = c(-1, 0, 20, 40, 60, 75, 90),
      labels = c("0", "1--20", "21--40", "41--60", "61--75", "76--90")
    )
  ) %>%
  count(ErrorMetric, Gender, AgeGroup, Model, name = "Number_of_wins") %>%
  group_by(ErrorMetric, Gender, AgeGroup) %>%
  mutate(Percentage = 100 * Number_of_wins / sum(Number_of_wins)) %>%
  ungroup() %>%
  arrange(ErrorMetric, Gender, AgeGroup, desc(Number_of_wins))

kable(
  AgeGroupWinCounts,
  digits = 2,
  caption = "Win counts by error metric, gender, age group, and model."
)
Win counts by error metric, gender, age group, and model.
ErrorMetric Gender AgeGroup Model Number_of_wins Percentage
MAE Female 0 PCA-GEE+C 17 60.71
MAE Female 0 LC 6 21.43
MAE Female 0 PCA-GEE 5 17.86
MAE Female 1–20 PCA-GEE 189 33.75
MAE Female 1–20 LC 186 33.21
MAE Female 1–20 PCA-GEE+C 185 33.04
MAE Female 21–40 PCA-GEE+C 227 40.54
MAE Female 21–40 PCA-GEE 191 34.11
MAE Female 21–40 LC 142 25.36
MAE Female 41–60 PCA-GEE+C 291 51.96
MAE Female 41–60 PCA-GEE 135 24.11
MAE Female 41–60 LC 134 23.93
MAE Female 61–75 PCA-GEE+C 187 44.52
MAE Female 61–75 LC 120 28.57
MAE Female 61–75 PCA-GEE 113 26.90
MAE Female 76–90 PCA-GEE+C 225 53.57
MAE Female 76–90 LC 118 28.10
MAE Female 76–90 PCA-GEE 77 18.33
MAE Male 0 PCA-GEE+C 15 53.57
MAE Male 0 PCA-GEE 13 46.43
MAE Male 1–20 LC 211 37.68
MAE Male 1–20 PCA-GEE+C 195 34.82
MAE Male 1–20 PCA-GEE 154 27.50
MAE Male 21–40 PCA-GEE+C 231 41.25
MAE Male 21–40 PCA-GEE 225 40.18
MAE Male 21–40 LC 104 18.57
MAE Male 41–60 PCA-GEE+C 268 47.86
MAE Male 41–60 LC 154 27.50
MAE Male 41–60 PCA-GEE 138 24.64
MAE Male 61–75 PCA-GEE+C 189 45.00
MAE Male 61–75 LC 126 30.00
MAE Male 61–75 PCA-GEE 105 25.00
MAE Male 76–90 PCA-GEE+C 184 43.81
MAE Male 76–90 LC 121 28.81
MAE Male 76–90 PCA-GEE 115 27.38
MAPE Female 0 PCA-GEE+C 17 60.71
MAPE Female 0 LC 6 21.43
MAPE Female 0 PCA-GEE 5 17.86
MAPE Female 1–20 PCA-GEE+C 195 34.82
MAPE Female 1–20 PCA-GEE 185 33.04
MAPE Female 1–20 LC 180 32.14
MAPE Female 21–40 PCA-GEE+C 242 43.21
MAPE Female 21–40 PCA-GEE 181 32.32
MAPE Female 21–40 LC 137 24.46
MAPE Female 41–60 PCA-GEE+C 299 53.39
MAPE Female 41–60 PCA-GEE 137 24.46
MAPE Female 41–60 LC 124 22.14
MAPE Female 61–75 PCA-GEE+C 203 48.33
MAPE Female 61–75 LC 117 27.86
MAPE Female 61–75 PCA-GEE 100 23.81
MAPE Female 76–90 PCA-GEE+C 225 53.57
MAPE Female 76–90 LC 114 27.14
MAPE Female 76–90 PCA-GEE 81 19.29
MAPE Male 0 PCA-GEE+C 14 50.00
MAPE Male 0 PCA-GEE 12 42.86
MAPE Male 0 LC 2 7.14
MAPE Male 1–20 LC 206 36.79
MAPE Male 1–20 PCA-GEE+C 191 34.11
MAPE Male 1–20 PCA-GEE 163 29.11
MAPE Male 21–40 PCA-GEE+C 229 40.89
MAPE Male 21–40 PCA-GEE 228 40.71
MAPE Male 21–40 LC 103 18.39
MAPE Male 41–60 PCA-GEE+C 266 47.50
MAPE Male 41–60 LC 155 27.68
MAPE Male 41–60 PCA-GEE 139 24.82
MAPE Male 61–75 PCA-GEE+C 190 45.24
MAPE Male 61–75 LC 128 30.48
MAPE Male 61–75 PCA-GEE 102 24.29
MAPE Male 76–90 PCA-GEE+C 180 42.86
MAPE Male 76–90 LC 124 29.52
MAPE Male 76–90 PCA-GEE 116 27.62
MSE Female 0 PCA-GEE+C 16 57.14
MSE Female 0 LC 6 21.43
MSE Female 0 PCA-GEE 6 21.43
MSE Female 1–20 LC 206 36.79
MSE Female 1–20 PCA-GEE 185 33.04
MSE Female 1–20 PCA-GEE+C 169 30.18
MSE Female 21–40 PCA-GEE+C 214 38.21
MSE Female 21–40 PCA-GEE 199 35.54
MSE Female 21–40 LC 147 26.25
MSE Female 41–60 PCA-GEE+C 269 48.04
MSE Female 41–60 PCA-GEE 157 28.04
MSE Female 41–60 LC 134 23.93
MSE Female 61–75 PCA-GEE+C 189 45.00
MSE Female 61–75 LC 117 27.86
MSE Female 61–75 PCA-GEE 114 27.14
MSE Female 76–90 PCA-GEE+C 227 54.05
MSE Female 76–90 LC 111 26.43
MSE Female 76–90 PCA-GEE 82 19.52
MSE Male 0 PCA-GEE+C 16 57.14
MSE Male 0 PCA-GEE 11 39.29
MSE Male 0 LC 1 3.57
MSE Male 1–20 LC 213 38.04
MSE Male 1–20 PCA-GEE+C 195 34.82
MSE Male 1–20 PCA-GEE 152 27.14
MSE Male 21–40 PCA-GEE 241 43.04
MSE Male 21–40 PCA-GEE+C 200 35.71
MSE Male 21–40 LC 119 21.25
MSE Male 41–60 PCA-GEE+C 267 47.68
MSE Male 41–60 LC 154 27.50
MSE Male 41–60 PCA-GEE 139 24.82
MSE Male 61–75 PCA-GEE+C 197 46.90
MSE Male 61–75 LC 121 28.81
MSE Male 61–75 PCA-GEE 102 24.29
MSE Male 76–90 PCA-GEE+C 170 40.48
MSE Male 76–90 PCA-GEE 128 30.48
MSE Male 76–90 LC 122 29.05
MedAE Female 0 PCA-GEE+C 17 60.71
MedAE Female 0 PCA-GEE 6 21.43
MedAE Female 0 LC 5 17.86
MedAE Female 1–20 LC 194 34.64
MedAE Female 1–20 PCA-GEE+C 191 34.11
MedAE Female 1–20 PCA-GEE 175 31.25
MedAE Female 21–40 PCA-GEE+C 241 43.04
MedAE Female 21–40 PCA-GEE 178 31.79
MedAE Female 21–40 LC 141 25.18
MedAE Female 41–60 PCA-GEE+C 290 51.79
MedAE Female 41–60 LC 137 24.46
MedAE Female 41–60 PCA-GEE 133 23.75
MedAE Female 61–75 PCA-GEE+C 190 45.24
MedAE Female 61–75 LC 117 27.86
MedAE Female 61–75 PCA-GEE 113 26.90
MedAE Female 76–90 PCA-GEE+C 216 51.43
MedAE Female 76–90 LC 120 28.57
MedAE Female 76–90 PCA-GEE 84 20.00
MedAE Male 0 PCA-GEE+C 15 53.57
MedAE Male 0 PCA-GEE 11 39.29
MedAE Male 0 LC 2 7.14
MedAE Male 1–20 LC 211 37.68
MedAE Male 1–20 PCA-GEE+C 197 35.18
MedAE Male 1–20 PCA-GEE 152 27.14
MedAE Male 21–40 PCA-GEE+C 236 42.14
MedAE Male 21–40 PCA-GEE 224 40.00
MedAE Male 21–40 LC 100 17.86
MedAE Male 41–60 PCA-GEE+C 266 47.50
MedAE Male 41–60 LC 166 29.64
MedAE Male 41–60 PCA-GEE 128 22.86
MedAE Male 61–75 PCA-GEE+C 166 39.52
MedAE Male 61–75 LC 138 32.86
MedAE Male 61–75 PCA-GEE 116 27.62
MedAE Male 76–90 PCA-GEE+C 177 42.14
MedAE Male 76–90 PCA-GEE 131 31.19
MedAE Male 76–90 LC 112 26.67
RMSE Female 0 PCA-GEE+C 16 57.14
RMSE Female 0 LC 6 21.43
RMSE Female 0 PCA-GEE 6 21.43
RMSE Female 1–20 LC 206 36.79
RMSE Female 1–20 PCA-GEE 185 33.04
RMSE Female 1–20 PCA-GEE+C 169 30.18
RMSE Female 21–40 PCA-GEE+C 214 38.21
RMSE Female 21–40 PCA-GEE 199 35.54
RMSE Female 21–40 LC 147 26.25
RMSE Female 41–60 PCA-GEE+C 269 48.04
RMSE Female 41–60 PCA-GEE 157 28.04
RMSE Female 41–60 LC 134 23.93
RMSE Female 61–75 PCA-GEE+C 189 45.00
RMSE Female 61–75 LC 117 27.86
RMSE Female 61–75 PCA-GEE 114 27.14
RMSE Female 76–90 PCA-GEE+C 227 54.05
RMSE Female 76–90 LC 111 26.43
RMSE Female 76–90 PCA-GEE 82 19.52
RMSE Male 0 PCA-GEE+C 16 57.14
RMSE Male 0 PCA-GEE 11 39.29
RMSE Male 0 LC 1 3.57
RMSE Male 1–20 LC 213 38.04
RMSE Male 1–20 PCA-GEE+C 195 34.82
RMSE Male 1–20 PCA-GEE 152 27.14
RMSE Male 21–40 PCA-GEE 241 43.04
RMSE Male 21–40 PCA-GEE+C 200 35.71
RMSE Male 21–40 LC 119 21.25
RMSE Male 41–60 PCA-GEE+C 267 47.68
RMSE Male 41–60 LC 154 27.50
RMSE Male 41–60 PCA-GEE 139 24.82
RMSE Male 61–75 PCA-GEE+C 197 46.90
RMSE Male 61–75 LC 121 28.81
RMSE Male 61–75 PCA-GEE 102 24.29
RMSE Male 76–90 PCA-GEE+C 170 40.48
RMSE Male 76–90 PCA-GEE 128 30.48
RMSE Male 76–90 LC 122 29.05
sMAPE Female 0 PCA-GEE+C 15 53.57
sMAPE Female 0 PCA-GEE 7 25.00
sMAPE Female 0 LC 6 21.43
sMAPE Female 1–20 LC 192 34.29
sMAPE Female 1–20 PCA-GEE+C 189 33.75
sMAPE Female 1–20 PCA-GEE 179 31.96
sMAPE Female 21–40 PCA-GEE+C 231 41.25
sMAPE Female 21–40 PCA-GEE 189 33.75
sMAPE Female 21–40 LC 140 25.00
sMAPE Female 41–60 PCA-GEE+C 286 51.07
sMAPE Female 41–60 PCA-GEE 140 25.00
sMAPE Female 41–60 LC 134 23.93
sMAPE Female 61–75 PCA-GEE+C 196 46.67
sMAPE Female 61–75 LC 122 29.05
sMAPE Female 61–75 PCA-GEE 102 24.29
sMAPE Female 76–90 PCA-GEE+C 224 53.33
sMAPE Female 76–90 LC 120 28.57
sMAPE Female 76–90 PCA-GEE 76 18.10
sMAPE Male 0 PCA-GEE+C 15 53.57
sMAPE Male 0 PCA-GEE 11 39.29
sMAPE Male 0 LC 2 7.14
sMAPE Male 1–20 LC 213 38.04
sMAPE Male 1–20 PCA-GEE+C 203 36.25
sMAPE Male 1–20 PCA-GEE 144 25.71
sMAPE Male 21–40 PCA-GEE+C 230 41.07
sMAPE Male 21–40 PCA-GEE 228 40.71
sMAPE Male 21–40 LC 102 18.21
sMAPE Male 41–60 PCA-GEE+C 266 47.50
sMAPE Male 41–60 LC 158 28.21
sMAPE Male 41–60 PCA-GEE 136 24.29
sMAPE Male 61–75 PCA-GEE+C 192 45.71
sMAPE Male 61–75 LC 126 30.00
sMAPE Male 61–75 PCA-GEE 102 24.29
sMAPE Male 76–90 PCA-GEE+C 182 43.33
sMAPE Male 76–90 LC 122 29.05
sMAPE Male 76–90 PCA-GEE 116 27.62
write.csv(AgeGroupWinCounts, file.path(output_dir, "age_group_win_counts.csv"), row.names = FALSE)

Plots

Error ratios by country

RatioLong <- RatioTable %>%
  select(Country, Gender, ErrorMetric, `LC / PCA-GEE`, `LC / PCA-GEE+C`, `PCA-GEE / PCA-GEE+C`) %>%
  pivot_longer(cols = c(`LC / PCA-GEE`, `LC / PCA-GEE+C`, `PCA-GEE / PCA-GEE+C`),
               names_to = "Comparison", values_to = "Ratio") %>%
  mutate(
    Direction = ifelse(Ratio >= 1, "Ratio >= 1", "Ratio < 1"),
    Shape = ifelse(Ratio >= 1, "Up", "Down")
  )

# Interpretation:
#   Ratio > 1: the denominator model has the smaller error.
#   Ratio < 1: the numerator model has the smaller error.
# Green upward triangles therefore indicate improvement of the denominator model.
# Red downward triangles indicate that the numerator model performs better.

p_ratio <- ggplot(RatioLong, aes(x = Country, y = Ratio)) +
  geom_hline(yintercept = 1, linetype = "dashed", linewidth = 0.4) +
  geom_point(
    aes(shape = Shape, color = Direction, fill = Direction),
    size = 2.8,
    stroke = 0.5
  ) +
  scale_shape_manual(
    values = c("Up" = 24, "Down" = 25),
    labels = c("Up" = "Ratio >= 1", "Down" = "Ratio < 1")
  ) +
  scale_color_manual(
    values = c("Ratio >= 1" = "green", "Ratio < 1" = "red")
  ) +
  scale_fill_manual(
    values = c("Ratio >= 1" = "green", "Ratio < 1" = "red")
  ) +
  facet_grid(ErrorMetric + Comparison ~ Gender, scales = "free_y") +
  theme_bw() +
  theme(
  axis.text.x = element_text(angle = 90, hjust = 1, size = 6),
  axis.text.y = element_text(size = 6),
  strip.text.x = element_text(size = 9),
  strip.text.y = element_text(size = 2.5),
  legend.position = "bottom",
  plot.title = element_text(size = 12),
  plot.subtitle = element_text(size = 9)
) +
  guides(
    shape = guide_legend(title = "Error ratio"),
    color = guide_legend(title = "Error ratio"),
    fill = guide_legend(title = "Error ratio")
  ) +
  labs(
    x = NULL,
    y = "Error ratio",
    title = "Error ratios by country, gender, model comparison, and error metric",
    subtitle = "Green upward triangles: ratio >= 1, denominator model has smaller error; red downward triangles: ratio < 1"
  )

print(p_ratio)

ggsave(file.path(output_dir, "error_ratio_plot.pdf"), plot = p_ratio, width = 16, height = 12)

RMSE by gender

CellErrors %>%
  group_by(Gender, Model) %>%
  summarise(RMSE = sqrt(mean(SquaredError, na.rm = TRUE)), .groups = "drop") %>%
  ggplot(aes(x = Model, y = RMSE)) +
  geom_col() +
  facet_wrap(~ Gender, scales = "free_y") +
  labs(x = NULL, y = "RMSE", title = "RMSE by gender")

RMSE by age

AgeRMSE <- CellErrors %>%
  group_by(Age, Model) %>%
  summarise(RMSE = sqrt(mean(SquaredError, na.rm = TRUE)), .groups = "drop")

ggplot(AgeRMSE, aes(x = Age, y = RMSE, linetype = Model)) +
  geom_line(linewidth = 0.8) +
  labs(x = "Age", y = "RMSE", title = "Age-specific RMSE")

RMSE by age group

AgeGroupRMSE <- CellErrors %>%
  mutate(AgeGroup = cut(Age,
                        breaks = c(-1, 0, 20, 40, 60, 75, 90),
                        labels = c("0", "1--20", "21--40", "41--60", "61--75", "76--90"))) %>%
  group_by(AgeGroup, Model) %>%
  summarise(RMSE = sqrt(mean(SquaredError, na.rm = TRUE)),
            MAE = mean(AbsError, na.rm = TRUE),
            MAPE = mean(APE, na.rm = TRUE),
            .groups = "drop")


kable(AgeGroupRMSE, digits = 6, caption = "Error measures by age group and model.")
Error measures by age group and model.
AgeGroup Model RMSE MAE MAPE
0 LC 0.001386 0.001101 31.09834
0 PCA-GEE 0.001351 0.001062 29.99241
0 PCA-GEE+C 0.001249 0.001012 28.36039
1–20 LC 0.000150 0.000078 104.65590
1–20 PCA-GEE 0.000146 0.000077 103.96405
1–20 PCA-GEE+C 0.000144 0.000076 98.04287
21–40 LC 0.000531 0.000284 82.99614
21–40 PCA-GEE 0.000513 0.000274 81.18677
21–40 PCA-GEE+C 0.000466 0.000265 74.35950
41–60 LC 0.001944 0.000923 39.82611
41–60 PCA-GEE 0.001900 0.000904 39.14427
41–60 PCA-GEE+C 0.001621 0.000831 36.42306
61–75 LC 0.005797 0.003855 21.27661
61–75 PCA-GEE 0.005776 0.003830 21.09500
61–75 PCA-GEE+C 0.005300 0.003560 19.96963
76–90 LC 0.017552 0.012193 15.01832
76–90 PCA-GEE 0.017458 0.012074 14.87758
76–90 PCA-GEE+C 0.016393 0.011324 14.05975

Age-specific winning model plot

# This plot uses aggregation:
# for each age and metric, count how often each model wins over all countries and both genders.

ggplot(AgeWinCountsByAgeMetric, aes(x = Age, y = Percentage, color = Model, linetype = Model)) +
  geom_line(linewidth = 0.8) +
  facet_wrap(~ ErrorMetric, scales = "free_y") +
  scale_color_manual(
    values = c(
      "LC" = "black",
      "PCA-GEE" = "blue",
      "PCA-GEE+C" = "darkgreen"
    )
  ) +
  labs(
    x = "Age",
    y = "Percentage of wins",
    color = "Model",
    linetype = "Model",
    title = "Age-specific win shares by error metric",
    subtitle = "For each age and metric, wins are counted over all countries and both genders."
  )

ggsave(file.path(output_dir, "age_specific_win_shares_all_metrics.pdf"), width = 14, height = 9)
AgeWinRMSE <- AgeWinCountsByAgeMetric %>%
  filter(ErrorMetric == "RMSE")

ggplot(AgeWinRMSE, aes(x = Age, y = Number_of_wins, color = Model, linetype = Model)) +
  geom_line(linewidth = 0.8) +
  scale_color_manual(
    values = c(
      "LC" = "black",
      "PCA-GEE" = "blue",
      "PCA-GEE+C" = "darkgreen"
    )
  ) +
  labs(
    x = "Age",
    y = "Number of wins",
    color = "Model",
    linetype = "Model",
    title = "Age-specific win counts based on RMSE",
    subtitle = "For age 0, age 1, ..., age 90, wins are counted over all countries and both genders."
  )

ggsave(file.path(output_dir, "age_specific_win_counts_rmse.pdf"), width = 13, height = 7)

RMSE by calendar year

YearRMSE <- CellErrors %>%
  group_by(Year, Model) %>%
  summarise(RMSE = sqrt(mean(SquaredError, na.rm = TRUE)), .groups = "drop")

ggplot(YearRMSE, aes(x = Year, y = RMSE, linetype = Model)) +
  geom_line(linewidth = 0.8) +
  labs(x = "Year", y = "RMSE", title = "Year-specific RMSE over the test period")

RMSE by country and gender

CountryRMSE <- CellErrors %>%
  group_by(Country, Gender, Model) %>%
  summarise(RMSE = sqrt(mean(SquaredError, na.rm = TRUE)), .groups = "drop")

ggplot(CountryRMSE, aes(x = Country, y = RMSE, shape = Model, color = Model)) +
  geom_point(size = 2.8, alpha = 0.9) +
  facet_wrap(~ Gender, scales = "free_y") +
  scale_color_manual(
    values = c(
      "LC" = "black",
      "PCA-GEE" = "blue",
      "PCA-GEE+C" = "darkgreen"
    )
  ) +
  theme(
    axis.text.x = element_text(angle = 90, hjust = 1, size = 7),
    legend.position = "bottom"
  ) +
  labs(
    x = NULL,
    y = "RMSE",
    color = "Model",
    shape = "Model",
    title = "Country-specific RMSE by gender"
  )

Residuals by age

ResidualAge <- CellErrors %>%
  group_by(Age, Model) %>%
  summarise(MeanResidual = mean(Error, na.rm = TRUE), .groups = "drop")

ggplot(ResidualAge, aes(x = Age, y = MeanResidual, linetype = Model)) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_line(linewidth = 0.8) +
  labs(x = "Age", y = "Mean residual", title = "Mean residual by age")