Skip to content

Commit 1f58e67

Browse files
committed
Fix incomplete symmetrize + document it
1 parent 21b4c85 commit 1f58e67

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

R/layer_cdc_flatline_quantiles.R

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@
3232
#' These samples are spaced evenly on the (0, 1) scale, F_X(x) resulting
3333
#' in linear interpolation on the X scale. This is achieved with
3434
#' [stats::quantile()] Type 7 (the default for that function).
35+
#' @param symmetrize Logical. If `TRUE`, does two things: (i) forces the
36+
#' "empirical" CDF of residuals to be symmetric by pretending that for every
37+
#' actually-observed residual X we also observed another residual -X, and (ii)
38+
#' at each ahead, forces the median simulated value to be equal to the point
39+
#' prediction by adding or subtracting the same amount to every simulated
40+
#' value. Adjustments in (ii) take place before propagating forward and
41+
#' simulating the next ahead. This forces any 1-ahead predictive intervals to
42+
#' be symmetric about the point prediction, and encourages larger aheads to be
43+
#' more symmetric.
3544
#' @param nonneg Logical. Force all predictive intervals be non-negative.
36-
#' Because non-negativity is forced _before_ propagating forward, this
37-
#' has slightly different behaviour than would occur if using
38-
#' [layer_threshold()].
45+
#' Because non-negativity is forced _before_ propagating forward, this has
46+
#' slightly different behaviour than would occur if using [layer_threshold()].
47+
#' Thresholding at each ahead takes place after any shifting from
48+
#' `symmetrize`.
3949
#'
4050
#' @return an updated `frosting` postprocessor. Calling [predict()] will result
4151
#' in an additional `<list-col>` named `.pred_distn_all` containing 2-column
@@ -232,6 +242,9 @@ slather.layer_cdc_flatline_quantiles <-
232242
propogate_samples <- function(
233243
r, p, quantile_levels, aheads, nsim, symmetrize, nonneg) {
234244
max_ahead <- max(aheads)
245+
if (symmetrize) {
246+
r <- c(r, -r)
247+
}
235248
samp <- quantile(r, probs = c(0, seq_len(nsim - 1)) / (nsim - 1), na.rm = TRUE)
236249
res <- list()
237250

0 commit comments

Comments
 (0)