Skip to content

Commit

Permalink
appease the gods of linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse committed Oct 3, 2024
1 parent f1be943 commit 8f4d680
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion R/class-forecast-binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ as_forecast_binary <- function(data,
#' @importFrom cli cli_abort
#' @keywords validate-forecast-object
assert_forecast.forecast_binary <- function(
forecast, forecast_type = NULL, verbose = TRUE, ...
forecast, forecast_type = NULL, verbose = TRUE, ...
) {
forecast <- assert_forecast_generic(forecast, verbose)
assert_forecast_type(forecast, actual = "binary", desired = forecast_type)
Expand Down
2 changes: 1 addition & 1 deletion R/class-forecast-nominal.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @keywords check-forecasts
#' @importFrom checkmate assert_names assert_set_equal test_set_equal
assert_forecast.forecast_nominal <- function(
forecast, forecast_type = NULL, verbose = TRUE, ...
forecast, forecast_type = NULL, verbose = TRUE, ...
) {
forecast <- assert_forecast_generic(forecast, verbose)
assert(check_columns_present(forecast, "predicted_label"))
Expand Down
2 changes: 1 addition & 1 deletion R/class-forecast-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @importFrom cli cli_abort
#' @keywords validate-forecast-object
assert_forecast.forecast_point <- function(
forecast, forecast_type = NULL, verbose = TRUE, ...
forecast, forecast_type = NULL, verbose = TRUE, ...
) {
forecast <- assert_forecast_generic(forecast, verbose)
assert_forecast_type(forecast, actual = "point", desired = forecast_type)
Expand Down
15 changes: 8 additions & 7 deletions R/class-forecast-quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ score.forecast_quantile <- function(forecast, metrics = get_metrics(forecast), .
#' @rdname assert_forecast
#' @keywords validate-forecast-object
assert_forecast.forecast_quantile <- function(
forecast, forecast_type = NULL, verbose = TRUE, ...
forecast, forecast_type = NULL, verbose = TRUE, ...
) {
forecast <- assert_forecast_generic(forecast, verbose)
assert_forecast_type(forecast, actual = "quantile", desired = forecast_type)
Expand Down Expand Up @@ -186,12 +186,13 @@ get_pit.forecast_quantile <- function(forecast, by, ...) {
quantile_coverage <-
forecast[, .(quantile_coverage = mean(quantile_coverage)),
by = c(unique(c(by, "quantile_level")))]
quantile_coverage <- quantile_coverage[order(quantile_level),
.(
quantile_level = c(quantile_level, 1),
pit_value = diff(c(0, quantile_coverage, 1))
),
by = c(get_forecast_unit(quantile_coverage))
quantile_coverage <- quantile_coverage[
order(quantile_level),
.(
quantile_level = c(quantile_level, 1),
pit_value = diff(c(0, quantile_coverage, 1))
),
by = c(get_forecast_unit(quantile_coverage))
]
return(quantile_coverage[])
}
Expand Down
17 changes: 9 additions & 8 deletions R/class-forecast-sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @rdname assert_forecast
#' @keywords validate-forecast-object
assert_forecast.forecast_sample <- function(
forecast, forecast_type = NULL, verbose = TRUE, ...
forecast, forecast_type = NULL, verbose = TRUE, ...
) {
forecast <- assert_forecast_generic(forecast, verbose)
assert_forecast_type(forecast, actual = "sample", desired = forecast_type)
Expand Down Expand Up @@ -61,10 +61,10 @@ is_forecast_sample <- function(x) {
#' @importFrom checkmate assert_numeric
#' @export
as_forecast_quantile.forecast_sample <- function(
data,
probs = c(0.05, 0.25, 0.5, 0.75, 0.95),
type = 7,
...
data,
probs = c(0.05, 0.25, 0.5, 0.75, 0.95),
type = 7,
...
) {
forecast <- copy(data)
assert_forecast(forecast, verbose = FALSE)
Expand Down Expand Up @@ -175,9 +175,10 @@ get_pit.forecast_sample <- function(forecast, by, n_replicates = 100, ...) {
forecast <- as.data.table(forecast)

# if prediction type is not quantile, calculate PIT values based on samples
forecast_wide <- data.table::dcast(forecast,
... ~ paste0("InternalSampl_", sample_id),
value.var = "predicted"
forecast_wide <- data.table::dcast(
forecast,
... ~ paste0("InternalSampl_", sample_id),
value.var = "predicted"
)

pit <- forecast_wide[, .(pit_value = pit_sample(
Expand Down
2 changes: 1 addition & 1 deletion R/get-coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ get_coverage <- function(forecast, by = "model") {
# convert to wide interval format and compute interval coverage --------------
interval_forecast <- quantile_to_interval(forecast, format = "wide")
interval_forecast[,
interval_coverage := (observed <= upper) & (observed >= lower)
interval_coverage := (observed <= upper) & (observed >= lower)
][, c("lower", "upper", "observed") := NULL]
interval_forecast[, interval_coverage_deviation :=
interval_coverage - interval_range / 100]
Expand Down
6 changes: 3 additions & 3 deletions R/get-duplicate-forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#' example <- rbind(example_quantile, example_quantile[1000:1010])
#' get_duplicate_forecasts(example)
get_duplicate_forecasts <- function(
data,
forecast_unit = NULL,
counts = FALSE
data,
forecast_unit = NULL,
counts = FALSE
) {
assert_data_frame(data)
data <- ensure_data.table(data)
Expand Down
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,3 @@ get_protected_columns <- function(data = NULL) {

return(protected_columns)
}

0 comments on commit 8f4d680

Please sign in to comment.