Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion R/class-forecast-quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,18 @@ is_forecast_quantile <- function(x) {
}


#' @rdname as_forecast_point
#' @title Convert a `forecast_quantile` to a `forecast_point`
#'
#' @description
#' When converting a `forecast_quantile` object into a `forecast_point` object,
#' the 0.5 quantile is extracted and returned as the point forecast.
#'
#' @param data A `forecast_quantile` object (as created by
#' [as_forecast_quantile()]).
#' @param ... Unused.
#' @returns A `forecast` object of class `forecast_point`.
#' @family functions to create forecast objects
#' @seealso [as_forecast_point()]
#' @export
#' @keywords as_forecast
as_forecast_point.forecast_quantile <- function(data, ...) {
Expand Down
29 changes: 23 additions & 6 deletions R/class-forecast-sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,26 @@ is_forecast_sample <- function(x) {
}


#' @rdname as_forecast_quantile
#' @details # Converting from `forecast_sample` to `forecast_quantile`
#' @title Convert a `forecast_sample` to a `forecast_quantile`
#'
#' @description
#' When creating a `forecast_quantile` object from a `forecast_sample` object,
#' the quantiles are estimated by computing empircal quantiles from the samples
#' the quantiles are estimated by computing empirical quantiles from the samples
#' via [quantile()]. Note that empirical quantiles are a biased estimator for
#' the true quantiles in particular in the tails of the distribution and
#' when the number of available samples is low.
#'
#' @param data A `forecast_sample` object (as created by
#' [as_forecast_sample()]).
#' @param probs A numeric vector of quantile levels for which
#' quantiles will be computed. Corresponds to the `probs` argument in
#' [quantile()].
#' @param type Type argument passed down to the quantile function. For more
#' information, see [quantile()].
#' @param ... Unused.
#' @returns A `forecast` object of class `forecast_quantile`.
#' @family functions to create forecast objects
#' @seealso [as_forecast_quantile()]
#' @importFrom stats quantile
#' @importFrom methods hasArg
#' @importFrom checkmate assert_numeric
Expand Down Expand Up @@ -192,11 +200,20 @@ get_metrics.forecast_sample <- function(x, select = NULL, exclude = NULL, ...) {
}


#' @rdname get_pit_histogram
#' @title PIT histogram for sample-based forecasts
#'
#' @description
#' Generate a Probability Integral Transformation (PIT) histogram for
#' sample-based forecast objects. Unlike the quantile-based method
#' ([get_pit_histogram.forecast_quantile()]), this method supports additional
#' arguments for handling integer-valued forecasts (`integers` and
#' `n_replicates`).
#'
#' @inherit get_pit_histogram params return
#' @inheritParams pit_histogram_sample
#' @seealso [get_pit_histogram()], [pit_histogram_sample()]
#' @importFrom data.table `:=` as.data.table dcast
#' @importFrom checkmate assert_int assert_numeric
#' @inheritParams pit_histogram_sample
#' @seealso [pit_histogram_sample()]
#' @export
get_pit_histogram.forecast_sample <- function(forecast, num_bins = 10,
breaks = NULL, by, integers = c(
Expand Down
1 change: 1 addition & 0 deletions R/helper-quantile-interval-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ quantile_to_interval_numeric <- function(observed,
#' based on interval ranges.
#'
#' @inheritParams as_forecast_quantile
#' @inheritParams as_forecast_quantile.forecast_sample
#' @param keep_quantile_col keep quantile_level column, default is TRUE
#' @returns A data.table in a long interval interval range format
#' @importFrom data.table as.data.table
Expand Down
2 changes: 2 additions & 0 deletions man/as_forecast_binary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/as_forecast_multivariate_sample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/as_forecast_nominal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/as_forecast_ordinal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions man/as_forecast_point.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions man/as_forecast_point.forecast_quantile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 3 additions & 25 deletions man/as_forecast_quantile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions man/as_forecast_quantile.forecast_sample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/as_forecast_sample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 1 addition & 25 deletions man/get_pit_histogram.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading