-
Notifications
You must be signed in to change notification settings - Fork 21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 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 d39f6c0
Some cosmetic changes
nikosbosse 76176d3
Update R/get-pit-histogram.R
nikosbosse 41059a6
address comments on comments without creating more comments
nikosbosse 643c297
use safe if
sbfnk ee34257
add plotting examples for pit histogram
sbfnk 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,65 @@ | ||
#' @title Probability integral transformation histogram | ||
#' | ||
#' @description | ||
#' Generate a Probability Integral Transformation (PIT) histogram for | ||
#' validated forecast objects. | ||
#' | ||
#' See the examples for how to plot the result of this function. | ||
#' | ||
#' @inherit score params | ||
#' @param num_bins The number of bins in the PIT histogram. For sample-based | ||
#' forecasts, the default is 10 bins. For quantile-based forecasts, the | ||
#' default is one bin for each available quantile. | ||
#' 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. | ||
#' 0 and 1 will always be added as left and right bounds, respectively. | ||
#' @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_histogram_sample | ||
#' @return A data.table with density values for each bin in the PIT histogram. | ||
#' @examples | ||
#' library("ggplot2") | ||
#' | ||
#' example <- as_forecast_sample(example_sample_continuous) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't it already of class sample and so this line isn't needed? |
||
#' result <- get_pit_histogram(example, by = "model") | ||
#' ggplot(result, aes(x = mid, y = density)) + | ||
nikosbosse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#' geom_col() + | ||
#' facet_wrap(. ~ model) + | ||
#' labs(x = "Quantile", "Density") | ||
#' | ||
#' # example with quantile data | ||
#' example <- as_forecast_quantile(example_quantile) | ||
#' result <- get_pit_histogram(example, by = "model") | ||
#' ggplot(result, aes(x = mid, y = density)) + | ||
#' geom_col() + | ||
#' facet_wrap(. ~ model) + | ||
#' labs(x = "Quantile", "Density") | ||
#' @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, breaks, 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.
typo:
sampel
->sample