BOT: Fix #942: Add plot_discrimination() for binary forecasts#1079
BOT: Fix #942: Add plot_discrimination() for binary forecasts#1079nikosbosse wants to merge 7 commits intomainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1079 +/- ##
==========================================
+ Coverage 97.98% 98.00% +0.02%
==========================================
Files 37 38 +1
Lines 1984 2006 +22
==========================================
+ Hits 1944 1966 +22
Misses 40 40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nikosbosse
left a comment
There was a problem hiding this comment.
CLAUDE: Approved. Clean implementation of plot_discrimination() that follows all existing package conventions (ensure_data.table, check_columns_present, theme_scoringutils). All 7 tests match specifications and pass. Only minor nitpick: unused @importFrom checkmate assert_data_frame import — harmless but unnecessary.
- Use expect_gte() instead of expect_true(x >= y) to satisfy expect_comparison_linter - Skip vdiffr snapshot tests on R < 4.2 where density estimation produces different SVG output Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Default to histogram with density on y-axis; density curves available via type = "density". Removes old vdiffr snapshots that only worked with one plot type and updates tests accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Allows users to pass arguments like bins, binwidth, bw, or adjust directly through to the underlying geom. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Proportions are computed within each observed level so both groups sum to 1, making the distribution shapes directly comparable regardless of sample size differences. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add nolint annotations for false positive object_usage_linter warnings caused by ... forwarding, and add group to globalVariables. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| #' | ||
| #' @param forecast A data.table (or data.frame) containing at least columns | ||
| #' `observed` (factor with two levels) and `predicted` (numeric probabilities | ||
| #' between 0 and 1). Typically a `forecast_binary` object or the output of |
There was a problem hiding this comment.
or? it is the output? Do we want to support input that isn't a forecast binary object? Based on package flow I would assume we are mving towards not doing so.
| labs(y = "Density") | ||
| } else { | ||
| plot <- plot + | ||
| geom_histogram( # nolint object_usage_linter |
There was a problem hiding this comment.
lintr really works this badly with standard dply?
seabbs
left a comment
There was a problem hiding this comment.
I think this looks pretty good. My main concern is do we want to support non forecast objects here or insist that they are first as_ before use in these functions.


Summary
plot_discrimination()function that visualises the discrimination ability of binary forecasts by plotting overlapping density curves of predicted probabilities, stratified by observed outcome levelensure_data.table(),check_columns_present(),theme_scoringutils())Closes #942
Root cause
No binary-specific plot functions existed in the codebase. The
forecast_binaryclass andexample_binarydataset provided the data structures but there was no way to visualise discrimination ability.What changed
R/plot-discrimination.Rwithplot_discrimination()— accepts a data.frame/data.table withobserved(factor) andpredicted(numeric) columns, renders overlapping density plots via ggplot2tests/testthat/test-plot_discrimination.Rwith 7 test cases and 2 visual regression snapshotsTest plan
🤖 Generated with Claude Code