--- title: "Significance testing for the PIT-Wasserstein metrics" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Significance testing for the PIT-Wasserstein metrics} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 6, fig.height = 4 ) ``` ```{r setup} source(pitw::.here("vignettes/setup.R")) set.seed(101) ``` Each test compares a PIT-Wasserstein score with the values expected under its reference model. The scores measure departures of the probability integral transform (PIT) values from uniformity. The reference distributions are large-sample approximations and assume independent PIT values. In the [EpiEstim example](sir-epiestim-example.html), each series contributes one estimate at a given window setting. Pooling the five settings would count the same series several times. The [worked example](#in-practice) uses 120 normal forecasts with a common location bias and reported standard deviations smaller than the spread of the errors. We score the forecasts with `pit_w()` and pass each score and the number of predictions to its significance function. The signs and $p$-values describe different aspects of the same set of forecasts. ## 1. The reference distribution for uniform PIT values We compare the cumulative distribution of the PIT values with that of a uniform distribution. The Brownian bridge describes how this difference varies across repeated samples of independent uniform PIT values as the sample size increases. ### 1a. The empirical process Under the baseline reference model, the PIT values $u_i = F_i(x_i)$ are $n$ independent draws from $\mathrm{Uniform}(0,1)$. The comparison uses these values, which are on a common scale even when the predictive distributions differ. Form the empirical CDF $F_n(t) = \frac1n\#\{u_i \le t\}$ and compare it to the CDF it should have, which is $F(t) = t$. The **empirical process** is the scaled gap between them: $$ \alpha_n(t) = \sqrt{n}\left(F_n(t) - t\right) $$ The scaled difference has three properties. 1. **At any fixed $t$**, $nF_n(t) \sim \mathrm{Binomial}(n, t)$, so $\alpha_n(t)$ has mean $0$ and variance $t(1-t)$, and by the CLT it is asymptotically normal. 2. **At two points** $s < t$, the covariance works out as $s(1-t) = s\wedge t - st$. 3. **At the ends**, $\alpha_n(0) = \alpha_n(1) = 0$ exactly, because the empirical CDF is pinned to 0 and 1 at the edges, whatever the sample. The standard Brownian bridge $B^\circ$ is a Gaussian process with mean zero, covariance $s\wedge t - st$ and value zero at both endpoints. Donsker's theorem gives the limit of the scaled difference. $$ \alpha_n \;\Rightarrow\; B^\circ \qquad \text{(Donsker's theorem)} $$ ```{r empirical-process, fig.width = 6, fig.height = 3.2} # The empirical process of uniform PIT values, for increasing n. dplyr::tibble(n = c(20L, 100L, 1000L)) |> dplyr::mutate(draw = purrr::map(n, ~ { u <- sort(stats::runif(.x)) dplyr::tibble(t = u, alpha = sqrt(.x) * (seq_along(u) / .x - u)) })) |> tidyr::unnest(draw) |> ggplot2::ggplot(ggplot2::aes(t, alpha)) + ggplot2::geom_hline(yintercept = 0, colour = "grey70") + ggplot2::geom_step(linewidth = 0.3) + ggplot2::facet_wrap(~ n, labeller = ggplot2::label_both) + ggplot2::labs(x = "t", y = expression(alpha[n](t))) + ggplot2::theme_minimal() ``` The path gets rougher as $n$ grows but its *vertical scale does not change*: that is the $\sqrt n$ doing its job. The limiting object is the same in all three panels. ### 1b. Comparing goodness-of-fit statistics Several goodness-of-fit tests summarise the difference between these cumulative distributions. Their reference distributions use the corresponding summary of $B^\circ$. | Test | Statistic | Limit | |---|---|---| | Kolmogorov–Smirnov | $\sup_t\lvert\alpha_n(t)\rvert$ | $\sup_t\lvert B^\circ\rvert$ | | Cramér–von Mises | $\int\alpha_n^2$ | $\int (B^\circ)^2$ | | Anderson–Darling | $\int \alpha_n^2 / (t(1-t))$ | weighted version | | **PIT-Wasserstein** | $\int\lvert\alpha_n\rvert$ | $\int_0^1\lvert B^\circ\rvert$ | KS takes the worst single point ($L^\infty$). Cramér–von Mises takes the mean square ($L^2$). **Ours takes the mean absolute gap (the $L^1$ norm), which is the area between the empirical CDF and the diagonal.** That area is exactly the 1-Wasserstein distance between the PIT distribution and the uniform, which gives the continuous reference for our midpoint approximation. Using the whole difference gives weight to small departures that persist across the PIT range. The Kolmogorov–Smirnov statistic uses the largest vertical difference. ```{r norms, fig.width = 6, fig.height = 3.2} # The same empirical process summarised three ways. u <- sort(stats::runif(60)) dplyr::tibble(t = u, Fn = seq_along(u) / 60) |> ggplot2::ggplot(ggplot2::aes(t)) + ggplot2::geom_ribbon(ggplot2::aes(ymin = pmin(Fn, t), ymax = pmax(Fn, t)), fill = "steelblue", alpha = 0.3) + ggplot2::geom_step(ggplot2::aes(y = Fn)) + ggplot2::geom_abline(slope = 1, intercept = 0, colour = "grey50") + ggplot2::labs(x = "t", y = expression(F[n](t)), subtitle = "shaded area = PIT-Wasserstein; KS = tallest vertical gap") + ggplot2::theme_minimal() ``` ### 1c. The effect of estimating a location shift For the baseline score, the reference is determined by the number of independent uniform PIT values. Estimating a location shift from the same forecasts affects the adjusted PIT values and changes their reference distribution. Section 5 describes this for the undirected adjusted score. ## 2. The three metrics, and the three hypotheses Given PIT values $u_i$ with order statistics $u_{(i)}$ and uniform plotting positions $r_i = (i - \tfrac12)/n$, we use one statistic $$ W(u) = \frac1n\sum_{i=1}^n \left| r_i - u_{(i)} \right| $$ and one signed variant, in which the signed discrepancy is multiplied by a weight that is $+1$ in the lower half of the distribution and $-1$ in the upper, so that over- and under-dispersion cancel rather than accumulate: $$ D(u) = \frac1n\sum_{i=1}^n \left( r_i - u_{(i)} \right)\,\mathrm{sgn}\!\left(\tfrac12 - r_i\right) $$ The **bias adjustment** estimates a single location shift in the link scale, $\hat\delta = \mathrm{median}_i\left(g(m_i) - g(x_i)\right)$ for predictive medians $m_i$, applies it to the observations, and re-computes the PITs. Write $u^{adj}$ for the result. The three metrics are then | Metric | Definition | Large-sample reference | |---|---|---| | $B_{pit}$ | $W(u)$ | Independent uniform PIT values | | $D_{pit}$ | $D(u^{adj})$ | Independent Gaussian errors with a common standard deviation on the link scale and a fitted median shift | | $U_{pit}$ | $W(u^{adj})$ | The same fitted Gaussian model | The baseline distance describes pooled PIT uniformity. The adjusted scores measure the direction and magnitude of the departure left after fitting a common shift. Their marginal tests use the same observations and may reject together. ```{r metrics} # Row-wise metrics on a matrix of PIT values: one replicate per row. pit_metrics <- function(v) { n <- ncol(v) s <- t(apply(v, 1, sort)) r <- matrix(seq(0.5 / n, 1 - 0.5 / n, length.out = n), nrow(v), n, byrow = TRUE) list(W = rowMeans(abs(r - s)), D = rowMeans((r - s) * sign(0.5 - r))) } null_pit <- function(n, reps = 4000) matrix(stats::runif(n * reps), reps, n) ``` ## 3. The null of `B_pit`: an explicit formula The difference between the midpoint distance and the distance to continuous uniformity is at most $1/(4n)$. They therefore have the same scaled limit, $$ \sqrt{n}\,B_{pit} \;\Rightarrow\; \int_0^1 \left| B^\circ(t) \right| \mathrm{d}t $$ Unlike the KS limit this one is not in every textbook, but it *is* known in closed form. Johnson & Killeen (1983) give the CDF of $L = \int_0^1|B^\circ|$ as a rapidly convergent series, $$ P(L \le \ell) = \sqrt{\pi/2}\sum_{j\ge1}\delta_j^{-3/2}\, \psi\!\left(\ell/\delta_j^{3/2}\right), \qquad \psi(t) = 3^{2/3}t^{-1/3}e^{-2/(27t^2)}\,\mathrm{Ai}\!\left((3t)^{-4/3}\right) $$ where $\mathrm{Ai}$ is the Airy function, $a'_j$ is the $j$th zero of $\mathrm{Ai}'$, and $\delta_j = |a'_j|/2^{1/3}$. This is implemented as `p_l1_bridge()` and `q_l1_bridge()`; nothing beyond base R's Bessel functions is needed, since $\mathrm{Ai}$ on the positive axis is a modified Bessel function in disguise. The mean of the limit is known exactly to be $\sqrt{2\pi}/8 \approx 0.3133$, which gives a free and rather demanding check on the implementation: ```{r jk-check} dplyr::tibble( quantity = c("mean", "q95", "q99"), series = c(stats::integrate(function(x) 1 - pitw::p_l1_bridge(x), 0, 5, subdivisions = 500L)$value, pitw::q_l1_bridge(0.95), pitw::q_l1_bridge(0.99)), theory = c(sqrt(2 * pi) / 8, NA, NA) ) ``` At the nominal 5% level we compare $B_{pit}$ with $0.5821/\sqrt n$. `b_pit_significance()` evaluates the limiting distribution. The table below compares it with independent uniform samples of finite size. ```{r b-null} purrr::map_dfr(c(25L, 50L, 100L, 400L), function(n) { b <- pit_metrics(null_pit(n))$W dplyr::tibble(n, mean_sqrt_n = sqrt(n) * mean(b), theory = sqrt(2 * pi) / 8, q95_sqrt_n = sqrt(n) * stats::quantile(b, 0.95), size_0.05 = mean(pitw::b_pit_significance(b, n)$p_value < 0.05)) }) ``` Both $\sqrt n\,\mathbb{E}B$ and $\sqrt n\,q_{0.95}$ are flat in $n$, confirming the scaling, and the test holds its nominal size. Takács (1993) gives series for the $L^1$ norm of Brownian motion. For the Brownian bridge we use the result of Johnson and Killeen (1983). ## 4. The Gaussian limit of `D_pit` Writing $w(t) = \mathrm{sgn}(\tfrac12 - t)$, the signed metric is a **linear** functional of the same process, $$ \sqrt{n}\,D_{pit} \;\Rightarrow\; \int_0^1 w(t)\,B^\circ(t)\,\mathrm{d}t $$ A linear functional of a Gaussian process is Gaussian, so this limit is normal with mean zero, and its variance is a double integral against the bridge covariance: $$ \mathrm{Var}\left( \int_0^1 w B^\circ \right) = \int_0^1\!\!\int_0^1 w(s)w(t)\left(s\wedge t - st\right)\mathrm{d}s\,\mathrm{d}t = \frac{1}{48} $$ The test therefore uses this large-sample reference: $$ D_{pit} \;\approx\; \mathcal{N}\!\left(0,\;\frac{1}{48n}\right) $$ This is where the $L^1$ family stops looking like KS: there is no signed variant of the supremum norm, because a supremum cannot cancel. Taking a signed integral is only available to us because we integrate. ```{r bridge} # Simulate Brownian bridges and evaluate both limiting functionals directly. sim_bridge <- function(reps = 2000, m = 1000) { t <- seq_len(m) / m incr <- matrix(stats::rnorm(reps * m, sd = sqrt(1 / m)), reps, m) w <- t(apply(incr, 1, cumsum)) # Wiener b <- w - outer(w[, m], t) # bridge wt <- matrix(sign(0.5 - t), reps, m, byrow = TRUE) list(signed = rowMeans(b * wt), absolute = rowMeans(abs(b))) } bridge <- sim_bridge() dplyr::tibble( quantity = c("Var(int w B)", "E|int |B||"), simulated = c(stats::var(bridge$signed), mean(bridge$absolute)), theory = c(1 / 48, sqrt(2 * pi) / 8) ) ``` The simulated variance and mean can be compared with $1/48$ and $\sqrt{2\pi}/8$, respectively. Both the finite integration grid and the number of simulated paths affect this comparison. The next table uses raw uniform PITs to check the signed functional before fitting a shift. ```{r d-null} purrr::map_dfr(c(10L, 25L, 50L, 100L, 400L), function(n) { d <- pit_metrics(null_pit(n))$D dplyr::tibble(n, n_var_D = n * stats::var(d), theory = 1 / 48, size_0.05 = mean(pitw::d_pit_significance(d, n)$p_value < 0.05)) }) ``` The simulation compares the finite-sample variance with $1/48$ on the scaled statistic. At small sample sizes the two-sided test can reject more often than its nominal 5% level. ## 5. The reference distribution for adjusted PIT values We estimate the location shift from the same forecasts that we score. In the common-scale Gaussian model, the reference distribution for $U_{pit}$ accounts for this estimate. The same principle motivates the Lilliefors correction for the Kolmogorov–Smirnov test of normality after estimating the mean and variance from the sample. Perturbing the location by $\delta$ moves each PIT value by $\varphi(\Phi^{-1}(t))\delta$ to first order, and the median centring pins the process at $t = \tfrac12$, so the limit is the bridge with that direction projected out: $$ \sqrt{n}\,U_{pit} \;\Rightarrow\; \int_0^1 \left| B^\circ(t) - \kappa(t)\,B^\circ(\tfrac12) \right| \mathrm{d}t, \qquad \kappa(t) = \frac{\varphi(\Phi^{-1}(t))}{\varphi(0)} $$ `u_pit_significance()` simulates and caches this limit process. The sensitivity above is for a common-scale Gaussian location model. In that model the limiting reference for $\sqrt n\,U_{pit}$ is fixed. Under link-scale adjustment, a different predictive family or varying forecast scales can change the effect of estimating the location shift. ```{r u-null-limit} # The limit process of section 5, compared to the unprojected bridge. t <- seq_len(1000) / 1000 kap <- stats::dnorm(stats::qnorm(t)) / stats::dnorm(0) incr <- matrix(stats::rnorm(4000 * 1000, sd = sqrt(1 / 1000)), 4000, 1000) w <- t(apply(incr, 1, cumsum)) b <- w - outer(w[, 1000], t) proj <- b - outer(b[, 500], kap) dplyr::tibble( limit = c("B (unprojected)", "U (projected)"), mean = c(mean(rowMeans(abs(b))), mean(rowMeans(abs(proj)))), q95 = c(stats::quantile(rowMeans(abs(b)), 0.95), stats::quantile(rowMeans(abs(proj)), 0.95)) ) ``` and against the finite-sample adjusted metric, with genuinely heteroscedastic calibrated predictions: ```{r u-null-finite} adjusted_pits <- function(n, reps, kappa) { mu <- matrix(stats::rnorm(n * reps, 10, 2), reps, n) sc <- matrix(exp(stats::rnorm(n * reps, 0, kappa)), reps, n) x <- matrix(stats::rnorm(n * reps, mu, sc), reps, n) b <- apply(mu - x, 1, median) stats::pnorm(x + b, mu, sc) } purrr::pmap_dfr(tidyr::crossing(n = c(25L, 76L, 400L), kappa = c(0, 0.5)), function(n, kappa) { u <- pit_metrics(adjusted_pits(n, 2000, kappa))$W dplyr::tibble(n, kappa, q95_U = stats::quantile(u, 0.95), q95_B = pitw::q_l1_bridge(0.95) / sqrt(n), ratio = stats::quantile(u, 0.95) / (pitw::q_l1_bridge(0.95) / sqrt(n)), size = mean(pitw::u_pit_significance(u, n)$p_value < 0.05)) }) ``` Under the common-scale Gaussian model the 5% critical value for $U_{pit}$ is about two-thirds of the baseline value. The rows with varying forecast scales check one particular simulation. Other families or patterns of variation can change the reference distribution. For illustration the two package functions assign different tail probabilities to a score of 0.05 with 76 independent predictions. ```{r conservative} dplyr::bind_rows( pitw::b_pit_significance(0.05, 76) |> dplyr::transmute(null = "baseline (wrong here)", p_value), pitw::u_pit_significance(0.05, 76) |> dplyr::transmute(null = "adjusted (correct)", p_value) ) ``` In the common-scale Gaussian model the location correction is symmetric about the median. It integrates to zero against the antisymmetric weight of $D_{pit}$. The same correction changes the absolute area used by $U_{pit}$. ## 6. Choosing a scale for the adjustment ### 6a. Link-scale and probit adjustments The package offers a median adjustment on the link scale or on the probit scale. The paper uses the link scale to represent a common location bias. Bias is a location error in $x$-space. An $x$-space shift $\delta$ becomes a **heterogeneous** shift $\delta/\sigma_i$ in probit space, so the correction required on the probit scale depends on the forecast standard deviation. Under homoscedasticity the two coincide; under heteroscedasticity they diverge, and the symptom is a loss of the log-calibration symmetry of the metric. That symmetry is a theorem, not an observation. With no bias and constant $\sigma$ the probit-transformed PIT values are exactly $z_i \sim \mathcal{N}(0, s)$ with $s = \sigma_E/\sigma_S$, so the PIT CDF is $F_s(p) = \Phi(\Phi^{-1}(p)/s)$ and $$F_{1/s}(p) = \Phi\!\left(s\,\Phi^{-1}(p)\right) = F_s^{-1}(p)$$ Inverting a monotone function reflects its graph in the diagonal, which preserves the area between graph and diagonal. So $\int_0^1|F_s(p)-p|\,dp$ is *exactly* invariant under $c \leftrightarrow 1/c$: an estimator twice too wide and one twice too narrow score identically. The identity concerns population distances for constant scales. ```{r symmetry} asymmetry <- function(c_cal, n = 2000, reps = 400) { b <- stats::runif(reps, -1, 1) k <- stats::runif(reps, 0, 2) e <- matrix(stats::rnorm(n * reps), reps, n) + b sc <- matrix(stats::rlnorm(n * reps, log(c_cal), sqrt(log(k^2 + 1))), reps, n) z <- -e / sc c(link_space = mean(pit_metrics(stats::pnorm((-e + apply(e, 1, median)) / sc))$W), probit_mean = mean(pit_metrics(stats::pnorm(z - rowMeans(z)))$W), probit_med = mean(pit_metrics(stats::pnorm(z - apply(z, 1, median)))$W)) } hi <- asymmetry(2); lo <- asymmetry(0.5) dplyr::tibble(adjustment = names(hi), U_at_c_2 = hi, U_at_c_half = lo, asymmetry_pct = 100 * (hi - lo) / ((hi + lo) / 2)) ``` With varying scales, the link adjustment removes the simulated common bias in outcome units. Centring the probits instead removes a common shift in standardised errors. The two operations answer different questions. ### 6b. Directed scores after fitting the shift ```{r adjustment-null} adjusted_null <- function(n, bias, kappa, reps = 4000) { e <- matrix(stats::rnorm(n * reps), reps, n) + bias sc <- if (kappa == 0) matrix(1, reps, n) else matrix(stats::rlnorm(n * reps, 0, sqrt(log(kappa^2 + 1))), reps, n) d <- pit_metrics(stats::pnorm((-e + apply(e, 1, median)) / sc))$D dplyr::tibble(n, bias, kappa, n_var_D = n * stats::var(d), size = mean(pitw::d_pit_significance(d, n)$p_value < 0.05)) } purrr::pmap_dfr(tidyr::crossing(n = c(100L, 400L), bias = c(0, 1), kappa = c(0, 0.5, 2)), adjusted_null) |> dplyr::mutate(theory = 1 / 48) ``` With $\kappa = 0$, the location adjustment cancels to first order in the Gaussian limit. In the simulation, $n\mathrm{Var}(D)$ stays near $1/48$ and the rejection rate is close to nominal with or without a common bias. At $\kappa>0$ reported spreads vary independently of the size of the errors. The rejection proportions in those rows describe a departure from the reference model. ## 7. What exactly is the null hypothesis? The following simulation keeps the median reported spread equal to the error standard deviation and varies the spread from case to case. We compare the resulting PIT tail frequency with the 10% expected under uniformity. ```{r kappa-not-null} purrr::map_dfr(c(0, 0.25, 0.5, 1, 2), function(k) { n <- 5000; reps <- 200 e <- matrix(stats::rnorm(n * reps), reps, n) sc <- if (k == 0) matrix(1, reps, n) else matrix(stats::rlnorm(n * reps, 0, sqrt(log(k^2 + 1))), reps, n) u <- stats::pnorm(-e / sc) dplyr::tibble(kappa = k, E_B_pit = mean(pit_metrics(u)$W), tail_mass = mean(u < 0.05 | u > 0.95)) # uniform => 0.10 }) ``` So $H_0$ for $B_{pit}$ is not "the median predictive width is correct". It is PIT uniformity, which in this simulation family requires the dispersion ratio $c = 1$ *and* $\kappa = 0$. Here $\kappa>0$ means that the reported spread varies independently of the error distribution. A correctly specified heteroscedastic forecast can also report different spreads. If the conditional distribution of the outcome matches each forecast, the PIT values are uniform. ## 8. Reading the three tests together The metrics respond to $\kappa$ quite differently, and the contrast is useful rather than inconvenient: ```{r three-part} sweep_c <- function(c_cal, kappa, n = 20000, reps = 100) { e <- matrix(stats::rnorm(n * reps), reps, n) sc <- if (kappa == 0) matrix(c_cal, reps, n) else matrix(stats::rlnorm(n * reps, log(c_cal), sqrt(log(kappa^2 + 1))), reps, n) m <- pit_metrics(stats::pnorm((-e + apply(e, 1, median)) / sc)) dplyr::tibble(c_cal, kappa, U = mean(m$W), D = mean(m$D)) } purrr::pmap_dfr(tidyr::crossing(c_cal = c(0.5, 0.8, 1, 1.25, 2), kappa = c(0, 0.5, 1, 2)), sweep_c) |> tidyr::pivot_wider(names_from = c_cal, values_from = c(U, D)) |> print(width = Inf) ``` In this simulation the average directed score stays near zero at $c=1$ as $\kappa$ increases. The average unsigned score increases. Independent variation in the scales can put excess PIT mass both near the endpoints and near the centre. Some departures then cancel in the directed score. At $n=200$, what fraction of replicate sets gives a rejection at the nominal 5% threshold? We calculate all three proportions for each of six scenarios, fitting a separate median shift in each replicate. ```{r power} scenario <- function(label, bias, c_cal, kappa, n = 200L, reps = 400) { e <- matrix(stats::rnorm(n * reps), reps, n) + bias sc <- if (kappa == 0) matrix(c_cal, reps, n) else matrix(stats::rlnorm(n * reps, log(c_cal), sqrt(log(kappa^2 + 1))), reps, n) B <- pit_metrics(stats::pnorm(-e / sc))$W # unadjusted m <- pit_metrics(stats::pnorm((-e + apply(e, 1, median)) / sc)) # adjusted dplyr::tibble(label, bias, c_cal, kappa, B_pit = mean(pitw::b_pit_significance(B, n)$p_value < 0.05), D_pit = mean(pitw::d_pit_significance(m$D, n)$p_value < 0.05), U_pit = mean(pitw::u_pit_significance(m$W, n)$p_value < 0.05)) } purrr::pmap_dfr(dplyr::tribble( ~label, ~bias, ~c_cal, ~kappa, "calibrated", 0, 1, 0, "pure bias", 1, 1, 0, "over-confident", 0, 0.7, 0, "over-conservative", 0, 1.3, 0, "spread-error decoupling", 0, 1, 1, "bias + over-conservative", 1, 1.3, 0 ), scenario) ``` A common shift produces a large baseline distance in this simulation. A pure width error can also produce a large baseline distance and can cause all three tests to reject. The sign of $D_{pit}$ then gives the net direction of the remaining error. Under independently varying spread, $U_{pit}$ can detect departures that largely cancel in $D_{pit}$. A shape error can give a similar pattern. The table reports marginal rejection rates for known scenarios. It supplies neither a unique diagnosis nor a joint 5% test. ## 9. In practice We simulate 120 observations from normal distributions with means 0.8 above their forecast means. Each forecast reports a standard deviation of one, while the standard deviation of the simulated errors is 1.4. ```{r practice} set.seed(2024) n <- 120 mu <- stats::rnorm(n, 10, 2) sc <- rep(1, n) x <- stats::rnorm(n, mu + 0.8, 1.4) # biased AND over-confident s <- pitw::pit_w(x, mu, sc, dist = "norm", link = "identity") dplyr::bind_rows( pitw::b_pit_significance(s$B_pit, n) |> dplyr::transmute(metric = "B_pit", value = B_pit, p_value), pitw::d_pit_significance(s$D_pit, n) |> dplyr::transmute(metric = "D_pit", value = D_pit, p_value), pitw::u_pit_significance(s$U_pit, n) |> dplyr::transmute(metric = "U_pit", value = U_pit, p_value) ) ``` All three tests reject in this example. The positive $D_{pit}$ is consistent with the reported spread being too narrow. We know the bias and the distributional family from the simulation design. The baseline score was $0.227$. The adjusted scores were $0.035$ for $D_{pit}$ and $0.037$ for $U_{pit}$. `prediction_scores()` additionally reports `n_predictions`, so the three tests can be applied directly to a table of scored forecasters. ## 10. Caveats **Independence.** Here $n$ counts independent predictions. Rolling estimates from one series may share observations or be correlated even when their windows do not overlap. The nominal thresholds can then misstate the evidence. In the EpiEstim study each comparison uses independent replicates. **Small $n$.** All three tests use limiting reference distributions. In the simulated Gaussian setting, the $D_{pit}$ normal approximation is mildly anti-conservative below $n \approx 50$ (empirical size around 8% at $n = 10$). **Skewed predictive families.** Constructing a *calibrated* example outside log-symmetric families needs care, independently of any of the above. For a scale family $X = \mu W$ with $\mathrm{median}(W) = 1$, placing predictions at $\mu_i = F_W^{-1}(q_i)$ gives $u_i = F_W(x_0/\mu_i)$, which is uniform only if $W \overset{d}{=} 1/W$, which is true for `lnorm4` but false for `gamma4`. The correct placement solves $F(x_0;\mu_i) = 1 - q_i$: ```{r calibrated-locations} calibrated_locations <- function(qs, x0, kappa, qfn) x0 / qfn(1 - qs, 1, kappa) qs <- seq(1, 199, 2) / 200 dplyr::tibble( placement = c("naive quantiles", "calibrated"), B_pit = c( pitw::pit_w(2.5, pitw::qgamma4(qs, 2.5, 0.5), 0.5, dist = "gamma4", link = "log")$B_pit, pitw::pit_w(2.5, calibrated_locations(qs, 2.5, 0.5, pitw::qgamma4), 0.5, dist = "gamma4", link = "log")$B_pit) ) ``` Use $B_{pit}$ rather than $U_{pit}$ for this kind of construction check: it asks the unconditional question and does not estimate anything from the sample. ## Summary * The PIT values of a calibrated forecaster are uniform, so the gap between their empirical CDF and the diagonal converges to a **Brownian bridge**. The limiting Wasserstein statistic uses its $L^1$ norm and Kolmogorov–Smirnov uses its supremum. * $\sqrt n\,B_{pit} \Rightarrow \int_0^1|B^\circ|$, with an explicit CDF from Johnson & Killeen (1983): a 5% critical value of $0.5821/\sqrt n$. * $\sqrt n\,D_{pit} \Rightarrow \mathcal{N}(0, 1/48)$ under the stated assumptions. The finite-sample test uses this limit as an approximation. * The bias adjustment estimates a parameter from the same data, so $U_{pit}$ needs its own null, which is the **Lilliefors step**. Its critical value is two thirds of $B_{pit}$'s in the Gaussian reference model. In that model the location adjustment cancels to first order for $D_{pit}$. * The adjustment must live in the link scale, not in PIT space, or bias-invariance under heteroscedasticity is lost. * $H_0$ is PIT uniformity, which is stronger than "the median width is correct": spread–error decoupling is an alternative, not a null. * Report all three with their $p$-values and interpret them alongside the fitted shift and the forecast design. The three tests use the same predictions.