Skip to content

Commit

Permalink
Fix incomplete symmetrize + document it
Browse files Browse the repository at this point in the history
  • Loading branch information
brookslogan committed Oct 4, 2023
1 parent 21b4c85 commit 1f58e67
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions R/layer_cdc_flatline_quantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@
#' These samples are spaced evenly on the (0, 1) scale, F_X(x) resulting
#' in linear interpolation on the X scale. This is achieved with
#' [stats::quantile()] Type 7 (the default for that function).
#' @param symmetrize Logical. If `TRUE`, does two things: (i) forces the
#' "empirical" CDF of residuals to be symmetric by pretending that for every
#' actually-observed residual X we also observed another residual -X, and (ii)
#' at each ahead, forces the median simulated value to be equal to the point
#' prediction by adding or subtracting the same amount to every simulated
#' value. Adjustments in (ii) take place before propagating forward and
#' simulating the next ahead. This forces any 1-ahead predictive intervals to
#' be symmetric about the point prediction, and encourages larger aheads to be
#' more symmetric.
#' @param nonneg Logical. Force all predictive intervals be non-negative.
#' Because non-negativity is forced _before_ propagating forward, this
#' has slightly different behaviour than would occur if using
#' [layer_threshold()].
#' Because non-negativity is forced _before_ propagating forward, this has
#' slightly different behaviour than would occur if using [layer_threshold()].
#' Thresholding at each ahead takes place after any shifting from
#' `symmetrize`.
#'
#' @return an updated `frosting` postprocessor. Calling [predict()] will result
#' in an additional `<list-col>` named `.pred_distn_all` containing 2-column
Expand Down Expand Up @@ -232,6 +242,9 @@ slather.layer_cdc_flatline_quantiles <-
propogate_samples <- function(
r, p, quantile_levels, aheads, nsim, symmetrize, nonneg) {
max_ahead <- max(aheads)
if (symmetrize) {
r <- c(r, -r)
}
samp <- quantile(r, probs = c(0, seq_len(nsim - 1)) / (nsim - 1), na.rm = TRUE)
res <- list()

Expand Down

0 comments on commit 1f58e67

Please sign in to comment.