Repository navigation
Keep zero estimates in impact plots - #19
david-mears-2 wants to merge 1 commit into
Conversation
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>
|
This is AI generated. TODO:
|
| ) | ||
|
|
||
| if (nrow(impact) > 0) { | ||
| if (any(impact$impact != 0)) { |
There was a problem hiding this comment.
The previous filter removed every zero-valued observation before plotting, so a trajectory such as 10, 0, 10 was drawn as a flat line from the first point to the last and hid the zero year. The !is.na(.data$impact) filter keeps zeros for the plot while still excluding missing estimates. The separate any(impact$impact != 0) check preserves the previous error for all-zero or otherwise non-estimable outcomes.
There was a problem hiding this comment.
The previous logic was that plotting is skipped when there are no rows (nrow as zero), but now you're checking whether any value is zero and preventing plots that have only zeros. I am not sure that's desired. Maybe you meant to skip plotting if any value is na? @copilot
The PR is for a bug Copilot identified, and the fix is also due to Copilot.
In brief, the issue is that a plotting function was dropping values equal to zero.
I don't know if there was any reason that the logic was the way it was - it quite explicitly filters out zero-values.
I reproduced using this command:
Before
After
Copilot's PR description
The bug
plot_impact()shows the estimated health benefit of vaccination over time, such as the number of cases averted each year. It also supports grouping estimates by birth cohort.The function removes estimates equal to zero before drawing the plot. For example, estimates of 10 cases averted in 2020, 0 in 2021, and 10 in 2022 become just the two points for 2020 and 2022. The line joins those points at 10, hiding the year with no estimated benefit. The same problem affects the birth-cohort view.
The fix
Keep zero estimates in the plotting data so that the line drops to zero and rises again in this example. Continue removing missing (
NA) estimates.Preserve the existing error when the filtered data has no nonzero estimates, including all-zero inputs. That check now happens separately from filtering the plotting data. Negative estimates remain supported.
This PR addresses only zero removal; it does not change country selection or other plotting behavior. It also updates the patch version to 0.0.7 and records the fix in
NEWS.md, as required byCONTRIBUTING.md.Tests
The regression checks the actual coordinates of both the line and point layers, not just whether a plot is returned. It covers year and birth-cohort views, a
10, 0, 10trajectory, a negative-to-positive trajectory through zero, and missing estimates. A second test checks that all-zero or absent outcomes still raise an error even when another outcome has nonzero estimates.R CMD INSTALLsucceeds, and both new tests pass against the installed package.main; this patch adds no lint findings.