From f2771f2f7b8e560def50600eec8ed8d9e36121da Mon Sep 17 00:00:00 2001 From: David Mears Date: Fri, 6 Nov 2026 17:06:54 +0000 Subject: [PATCH] Keep zero estimates in impact plot trajectories Retain zero-valued observations in mixed impact series while preserving the existing no-nonzero-estimates error. Add coordinate regressions for both views and update the patch release notes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- DESCRIPTION | 2 +- NEWS.md | 6 ++++ R/fn_plotting_impact.R | 4 +-- tests/testthat/test-plot_impact.R | 51 +++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 97d393f..fa7efd1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: vimcheck Title: Diagnostics for Vaccine Impact Modelling Consortium Burden and Impact Estimates -Version: 0.0.6 +Version: 0.0.7 Authors@R: c( person("Pratik", "Gupte", , "p.gupte24@imperial.ac.uk", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5294-7819")), diff --git a/NEWS.md b/NEWS.md index 047b01d..94db74a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# vimcheck 0.0.7 + +- Fixed `plot_impact()` to retain zero estimates in year and birth-cohort + trajectories instead of drawing a line across them. Inputs with no nonzero + estimates still raise an error. + # vimcheck 0.0.6 - Fixed `basic_burden_sanity()` to return failed-check messages instead of diff --git a/R/fn_plotting_impact.R b/R/fn_plotting_impact.R index 0b637e6..50d59e3 100644 --- a/R/fn_plotting_impact.R +++ b/R/fn_plotting_impact.R @@ -67,10 +67,10 @@ plot_impact <- function( data, .data$country %in% country, .data$burden_outcome == burden_type, - .data$impact != 0 # can this be safely written as impact > 0? + !is.na(.data$impact) ) - if (nrow(impact) > 0) { + if (any(impact$impact != 0)) { if (view == "cohort") { checkmate::assert_names(names(data), must.include = "birth_cohort") x_var <- "birth_cohort" diff --git a/tests/testthat/test-plot_impact.R b/tests/testthat/test-plot_impact.R index af73183..6215f59 100644 --- a/tests/testthat/test-plot_impact.R +++ b/tests/testthat/test-plot_impact.R @@ -77,6 +77,57 @@ test_that("Plotting impact works", { ) }) +test_that("Impact trajectories retain zero estimates in both views", { + impact_data <- data.frame( + country = "A", + year = 2020:2023, + birth_cohort = 2000:2003, + burden_outcome = "cases", + impact = c(10, 0, 10, NA), + short_name = "routine" + ) + + for (values in list(c(10, 0, 10, NA), c(-10, 0, 10, NA))) { + impact_data$impact <- values + + for (view in c("year", "cohort")) { + p <- plot_impact(impact_data, "A", "cases", view) + expected_x <- if (view == "year") 2020:2022 else 2000:2002 + expected_y <- values[1:3] + + expect_equal(p$data$impact, expected_y) + + layers <- ggplot2::ggplot_build(p)$data + for (layer in layers[2:3]) { + expect_equal(layer$x, expected_x) + expect_equal(layer$y, expected_y) + } + } + } +}) + +test_that("Impact plots still reject outcomes without nonzero estimates", { + impact_data <- data.frame( + country = "A", + year = 2020:2022, + birth_cohort = 2000:2002, + burden_outcome = c("cases", "cases", "deaths"), + impact = c(0, NA, 10), + short_name = "routine" + ) + + for (view in c("year", "cohort")) { + expect_error( + plot_impact(impact_data, "A", "cases", view), + "No estimates remaining in the data" + ) + expect_error( + plot_impact(impact_data, "A", "dalys", view), + "No estimates remaining in the data" + ) + } +}) + test_that("Plotting coverage and FVPs works", { p <- plot_coverage_fvps(eg_fvps_2, "AGO") expect_list(p, "ggplot")