Tutorials › Bayesian Clinical Trials › Rank-Normalized R-Hat For Multiple Chains in Bayesian Trials

Posterior Computation · Tutorial 131 of 696

Rank-Normalized R-Hat For Multiple Chains in Bayesian Trials

You will learn to calculate and interpret rank-normalized split R-hat, including its folded version, and to use it with trace plots without treating a value near one as proof of convergence.

Intermediate 12 min read

What You'll Learn

  • Explain why chains are split before calculating R-hat.
  • Apply pooled rank normalization to MCMC draws.
  • Calculate the within-chain variance, between-chain variance, and R-hat.
  • Interpret rank and folded R-hat together with trace plots.
  • Identify what a value near one can and cannot establish.
  • Recognize warning signs that R-hat may miss.

Why Compare Multiple Chains?

A trace plot shows how a parameter’s sampled values change across iterations. Seeing several traces overlap and move through a similar range is reassuring, but visual inspection alone can miss differences in chain location or spread. R-hat summarizes one such comparison: it asks whether the variation between chains is small relative to the variation within chains.

Rank-normalized split R-hat is a diagnostic for a scalar quantity of interest, such as a treatment effect, a baseline risk, or a derived clinical-trial estimand. It uses multiple chains targeting the same posterior distribution. The procedure splits each chain, converts pooled draws to normal scores based on their ranks, and compares within-chain and between-chain variation on that transformed scale. A folded version also checks for differences in spread that may not show up as differences in location.

Definition: Let \(m\) be the number of chains after splitting and \(n\) the number of retained draws in each split chain. For transformed draws \(z_{ij}\), where \(i=1,\ldots,m\) indexes chains and \(j=1,\ldots,n\) indexes iterations, let \(\bar{z}_i\) be the mean for chain \(i\), and let \(s_i^2\) be its sample variance. Define the average within-chain variance \(W\), the between-chain variance \(B\), the estimated marginal variance \(\widehat{V}\), and R-hat by the formulas below.
$$ W=\frac{1}{m}\sum_{i=1}^{m}s_i^2,\qquad B=\frac{n}{m-1}\sum_{i=1}^{m}(\bar{z}_i-\bar{z}_{\cdot})^2,\qquad \bar{z}_{\cdot}=\frac{1}{m}\sum_{i=1}^{m}\bar{z}_i $$
$$ \widehat{V}=\frac{n-1}{n}W+\frac{1}{n}B,\qquad \widehat{R}=\sqrt{\frac{\widehat{V}}{W}} $$

Here \(W\) summarizes variation within chains, while \(B\) reflects how far the chain means are spread from their overall mean. If the chains explore the same target distribution, their means should not remain systematically separated, and the two variance estimates should be similar. A value of \(\widehat{R}\) near one is consistent with that expectation. It is a diagnostic signal, not a proof that the chains have converged or that the model is correct.

Constructing Rank-Normalized Split R-hat

Start with multiple chains that use the same model and target posterior distribution. After warmup has been removed, split each retained chain into two halves, usually its first and last halves. If the length is odd, one draw can be omitted so the halves have equal length. Splitting makes a chain’s early and late behavior contribute separately: a chain that drifts or changes location over time may otherwise have a single overall mean that conceals the problem.

Pool the draws from all \(2m\) split chains and assign each draw a rank \(r\) among the \(S=2mn\) pooled draws. For ties, use their average rank. Convert each rank to a normal score using the inverse standard normal cumulative distribution function \(\Phi^{-1}\):

$$ z=\Phi^{-1}\left(\frac{r-\frac{3}{8}}{S+\frac{1}{4}}\right) $$

This rank transformation, often called the Blom transformation, replaces the original values with scores determined by their relative order. Calculate \(W\), \(B\), \(\widehat{V}\), and \(\widehat{R}\) for these scores. Because the comparison is based on ranks, this version is less dependent on the original parameter’s scale and is more robust to some skewed or heavy-tailed marginal distributions than an R-hat calculated directly on raw values.

Rank normalization mainly checks for differences in location. To make a complementary check for differences in scale, calculate the absolute deviations of the original draws from their pooled median, rank-normalize those deviations by the same procedure, and calculate another split R-hat. This is the folded rank-normalized R-hat. Report the larger of the rank-normalized and folded values as rank-normalized split R-hat. A high folded value can flag chains with similar centers but different spreads.

Key takeaway: Rank-normalized split R-hat is the maximum of two diagnostics: the split R-hat for rank-normalized draws and the split R-hat for rank-normalized absolute deviations from the pooled median. Inspect both components when the maximum is elevated.

Worked Calculations

Worked Example: Calculating Rank R-hat From Chain Summaries

Suppose four hypothetical trial-model chains are split into eight chains, each with \(n=50\) draws. After rank-normalizing the pooled draws, suppose the chain summaries give \(W=0.960\) and \(B=1.10\). These are summaries of the transformed scores, not of the parameter in its original clinical units.

First combine the two variance estimates:

$$ \widehat{V}=\frac{49}{50}(0.960)+\frac{1}{50}(1.10) =0.9408+0.0220=0.9628 $$

Then calculate the rank-normalized split R-hat:

$$ \widehat{R}=\sqrt{\frac{0.9628}{0.960}} =\sqrt{1.0029167}\approx 1.001 $$

The result is approximately 1.001 to four significant figures. It indicates that the between-chain and within-chain variation on the rank scale are similar for this quantity. It does not establish that all parts of the posterior have been explored.

Worked Example: Chain Means That Remain Separated

Consider four hypothetical split chains, each with \(n=40\) rank-normalized draws, with \(W=1.00\). Suppose their means are \(-3a,-a,a,3a\), where \(a=\sqrt{0.03375}\approx0.1837\). Their overall mean is zero, and the sum of squared deviations of their means from zero is \(20a^2=0.675\).

The between-chain variance is therefore:

$$ B=\frac{40}{3}(0.675)=9.00 $$

Now calculate the estimated marginal variance and R-hat:

$$ \widehat{V}=\frac{39}{40}(1.00)+\frac{9.00}{40} =0.975+0.225=1.20 $$
$$ \widehat{R}=\sqrt{\frac{1.20}{1.00}} =\sqrt{1.20}\approx1.095 $$

The value is substantially above one, because the chain means are dispersed relative to the within-chain variation. In an applied analysis, this result would prompt investigation of the traces and the sampling process rather than a claim that the chains have successfully represented one common posterior distribution.

Worked Example: A Folded Diagnostic Finds Unequal Spread

Suppose the rank-normalized split R-hat for a hypothetical treatment-effect parameter is \(1.000\) to three significant figures. The traces have similar centers, but one chain appears much more dispersed. For the folded, rank-normalized draws, suppose \(n=100\), \(W=0.800\), and \(B=3.20\).

The folded variance estimate is:

$$ \widehat{V}_{\mathrm{folded}} =\frac{99}{100}(0.800)+\frac{1}{100}(3.20) =0.792+0.032=0.824 $$

Thus:

$$ \widehat{R}_{\mathrm{folded}} =\sqrt{\frac{0.824}{0.800}} =\sqrt{1.03}\approx1.015 $$

The rank-based location diagnostic is near one, but the folded diagnostic is higher. The reported rank-normalized split R-hat is the maximum, \(1.015\). The difference is a warning that the chains may not agree about the parameter’s spread, even though their centers appear similar.

Assumptions and Interpretation

This diagnostic is most informative when the chains are independent runs with dispersed initial values, use the same model and posterior target, and are assessed after warmup. The retained portions should be intended to sample from a stationary distribution. If chains target different distributions because of different code, data, or model settings, their R-hat comparison does not answer the intended convergence question. Nor does a favorable R-hat repair a misspecified model or an incorrect likelihood.

In practice, values close to one are reassuring only in conjunction with trace plots and other checks. A threshold such as 1.01 is sometimes used as a stringent warning rule, but it is not a universal guarantee: interpretation depends on the analysis, parameter, and consequences of inadequate computation. A value appreciably above one calls for investigation. A value slightly below one can occur from finite-sample variation and is not evidence of “better than converged” sampling.

Check the diagnostic for parameters that matter to the trial conclusions, including clinically interpretable derived quantities where appropriate. A single model parameter can look satisfactory while a nonlinear function of several parameters, such as a predicted risk difference, behaves differently across chains. The trace plot helps identify patterns R-hat compresses into one number: drift, long periods of little movement, separated regions, or changes in spread.

Common Pitfalls and Alternatives

  • Calling a value near one proof of convergence. R-hat compares chains on a particular quantity; it cannot establish that every relevant posterior feature has been explored. Use it with traces and other diagnostics.
  • Using only the ordinary, unsplit statistic. A whole-chain summary can obscure a difference between early and late behavior. Splitting makes that kind of within-chain change more visible.
  • Ignoring the folded value. Chains can have similar centers but different spreads. Check the folded diagnostic as well as the rank-based location diagnostic.
  • Comparing chains that do not share a target. Different model specifications or data inputs undermine the interpretation of the comparison. Confirm that chains were run under the same posterior model.
  • Reading R-hat as a clinical effect measure. It is a dimensionless computational diagnostic, not an estimate of treatment benefit and not an interval in clinical units.

A raw-scale split R-hat is a simpler alternative, but it can be more sensitive to scale and distributional shape. Rank normalization improves the comparison for many non-normal posterior distributions, and folding adds sensitivity to scale differences. Trace plots provide a visual, time-ordered complement; unlike R-hat, they can reveal the pattern of a problem, but they do not reduce that evidence to a numerical summary. No one of these checks is sufficient by itself.

R-hat also has limitations. A value near one can occur when all chains become stuck in the same region, or when chains fail to visit a relevant low-probability region. It is a comparison across chains, not a direct measure of how precisely a posterior expectation or quantile has been estimated. It does not replace checks tailored to particular sampling methods or parameter constraints.

A Short Justification of the Variance Comparison

The construction combines a within-chain estimate with a between-chain estimate. The weight on \(W\) is \((n-1)/n\), and the weight on \(B\) is \(1/n\), so \(\widehat{V}\) lies between these components when both are nonnegative. If \(B=W\), then:

$$ \widehat{V}=\frac{n-1}{n}W+\frac{1}{n}W=W \quad\Longrightarrow\quad \widehat{R}=\sqrt{\frac{W}{W}}=1 $$

If \(B>W\), then \(\widehat{V}>W\), so \(\widehat{R}>1\). This explains why persistent separation among chain means tends to raise the statistic. The calculation is a variance comparison, however, not a theorem that \(\widehat{R}=1\) proves stationarity or complete exploration. The split, rank, and folded steps improve the diagnostic’s ability to reveal certain discrepancies; they do not eliminate its limitations.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. What two sources of variation are compared by R-hat, and what does a value near one suggest?
  2. Why split each retained chain before calculating the statistic?
  3. For \(W=1.00\), \(B=2.00\), and \(n=50\), calculate \(\widehat{V}\) and R-hat.
  4. What problem can the folded rank-normalized calculation reveal when the ordinary rank-based value is near one?
  5. Give one reason that a favorable R-hat does not by itself establish adequate exploration of the posterior.

Solutions. (1) It compares within-chain variation \(W\) with a variance estimate \(\widehat{V}\) that incorporates between-chain variation \(B\). A value near one suggests these estimates are similar for the quantity examined; it does not prove convergence. (2) Splitting allows early and late portions of a chain to contribute separately, making some within-chain changes easier to detect. (3) \(\widehat{V}=(49/50)(1.00)+(1/50)(2.00)=0.98+0.04=1.02\), so \(\widehat{R}=\sqrt{1.02/1.00}\approx1.01\) to three significant figures. (4) It can reveal differences in chain spread despite similar centers. (5) For example, all chains might become stuck in the same region, so they agree with one another without exploring the full posterior.

Clinical Biostats