-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
913: Functions for PIT histograms #949
Open
sbfnk
wants to merge
10
commits into
main
Choose a base branch
from
pit-histogram
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c62c946
pit_sample -> pit_sample_histogram
sbfnk a9a6015
get_pit -> get_pit_histogram
sbfnk 7920aa0
update tests
sbfnk 1c4fea2
update namespace
sbfnk 9b74855
add news item
sbfnk 8a206e1
update manuscript
sbfnk 08d25a3
rename f_dash -> f_bar to match docs
sbfnk c2d4e1a
minor re-formatting
sbfnk e18231d
add xlab/ylab in appropriate place
sbfnk 674fe37
Merge branch 'main' into pit-histogram
nikosbosse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#' @title Probability integral transformation histogram | ||
#' | ||
#' @description | ||
#' Generate a Probability Integral Transformation (PIT) histogram for | ||
#' validated forecast objects. | ||
#' | ||
#' @inherit score params | ||
#' @param num_bins The number of bins in the PIT histogram, default is "auto". | ||
#' When `num_bins == "auto"`, a histogram will be created with either 10 bins, | ||
#' or it a bin for each available quantile in case the forecasts are in a | ||
#' quantile-based format. | ||
#' You can control the number of bins by supplying a number. This is fine for | ||
#' sample-based pit histograms, but may fail for quantile-based formats. In this | ||
#' case it is preferred to supply explicit breaks points using the `breaks` | ||
#' argument. | ||
#' @param breaks Numeric vector with the break points for the bins in the | ||
#' PIT histogram. This is preferred when creating a PIT histogram based on | ||
#' quantile-based data. Default is `NULL` and breaks will be determined by | ||
#' `num_bins`. If `breaks` is used, `num_bins` will be ignored. | ||
#' @param by Character vector with the columns according to which the | ||
#' PIT values shall be grouped. If you e.g. have the columns 'model' and | ||
#' 'location' in the input data and want to have a PIT histogram for | ||
#' every model and location, specify `by = c("model", "location")`. | ||
#' @inheritParams pit_sample | ||
#' @return A data.table with density values for each bin in the PIT histogram. | ||
#' @examples | ||
#' example <- as_forecast_sample(example_sample_continuous) | ||
#' result <- get_pit_histogram(example, by = "model") | ||
#' | ||
#' # example with quantile data | ||
#' example <- as_forecast_quantile(example_quantile) | ||
#' result <- get_pit_histogram(example, by = "model") | ||
#' @export | ||
#' @keywords scoring | ||
#' @references | ||
#' Sebastian Funk, Anton Camacho, Adam J. Kucharski, Rachel Lowe, | ||
#' Rosalind M. Eggo, W. John Edmunds (2019) Assessing the performance of | ||
#' real-time epidemic forecasts: A case study of Ebola in the Western Area | ||
#' region of Sierra Leone, 2014-15, \doi{10.1371/journal.pcbi.1006785} | ||
get_pit_histogram <- function(forecast, num_bins = "auto", breaks = NULL, by, | ||
...) { | ||
UseMethod("get_pit_histogram") | ||
} | ||
|
||
|
||
#' @rdname get_pit_histogram | ||
#' @importFrom cli cli_abort | ||
#' @export | ||
get_pit_histogram.default <- function(forecast, num_bins, breaks, by, ...) { | ||
cli_abort(c( | ||
"!" = "The input needs to be a valid forecast object represented as quantiles or samples." # nolint | ||
)) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to round twice? (we round in line 187 as well)