Skip to content

Commit

Permalink
fix to averaging function
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreus committed Jan 23, 2024
1 parent 6de3dd4 commit d75336e
Show file tree
Hide file tree
Showing 11 changed files with 3,607 additions and 3,609 deletions.
2,660 changes: 1,330 additions & 1,330 deletions output-data/output-for-interactive/by_location.csv

Large diffs are not rendered by default.

1,824 changes: 912 additions & 912 deletions output-data/output-for-interactive/by_location_per_100k.csv

Large diffs are not rendered by default.

2,652 changes: 1,326 additions & 1,326 deletions output-data/output-for-interactive/infections_per_day.csv

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions output-data/output-for-interactive/main_map.csv

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions output-data/output-for-interactive/regions_line_chart.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
location,date,estimate,estimate_top_95,estimate_top_50,estimate_bot_50,estimate_bot_95,official_covid_deaths,known_excess_deaths
Africa,2020-01-01,635.004,1213.731,635.004,84.774,-105.854,0,FALSE
Asia,2020-01-01,-264.284,593.793,-264.284,-1010.258,-1262.044,0,FALSE
Africa,2020-01-01,635.004,1213.731,635.004,84.774,-105.854,NA,FALSE
Asia,2020-01-01,-264.284,593.793,-264.284,-1010.258,-1262.044,NA,FALSE
North America,2020-01-01,0,0,0,0,0,0,FALSE
Europe,2020-01-01,-0.097,0.098,-0.019,-0.137,-0.265,0,FALSE
Oceania,2020-01-01,-1.123,18.817,8.33,-2.1,-6.971,0,FALSE
Europe,2020-01-01,-0.097,0.098,-0.019,-0.137,-0.265,NA,FALSE
Oceania,2020-01-01,-1.123,18.817,8.33,-2.1,-6.971,NA,FALSE
Latin America and Caribbean,2020-01-01,4.743,17.654,4.743,-2.11,-10.561,0,FALSE
Africa,2020-01-06,635.159,1208.065,635.159,93.664,-104.669,0,FALSE
Asia,2020-01-06,-264.465,582.615,-264.465,-1028.321,-1218.65,0,FALSE
Expand Down Expand Up @@ -1271,9 +1271,9 @@ Asia,2024-01-15,3447.157,13333.182,4458.04,-364.871,-3140.861,14.571,FALSE
Oceania,2024-01-15,-4.213,76.902,21.477,-4.702,-52.266,6.143,FALSE
North America,2024-01-15,-42.596,803.993,-17.617,-270.076,-607.42,0.143,FALSE
Europe,2024-01-15,-314.841,873.244,-150.58,-968.157,-1431.248,0,FALSE
Africa,2024-01-22,648.486,2909.879,1237.354,-151.207,-1143.123,0,FALSE
Oceania,2024-01-22,-1.782,79.209,25.373,-3.464,-48.447,0,FALSE
Africa,2024-01-22,648.486,2909.879,1237.354,-151.207,-1143.123,NA,FALSE
Oceania,2024-01-22,-1.782,79.209,25.373,-3.464,-48.447,NA,FALSE
Latin America and Caribbean,2024-01-22,-102.833,968.074,248.648,-194.171,-1106.512,0,FALSE
Asia,2024-01-22,3613.075,13323.487,4468.164,-504.769,-3279.726,0,FALSE
Asia,2024-01-22,3613.075,13323.487,4468.164,-504.769,-3279.726,NA,FALSE
North America,2024-01-22,-42.596,803.993,-1.676,-277.762,-607.42,0,FALSE
Europe,2024-01-22,-314.859,865.85,-151.577,-968.079,-1431.248,0,FALSE
Europe,2024-01-22,-314.859,865.85,-151.577,-968.079,-1431.248,NA,FALSE
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,8 @@ Latin America and Caribbean,2024-01-15,-0.016,0.147,0.038,-0.028,-0.167,0,FALSE
Africa,2024-01-15,0.045,0.204,0.087,0.005,-0.072,0,FALSE
Asia,2024-01-15,0.073,0.284,0.095,-0.008,-0.067,0,FALSE
North America,2024-01-22,-0.011,0.213,-0,-0.074,-0.161,0,FALSE
Europe,2024-01-22,-0.042,0.116,-0.02,-0.13,-0.192,0,FALSE
Oceania,2024-01-22,-0.004,0.176,0.056,-0.008,-0.108,0,FALSE
Europe,2024-01-22,-0.042,0.116,-0.02,-0.13,-0.192,NA,FALSE
Oceania,2024-01-22,-0.004,0.176,0.056,-0.008,-0.108,NA,FALSE
Latin America and Caribbean,2024-01-22,-0.016,0.147,0.038,-0.029,-0.168,0,FALSE
Africa,2024-01-22,0.045,0.204,0.087,-0.011,-0.08,0,FALSE
Asia,2024-01-22,0.077,0.284,0.095,-0.011,-0.07,0,FALSE
Africa,2024-01-22,0.045,0.204,0.087,-0.011,-0.08,NA,FALSE
Asia,2024-01-22,0.077,0.284,0.095,-0.011,-0.07,NA,FALSE
2 changes: 1 addition & 1 deletion output-data/output-for-interactive/timestamp.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
timestamp
2024-01-23T10:55:49Z
2024-01-23T11:31:04Z
4 changes: 2 additions & 2 deletions output-data/output-for-interactive/world_line_chart.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
location,date,estimate,estimate_top_95,estimate_top_50,estimate_bot_50,estimate_bot_95,official_covid_deaths,known_excess_deaths
World,2020-01-01,374.243,1384.672,374.243,-844.36,-1390.743,0,FALSE
World,2020-01-01,374.243,1384.672,374.243,-844.36,-1390.743,NA,FALSE
World,2020-01-06,373.124,1370.299,373.124,-895.181,-1315.737,0.5,FALSE
World,2020-01-13,134.855,1289.904,134.855,-1117.36,-1615.393,0.143,FALSE
World,2020-01-20,29.609,1073.973,29.609,-1457.189,-2158.155,0.286,FALSE
Expand Down Expand Up @@ -211,4 +211,4 @@ World,2023-12-25,7015.2,19766.107,9413.021,1752.837,-1197.669,209.286,FALSE
World,2024-01-01,5580.444,20646.006,7699.299,-189.356,-3906.676,165.143,FALSE
World,2024-01-08,4849.286,20881.452,6184.286,-754.917,-4553.517,118.286,FALSE
World,2024-01-15,3630.215,19349.324,5675.962,-1131.606,-6227.168,23.857,FALSE
World,2024-01-22,3798.849,19362.117,5436.865,-1878.987,-5874.573,0,FALSE
World,2024-01-22,3798.849,19362.117,5436.865,-1878.987,-5874.573,NA,FALSE
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ World,2023-12-25,0.088,0.249,0.118,0.022,-0.015,0.003,FALSE
World,2024-01-01,0.07,0.26,0.097,-0.002,-0.049,0.002,FALSE
World,2024-01-08,0.061,0.263,0.078,-0.009,-0.057,0.001,FALSE
World,2024-01-15,0.046,0.243,0.071,-0.014,-0.078,0,FALSE
World,2024-01-22,0.048,0.244,0.068,-0.024,-0.074,0,FALSE
World,2024-01-22,0.048,0.244,0.068,-0.024,-0.074,NA,FALSE
2 changes: 1 addition & 1 deletion scripts/1_excess_deaths_global_estimates_data_generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ country_daily_data <- data.frame(country_daily_data[order(country_daily_data$dat
seven_day_average <- function(x){
temp <- x
for(i in 1:length(x)){
x[i] <- sum(temp[max(c(1, i-6)):min(c(length(x), i))], na.rm = T)/length(temp[max(c(1, i-6)):min(c(length(x), i))])
x[i] <- ifelse(any(!is.na(temp[max(c(1, i-6)):min(c(length(x), i))])), sum(temp[max(c(1, i-6)):min(c(length(x), i))], na.rm = T)/length(temp[max(c(1, i-6)):min(c(length(x), i))]), NA)
}
x
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ country_daily_data <- merge(data.frame(country_daily_data), expand.grid(iso_code
date = unique_dates),
all = T)



country_daily_data <- country_daily_data[order(country_daily_data$date, country_daily_data$iso_code), ]

columns_to_fill <- c("location", "continent", "population", "aged_65_older", "aged_70_older")
Expand All @@ -67,7 +65,7 @@ country_daily_data <- data.frame(country_daily_data[order(country_daily_data$dat
seven_day_average <- function(x){
temp <- x
for(i in 1:length(x)){
x[i] <- sum(temp[max(c(1, i-6)):min(c(length(x), i))], na.rm = T)/length(temp[max(c(1, i-6)):min(c(length(x), i))])
x[i] <- ifelse(any(!is.na(temp[max(c(1, i-6)):min(c(length(x), i))])), sum(temp[max(c(1, i-6)):min(c(length(x), i))], na.rm = T)/length(temp[max(c(1, i-6)):min(c(length(x), i))]), NA)
}
x
}
Expand All @@ -89,19 +87,19 @@ fill_if_known_in_last_90 <- function(x){
country_daily_data$total_deaths <- as.numeric(ave(country_daily_data$total_deaths, country_daily_data$location, FUN = fill_if_known_in_last_90))
country_daily_data$total_vaccinations <- as.numeric(ave(country_daily_data$total_vaccinations, country_daily_data$location, FUN = fill_if_known_in_last_90))

## Use last known value for new deaths (if known within the last 30 days):
## Use last known value for new deaths (if known within the last 14 days):
country_daily_data <- country_daily_data[order(country_daily_data$date), ]

fill_if_known_in_last_30 <- function(x){
fill_if_known_in_last_14 <- function(x){
temp <- x
for(i in 1:length(x)){
if(is.na(x[i])){
x[i] <- rev(c(NA, na.omit(temp[max(c(1, i-30)):(i-1)])))[1]
x[i] <- rev(c(NA, na.omit(temp[max(c(1, i-14)):(i-1)])))[1]
}
}
x
}
country_daily_data$new_deaths <- as.numeric(ave(country_daily_data$new_deaths, country_daily_data$location, FUN = fill_if_known_in_last_30))
country_daily_data$new_deaths <- as.numeric(ave(country_daily_data$new_deaths, country_daily_data$location, FUN = fill_if_known_in_last_14))

# Ensure stable covariates are not missing:
for(i in c("location", "continent", 'aged_65_older', "aged_70_older")){
Expand Down

0 comments on commit d75336e

Please sign in to comment.