Compute per-site empirical-Bayes shrinkage proportions
Source:R/layer2-diagnostics.R
compute_shrinkage.RdCompute the classical empirical-Bayes shrinkage weight per site, \(S_j = \sigma_\tau^2 / (\sigma_\tau^2 + \widehat{se}_j^2)\) — the fraction by which a partial-pooling estimator pulls each site's estimate toward the grand mean. Group D diagnostic (downstream shrinkage — Dr. Chen's question 4: "How much does empirical Bayes pool toward the mean?").
Arguments
- se2_j
Numeric vector (length \(\ge 1\), strictly positive). Per-site sampling variances \(\widehat{se}_j^2\).
- sigma_tau
Numeric scalar (\(\ge 0\)). Between-site SD on the response scale.
sigma_tau = 0returns zeros (no heterogeneity to shrink toward).- monotone
Logical scalar. If
TRUE, returnsort(shrinkage)for plotting purposes. DefaultFALSEpreserves site-index alignment.
Value
A numeric vector of length length(se2_j), each entry in
[0, 1). Sorted ascending when monotone = TRUE.
Details
\(S_j\) ranges over [0, 1). \(S_j \to 1\) means "the prior
dominates" — site \(j\) has so much sampling noise that
partial-pooling collapses its estimate toward the overall mean.
\(S_j \to 0\) means "the data dominate" — the site identifies its
own latent effect cleanly. Sites with intermediate \(S_j\) are
where empirical-Bayes pooling does real work.
\(\sigma_\tau = 0\) returns zero for every site (no heterogeneity
to recover).
Reading guide. For diagnostic plots — funnel- or
caterpillar-style traces of shrinkage against site precision — pass
monotone = TRUE so the returned vector is sorted ascending and
renders as a smooth curve. For computing means or downstream
summaries, leave monotone = FALSE so each \(S_j\) aligns with
its site index.
For the four-question diagnostic walkthrough see the A3 · Diagnostics in practice vignette.
References
Lee, J., Che, J., Rabe-Hesketh, S., Feller, A., & Miratrix, L. (2025). Improving the estimation of site-specific effects and their distribution in multisite trials. Journal of Educational and Behavioral Statistics, 50(5), 731–764. doi:10.3102/10769986241254286 .
See also
compute_I for the geometric-mean aggregate
\(\widehat{I}\) that uses the same shrinkage kernel;
mean_shrinkage for the across-site mean of \(S_j\);
feasibility_index for \(\sum_j S_j\) (Efron) or
\(\sum_j (1 - S_j)\) (Morris);
scenario_audit for the quality gates that consume
these diagnostics;
the A3 ·
Diagnostics in practice vignette.
Other family-diagnostics:
bhattacharyya_coef(),
compute_I(),
compute_kappa(),
default_thresholds(),
feasibility_index(),
heterogeneity_ratio(),
informativeness(),
ks_distance(),
mean_shrinkage(),
realized_rank_corr(),
realized_rank_corr_marginal(),
scenario_audit()
Examples
# Two sites, the second twice as noisy as the first.
compute_shrinkage(c(0.05, 0.10), sigma_tau = 0.20)
#> [1] 0.4444444 0.2857143
# First site keeps more of its own information; second is shrunk harder.
# Sorted view — useful for a per-site shrinkage curve plot.
compute_shrinkage(c(0.10, 0.04, 0.07), sigma_tau = 0.20, monotone = TRUE)
#> [1] 0.2857143 0.3636364 0.5000000
# No heterogeneity collapses every site to zero shrinkage.
compute_shrinkage(c(0.05, 0.10), sigma_tau = 0)
#> [1] 0 0