Skip to content

Commit

Permalink
simplify checking for continuous/discrete forecasts
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse authored and seabbs committed Mar 27, 2024
1 parent d4dac50 commit e825741
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions R/pit.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,21 @@ pit_sample <- function(observed,
predicted <- matrix(predicted, nrow = 1)
}

# check data type ------------------------------------------------------------
# check whether continuous or integer
if (isTRUE(all.equal(as.vector(predicted), as.integer(predicted)))) {
continuous_predictions <- FALSE
} else {
continuous_predictions <- TRUE
}

# calculate PIT-values -------------------------------------------------------
n_pred <- ncol(predicted)

# calculate emipirical cumulative distribution function as
# Portion of (y_observed <= y_predicted)
p_x <- rowSums(predicted <= observed) / n_pred

# calculate PIT for continuous predictions case
if (continuous_predictions) {
pit_values <- p_x
} else {
# PIT calculation is different for integer and continuous predictions
if (get_type(predicted) == "integer") {
p_xm1 <- rowSums(predicted <= (observed - 1)) / n_pred
pit_values <- as.vector(
replicate(n_replicates, p_xm1 + runif(1) * (p_x - p_xm1))
)
} else {
pit_values <- p_x
}
return(pit_values)
}
Expand Down

0 comments on commit e825741

Please sign in to comment.