Skip to content
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

rename sharpness to dispersion #163

Merged
merged 2 commits into from
Nov 25, 2021
Merged
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
6 changes: 3 additions & 3 deletions R/eval_forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' \item {aem} Absolute error of the median prediction
#' \item {Bias} 0 is good, 1 and -1 are bad.
#' See [bias()] for more information.
#' \item {Sharpness} Smaller is better. See [sharpness()] for more
#' \item {Sharpness/dispersion} Smaller is better. See [sharpness()] for more
#' information.
#' \item {Calibration} represented through the p-value of the
#' Anderson-Darling test for the uniformity of the Probability Integral
Expand Down Expand Up @@ -131,8 +131,8 @@
#'
#' @return A data.table with appropriate scores. For binary predictions,
#' the Brier Score will be returned, for quantile predictions the interval
#' score, as well as adapted metrics for calibration, sharpness and bias.
#' For integer forecasts, Sharpness, Bias, DSS, CRPS, LogS, and
#' score, as well as adapted metrics for calibration, sharpness/dispersion and
#' bias. For integer forecasts, Sharpness, Bias, DSS, CRPS, LogS, and
#' pit_p_val (as an indicator of calibration) are returned. For integer
#' forecasts, pit_sd is returned (to account for the randomised PIT),
#' but no Log Score is returned (the internal estimation relies on a
Expand Down
8 changes: 4 additions & 4 deletions R/eval_forecasts_quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ eval_forecasts_quantile <- function(data,
# compute separate results if desired
if (interval_score_arguments$separate_results) {
res <- res[, c("interval_score",
"sharpness",
"dispersion",
"underprediction",
"overprediction") := do.call(scoringutils::interval_score,
c(list(true_value,
Expand Down Expand Up @@ -155,7 +155,7 @@ eval_forecasts_quantile <- function(data,
res <- add_quantiles(res,
c("interval_score", "coverage",
"overprediction", "underprediction",
"coverage_deviation", "bias", "sharpness", "aem",
"coverage_deviation", "bias", "dispersion", "aem",
"ae_point"),
quantiles,
by = c(summarise_by))
Expand All @@ -165,7 +165,7 @@ eval_forecasts_quantile <- function(data,
res <- add_sd(res,
varnames = c("interval_score", "bias", "coverage",
"overprediction", "underprediction",
"coverage_deviation", "sharpness", "aem",
"coverage_deviation", "dispersion", "aem",
"ae_point"),
by = c(summarise_by))
}
Expand All @@ -174,7 +174,7 @@ eval_forecasts_quantile <- function(data,
res <- res[, lapply(.SD, mean, na.rm = TRUE),
by = c(summarise_by),
.SDcols = colnames(res) %like%
"coverage|bias|sharpness|coverage_deviation|interval_score|overprediction|underprediction|aem|ae_point|relative_skill|scaled_rel_skill"]
"coverage|bias|dispersion|coverage_deviation|interval_score|overprediction|underprediction|aem|ae_point|relative_skill|scaled_rel_skill"]
}

# if neither quantile nor range are in summarise_by, remove coverage and quantile_coverage
Expand Down
10 changes: 5 additions & 5 deletions R/interval_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' into an interval score that, in the limit, corresponds to CRPS. Default:
#' `FALSE`.
#' @param separate_results if `TRUE` (default is `FALSE`), then the separate
#' parts of the interval score (sharpness, penalties for over- and
#' parts of the interval score (dispersion penalty, penalties for over- and
#' under-prediction get returned as separate elements of a list). If you want a
#' `data.frame` instead, simply call [as.data.frame()] on the output.
#' @return vector with the scoring values, or a list with separate entries if
Expand Down Expand Up @@ -91,21 +91,21 @@ interval_score <- function(true_values,
alpha <- (100 - interval_range) / 100

# calculate three components of WIS
sharpness <- (upper - lower)
dispersion <- (upper - lower)
overprediction <- 2/alpha * (lower - true_values) * (true_values < lower)
underprediction <- 2/alpha * (true_values - upper) * (true_values > upper)

if (weigh) {
sharpness <- sharpness * alpha / 2
dispersion <- dispersion * alpha / 2
underprediction <- underprediction * alpha / 2
overprediction <- overprediction * alpha / 2
}

score <- sharpness + underprediction + overprediction
score <- dispersion + underprediction + overprediction

if (separate_results) {
return(list(interval_score = score,
sharpness = sharpness,
dispersion = dispersion,
underprediction = underprediction,
overprediction = overprediction))
} else {
Expand Down
18 changes: 9 additions & 9 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ correlation_plot <- function(scores,
#'
#' @description
#' Visualise the components of the weighted interval score: penalties for
#' over-prediction, under-prediction and for a lack of sharpness
#' over-prediction, under-prediction and for high dispersion (lack of sharpness)
#'
#' @param scores A data.frame of scores based on quantile forecasts as
#' produced by [eval_forecasts()]
Expand Down Expand Up @@ -323,7 +323,7 @@ wis_components <- function(scores,
scores <- data.table::melt(scores,
measure.vars = c("overprediction",
"underprediction",
"sharpness"),
"dispersion"),
variable.name = "wis_component_name",
value.name = "component_value")

Expand Down Expand Up @@ -363,14 +363,14 @@ wis_components <- function(scores,
#'
#' @description
#' Visualise the metrics by range, e.g. if you are interested how different
#' interval ranges contribute to the overall interval score, or how sharpness
#' changes by range.
#' interval ranges contribute to the overall interval score, or how
#' sharpness / dispersion changes by range.
#'
#' @param scores A data.frame of scores based on quantile forecasts as
#' produced by [eval_forecasts()]. Note that "range" must be included
#' in the `summarise_by` argument when running `eval_forecasts`
#' @param y The variable from the scores you want to show on the y-Axis.
#' This could be something like "interval_score" (the default) or "sharpness"
#' This could be something like "interval_score" (the default) or "dispersion"
#' @param x The variable from the scores you want to show on the x-Axis.
#' Usually this will be "model"
#' @param colour Character vector of length one used to determine a variable
Expand Down Expand Up @@ -399,15 +399,15 @@ wis_components <- function(scores,
#'
#' scoringutils::range_plot(scores, x = "model", facet_formula = ~ value_desc)
#'
#' # visualise sharpness instead of interval score
#' scoringutils::range_plot(scores, y = "sharpness", x = "model",
#' # visualise dispersion instead of interval score
#' scoringutils::range_plot(scores, y = "dispersion", x = "model",
#' facet_formula = ~value_desc)
#'
#' # we saw above that sharpness values crossed. Let's look at the unweighted WIS
#' # we saw above that dispersion values crossed. Let's look at the unweighted WIS
#' scores <- scoringutils::eval_forecasts(scoringutils::quantile_example_data,
#' interval_score_arguments = list(weigh = FALSE),
#' summarise_by = c("model", "value_desc", "range"))
#' scoringutils::range_plot(scores, y = "sharpness", x = "model",
#' scoringutils::range_plot(scores, y = "dispersion", x = "model",
#' facet_formula = ~value_desc)


Expand Down
6 changes: 3 additions & 3 deletions man/eval_forecasts.Rd

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

2 changes: 1 addition & 1 deletion man/interval_score.Rd

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

14 changes: 7 additions & 7 deletions man/range_plot.Rd

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

2 changes: 1 addition & 1 deletion man/wis_components.Rd

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

4 changes: 2 additions & 2 deletions vignettes/scoringutils.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Let us look at the individual components of the weighted interval score:

```{r}
scores <- scoringutils::eval_forecasts(data,
summarise_by = c("model", "value_desc"))
summarise_by = c("model", "value_desc"))
scoringutils::wis_components(scores, facet_formula = ~ value_desc)
```

Expand Down Expand Up @@ -203,7 +203,7 @@ Sharpness is the ability of the model to generate predictions within a
narrow range. It is a data-independent measure, and is purely a feature
of the forecasts themselves.

Shaprness of predictive samples corresponding to one single true value is
Shaprness / dispersion of predictive samples corresponding to one single true value is
measured as the normalised median of the absolute deviation from
the median of the predictive samples. For details, see `?stats::mad`

Expand Down