Skip to content

Commit

Permalink
Merge 35901b7 into 29ac025
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse authored Nov 22, 2021
2 parents 29ac025 + 35901b7 commit 2d96ec5
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 20 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(abs_error)
export(ae_median_quantile)
export(ae_median_sample)
export(available_metrics)
export(bias)
export(brier_score)
export(correlation_plot)
Expand Down
2 changes: 1 addition & 1 deletion R/bias.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bias <- function(true_values, predictions) {
# ============================================

## check whether continuous or integer
if (all.equal(as.vector(predictions), as.integer(predictions)) != TRUE) {
if (!isTRUE(all.equal(as.vector(predictions), as.integer(predictions)))) {
continuous_predictions <- TRUE
} else {
continuous_predictions <- FALSE
Expand Down
11 changes: 6 additions & 5 deletions R/eval_forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
#' `summarise_by` is also the grouping level used to compute
#' (and possibly plot) the probability integral transform(pit).
#' @param metrics the metrics you want to have in the output. If `NULL` (the
#' default), all available metrics will be computed.
#' default), all available metrics will be computed. For a list of available
#' metrics see [available_metrics()]
#' @param quantiles numeric vector of quantiles to be returned when summarising.
#' Instead of just returning a mean, quantiles will be returned for the
#' groups specified through `summarise_by`. By default, no quantiles are
Expand Down Expand Up @@ -254,7 +255,7 @@ eval_forecasts <- function(data = NULL,
}
compute_relative_skill <- FALSE
}
if (rel_skill_metric != "auto" && !(rel_skill_metric %in% list_of_avail_metrics())) {
if (rel_skill_metric != "auto" && !(rel_skill_metric %in% available_metrics())) {
if (verbose) {
warning("argument 'rel_skill_metric' must either be 'auto' or one of the metrics that can be computed. Relative skill will not be computed")
}
Expand Down Expand Up @@ -302,7 +303,7 @@ eval_forecasts <- function(data = NULL,
}

# check metrics to be computed
available_metrics <- list_of_avail_metrics()
available_metrics <- available_metrics()
if (is.null(metrics)) {
metrics <- available_metrics
} else {
Expand All @@ -321,13 +322,13 @@ eval_forecasts <- function(data = NULL,
if (any(grepl("lower", names(data))) | "boundary" %in% names(data) |
"quantile" %in% names(data) | "range" %in% names(data)) {
prediction_type <- "quantile"
} else if (all.equal(data$prediction, as.integer(data$prediction)) == TRUE) {
} else if (isTRUE(all.equal(data$prediction, as.integer(data$prediction)))) {
prediction_type <- "integer"
} else {
prediction_type <- "continuous"
}

if (all.equal(data$true_value, as.integer(data$true_value)) == TRUE) {
if (isTRUE(all.equal(data$true_value, as.integer(data$true_value)))) {
if (all(data$true_value %in% c(0,1)) && all(data$prediction >= 0) && all(data$prediction <= 1)) {
target_type = "binary"
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/eval_forecasts_continuous_integer.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ eval_forecasts_sample <- function(data,
verbose) {

if (missing(prediction_type)) {
if (all.equal(data$prediction, as.integer(data$prediction)) == TRUE) {
if (isTRUE(all.equal(data$prediction, as.integer(data$prediction)))) {
prediction_type <- "integer"
} else {
prediction_type <- "continuous"
Expand Down
2 changes: 1 addition & 1 deletion R/pairwise-comparisons.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pairwise_comparison <- function(scores,
# usually, by = NULL should be fine and only needs to be specified if there
# are additional columns that are not metrics and not related to the unit of observation
if (is.null(by)) {
all_metrics <- list_of_avail_metrics()
all_metrics <- available_metrics()
by <- setdiff(names(scores), c(all_metrics, "model"))
}

Expand Down
6 changes: 3 additions & 3 deletions R/pit.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#' number of Monte Carlo samples
#' @param plot logical. If `TRUE`, a histogram of the PIT values will be
#' returned as well
#' @param num_bins the number of bins in the PIT histogram (if `plot == TRUE`)
#' @param num_bins the number of bins in the PIT histogram (if `plot = TRUE`)
#' If not given, the square root of n will be used
#' @param n_replicates the number of tests to perform,
#' each time re-randomising the PIT
Expand Down Expand Up @@ -153,7 +153,7 @@ pit <- function(true_values,

# check data type ------------------------------------------------------------
# check whether continuous or integer
if (all.equal(as.vector(predictions), as.integer(predictions)) != TRUE) {
if (!isTRUE(all.equal(as.vector(predictions), as.integer(predictions)))) {
continuous_predictions <- TRUE
} else {
continuous_predictions <- FALSE
Expand Down Expand Up @@ -235,7 +235,7 @@ pit <- function(true_values,
#' \item `data`: the input data.frame (not including rows where prediction is `NA`),
#' with added columns `pit_p_val` and `pit_sd`
#' \item `hist_PIT` a plot object with the PIT histogram. Only returned
#' if `plot == TRUE`. Call
#' if `plot = TRUE`. Call
#' `plot(PIT(...)$hist_PIT)` to display the histogram.
#' \item `p_values`: all p_values generated from the Anderson-Darling tests on the
#' (randomised) PIT. Only returned if `full_output = TRUE`
Expand Down
4 changes: 2 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ score_table <- function(summarised_scores,
# identify metrics -----------------------------------------------------------
# identify metrics by looking at which of the available column names
# are metrics. All other variables are treated as identifier variables
all_metrics <- list_of_avail_metrics()
all_metrics <- available_metrics()

metrics <- names(summarised_scores)[names(summarised_scores) %in% all_metrics]
id_vars <- names(summarised_scores)[!(names(summarised_scores) %in% all_metrics)]
Expand Down Expand Up @@ -196,7 +196,7 @@ correlation_plot <- function(scores,
select_metrics = NULL) {

# define possible metrics
all_metrics <- list_of_avail_metrics()
all_metrics <- available_metrics()

# find metrics present
metrics <- names(scores)[names(scores) %in% all_metrics]
Expand Down
7 changes: 6 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ globalVariables(c("..index",
"g"))


list_of_avail_metrics <- function() {
#' @title Available metrics in scoringutils
#'
#' @return A vector with the name of all available metrics
#' @export

available_metrics <- function() {
available_metrics <- c("ae_point", "aem", "log_score", "sharpness", "bias", "dss", "crps",
"coverage", "coverage_deviation", "quantile_coverage",
"pit_p_val", "pit_sd","interval_score",
Expand Down
14 changes: 14 additions & 0 deletions man/available_metrics.Rd

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

3 changes: 2 additions & 1 deletion man/eval_forecasts.Rd

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

3 changes: 2 additions & 1 deletion man/eval_forecasts_binary.Rd

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

3 changes: 2 additions & 1 deletion man/eval_forecasts_sample.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/pit.Rd

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

4 changes: 2 additions & 2 deletions man/pit_df.Rd

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

0 comments on commit 2d96ec5

Please sign in to comment.