From ee34257ab51fbb709696b1a622c74d8f776de1c6 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 21 Oct 2024 14:36:51 +0100 Subject: [PATCH] add plotting examples for pit histogram --- R/get-pit-histogram.R | 12 ++++++++++++ man/get_pit_histogram.Rd | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/R/get-pit-histogram.R b/R/get-pit-histogram.R index c528268f..7aeab245 100644 --- a/R/get-pit-histogram.R +++ b/R/get-pit-histogram.R @@ -4,6 +4,8 @@ #' 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 @@ -24,12 +26,22 @@ #' @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) #' result <- get_pit_histogram(example, by = "model") +#' ggplot(result, aes(x = mid, y = density)) + +#' 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 diff --git a/man/get_pit_histogram.Rd b/man/get_pit_histogram.Rd index 8dbe89c5..074aa494 100644 --- a/man/get_pit_histogram.Rd +++ b/man/get_pit_histogram.Rd @@ -68,14 +68,26 @@ A data.table with density values for each bin in the PIT 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. } \examples{ +library("ggplot2") + example <- as_forecast_sample(example_sample_continuous) result <- get_pit_histogram(example, by = "model") +ggplot(result, aes(x = mid, y = density)) + + 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") } \references{ Sebastian Funk, Anton Camacho, Adam J. Kucharski, Rachel Lowe,