Tutorials › Response-Adaptive Randomization › Thompson Sampling With Correlated Treatment Posteriors

Thompson Sampling for Trials · Tutorial 268 of 501

Thompson Sampling With Correlated Treatment Posteriors

Use joint posterior draws to estimate each treatment’s probability of being best while preserving correlation and hierarchical shrinkage.

Advanced 12 min read

What You'll Learn

  • Define a posterior best-arm probability from the joint distribution of treatment effects.
  • Estimate best-arm probabilities by counting maxima across joint posterior draws.
  • Calculate how posterior correlation changes a two-arm probability of superiority.
  • Use a hierarchical posterior sampler without breaking dependence among treatment effects.
  • Assess Monte Carlo error and identify common implementation failures.
  • Distinguish joint posterior sampling from independent sampling and plug-in greedy allocation.

Why Dependence Matters for Thompson Sampling

Thompson sampling for treatment allocation uses uncertainty about which treatment has the greatest response. When treatment effects share information through a common control, a shared model parameter, or hierarchical shrinkage, their posterior uncertainties are generally dependent. The probability that one treatment is best then depends on the joint posterior distribution, not just on each treatment’s posterior mean and variance considered separately.

For example, two treatment effects may tend to rise and fall together because both depend on an uncertain common baseline. Their individual posterior distributions may be quite wide while their difference is comparatively precise. Conversely, negative dependence can make their difference more variable. Sampling each treatment independently would discard this structure and can change the probability of selecting each arm.

Definition: Suppose \(\theta_j\) is the treatment response parameter for arm \(j\), with larger values preferred, and let \(D\) denote the observed trial data. The posterior best-arm probability for arm \(k\) is $$ q_k=P\!\left(\theta_k=\max_{1\leq j\leq K}\theta_j\mid D\right). $$ These probabilities are computed under the joint posterior distribution of \((\theta_1,\ldots,\theta_K)\). If ties have posterior probability zero, then \(\sum_{k=1}^K q_k=1\).

In a continuous model, exact ties ordinarily have probability zero. In a discrete model or a model with point masses, ties may have positive probability; the allocation rule must then specify how tied maxima are handled. Here the focus is on continuous treatment posteriors. Once the \(q_k\) values have been computed, ordinary Thompson sampling assigns the next participant to arm \(k\) with probability \(q_k\), conditional on the current trial data and the model.

Computing Best-Arm Probabilities From Joint Draws

Let \(\boldsymbol{\theta}^{(m)}=(\theta_1^{(m)},\ldots,\theta_K^{(m)})\), for \(m=1,\ldots,M\), be draws from the joint posterior given \(D\). Each draw must represent a coherent set of treatment effects from the same posterior draw, including shared parameters and latent effects. For each draw, identify the arm with the largest value. The fraction of draws in which arm \(k\) is largest estimates \(q_k\):

$$ \widehat q_k=\frac{1}{M}\sum_{m=1}^{M} \mathbf{1}\!\left\{\theta_k^{(m)}=\max_{1\leq j\leq K}\theta_j^{(m)}\right\}. $$

This is a Monte Carlo estimate of a posterior probability, not a proportion of trial participants who responded. The treatment-effect draws are simulated from the posterior; they are not additional observed patients. When the draws are independent, the indicator in this expression is a Bernoulli random variable with probability \(q_k\), so the approximate Monte Carlo standard error is

$$ \operatorname{MCSE}(\widehat q_k)\approx \sqrt{\frac{\widehat q_k(1-\widehat q_k)}{M}}. $$

If the draws come from a correlated Markov chain, this formula using the raw number of draws can understate uncertainty. The sequence of indicators for whether arm \(k\) is best is itself correlated; an effective sample size for that indicator, or a batch-based Monte Carlo error estimate, is more appropriate.

Worked Example: Two Correlated Normal Treatment Effects

Suppose a hypothetical trial compares two treatments, with higher response effect preferred. Conditional on the observed data, let their effects have the joint representation \(\theta_1=0.10+U+E_1\) and \(\theta_2=U+E_2\), where \(U\sim N(0,0.04)\), \(E_1\sim N(0,0.01)\), and \(E_2\sim N(0,0.01)\) are mutually independent. The effects are measured in response-rate units. Find the posterior probability that treatment 1 is best.

The shared component \(U\) makes the treatment effects positively correlated. Their difference is \(\theta_1-\theta_2=0.10+E_1-E_2\), because the common component cancels. Thus the difference has mean \(0.10\) and variance

$$ \operatorname{Var}(\theta_1-\theta_2) =0.10^2+0.10^2+2(0.20^2)-2(0.04) =0.01+0.01+0.08-0.08 =0.02. $$

Equivalently, each treatment effect has variance \(0.01+0.04=0.05\), and their covariance is \(0.04\), giving \(0.05+0.05-2(0.04)=0.02\). Therefore,

$$ P(\theta_1>\theta_2\mid D) =P(\theta_1-\theta_2>0\mid D) =\Phi\!\left(\frac{0.10}{\sqrt{0.02}}\right) =\Phi(0.7071)\approx 0.7602. $$

The posterior best-arm probabilities are about \(0.7602\) for treatment 1 and \(1-0.7602=0.2398\) for treatment 2. If one incorrectly sampled from the two marginal posteriors independently, the variance of the difference would be \(0.05+0.05=0.10\), giving \(\Phi(0.10/\sqrt{0.10})=\Phi(0.3162)\approx0.6241\). That is a different probability because independent sampling removes the posterior covariance.

Hierarchical Posteriors and the Joint-Draw Procedure

A hierarchical model often gives treatment effects a shared distribution, such as \(\theta_j\mid\mu,\tau\sim N(\mu,\tau^2)\), with a posterior for the common mean \(\mu\) and possibly for the between-treatment scale \(\tau\). Conditional on a shared parameter, arm-specific effects may be independent, but after integrating over uncertainty in shared parameters they need not be independent. A posterior draw must therefore include a draw of the shared parameters and the corresponding arm effects. Pairing the arm effects from the same draw preserves the dependence induced by the hierarchy.

The procedure requires a proper joint posterior under the specified model and data, a way to obtain representative draws from it, and a clearly defined direction of preference. If larger values are not better, the parameter must first be expressed on a scale where the stated maximization is appropriate. The model must also reflect the trial’s dependence structure; preserving the dependence in an incorrect model does not make the resulting probabilities reliable.

1
Draw the shared state.
For each Monte Carlo iteration, draw any common parameters or latent quantities from their posterior distribution.
2
Draw all treatment effects jointly.
Generate the complete vector of arm effects conditional on that same shared state, following the fitted model.
3
Record the maximum.
Identify the arm with the largest sampled effect and add one to its best-arm count.
4
Normalize and assess error.
Divide each arm’s count by the number of draws; then assess Monte Carlo error, accounting for serial dependence if applicable.

Worked Example: Counting Maxima Across Three Arms

Consider a hypothetical three-arm trial. A hierarchical posterior sampler has produced the following 12 joint draws of treatment effects, in response-rate units. The columns in each row belong together: they were generated in the same iteration, including the shared posterior quantities.

DrawArm AArm BArm CLargest effect
11.20.70.1A
20.30.80.5B
30.60.40.9C
40.90.20.4A
50.41.10.7B
60.50.60.2B
71.00.90.8A
80.20.30.6C
90.80.70.1A
100.10.50.4B
110.70.60.8C
120.90.40.5A

Arm A is largest in draws 1, 4, 7, 9, and 12, giving 5 maxima. Arm B is largest in draws 2, 5, 6, and 10, giving 4; Arm C is largest in draws 3, 8, and 11, giving 3. Therefore the estimated probabilities are

$$ \widehat q_A=\frac{5}{12}=0.4167,\qquad \widehat q_B=\frac{4}{12}=0.3333,\qquad \widehat q_C=\frac{3}{12}=0.2500. $$

They sum to 1 because each draw has exactly one largest effect. If these were the only available draws, the estimates would be very imprecise; the example illustrates the calculation, not a recommended simulation size.

A Larger Simulation and Its Monte Carlo Error

In practice, the joint draw may come from a hierarchical model fitted to trial summaries or participant-level outcomes. To make the calculation concrete, suppose a hypothetical three-arm trial has observed response-effect summaries \(y=(0.35,0.10,-0.10)\), each with standard error \(0.20\). A model assigns the arm effects a common hierarchical distribution and samples its shared parameters and arm effects jointly. Assume for this illustration that the sampler has converged and has yielded 20,000 effectively independent joint draws. The specific posterior probabilities below are hypothetical simulation output, not values inferred from these summaries alone.

Worked Example: Estimating Probabilities From 20,000 Joint Draws

Suppose Arm A is the maximum in 11,440 draws, Arm B in 6,020, and Arm C in 2,540. The counts sum to 20,000. Dividing by that total gives

$$ \widehat q_A=\frac{11440}{20000}=0.5720,\quad \widehat q_B=\frac{6020}{20000}=0.3010,\quad \widehat q_C=\frac{2540}{20000}=0.1270. $$

For Arm A, the independent-draw Monte Carlo standard error is \(\sqrt{0.5720(1-0.5720)/20000}\approx0.00350\). For Arm B it is \(\sqrt{0.3010(1-0.3010)/20000}\approx0.00324\), and for Arm C it is \(\sqrt{0.1270(1-0.1270)/20000}\approx0.00235\). These quantify simulation error in estimating the posterior probabilities, conditional on the model and data. They do not quantify uncertainty about whether the model is appropriate, nor do they turn a posterior probability into a frequentist confidence statement.

Under ordinary Thompson sampling, the next participant would be assigned to A, B, or C with probabilities \(0.5720\), \(0.3010\), and \(0.1270\), respectively, conditional on the current data. The largest probability does not imply that Arm A is certain to be best; it means that it was best in about 57.2% of the joint posterior draws.

Why the Joint Draw Is the Essential Unit

The justification for counting maxima is direct. Under the joint posterior, the event that arm \(k\) is best is represented by an indicator that equals 1 when \(\theta_k\) is the largest and 0 otherwise. Its posterior expectation is exactly the event probability:

$$ E\!\left[ \mathbf{1}\!\left\{\theta_k=\max_j\theta_j\right\}\mid D \right] =P\!\left(\theta_k=\max_j\theta_j\mid D\right)=q_k. $$

A Monte Carlo average of these indicators therefore estimates \(q_k\). This argument depends on drawing the vector from the joint posterior. If one instead shuffles each arm’s draws separately, the resulting rows combine values that may never occur together under the posterior. The computed maxima then refer to an artificial independent distribution, not the fitted model.

A shared additive component is one special case: it induces positive correlation in arm effects but cancels from every pairwise difference, so it does not change which arm is largest in a draw. Correlation is not automatically consequential in the same direction for every model. The relevant question is how the dependence changes the joint distribution of contrasts and, ultimately, the ordering of the effects.

Diagnostics, Alternatives, and Limitations

ApproachWhat it computesWhen it is appropriate or problematic
Joint posterior drawsBest-arm frequencies using complete vectors from the fitted joint posteriorAppropriate for correlated or hierarchical posteriors when draws represent the specified joint model
Independent arm drawsBest-arm frequencies after drawing each arm separately from its marginal posteriorAppropriate only when the joint posterior factorizes across arms; otherwise it imposes a different dependence structure
Plug-in greedy choiceSelects the arm with the largest posterior meanDoes not calculate posterior best-arm probabilities and does not perform Thompson sampling

Several checks help detect problems. Verify that every iteration contains one value for every arm from the same posterior state. Confirm that the maximum is selected on the intended response scale and that no arm labels are shifted or reordered. Check that the estimated probabilities sum to 1, up to rounding, when there is one winner per draw. Increase the number of draws and compare estimates; large changes indicate inadequate Monte Carlo precision. For Markov chain draws, inspect convergence and account for autocorrelation in the best-arm indicators, not only in the individual treatment effects.

The method also has substantive limitations. Best-arm probabilities depend on the likelihood, prior, hierarchical structure, and observed data. A model that assumes exchangeability among treatments may shrink effects toward a common distribution in ways that are questionable when treatments are not genuinely comparable. Further, the probability of having the largest modeled response parameter is not by itself a statement about clinical importance or predictive response probability. The introductory material on best-arm probability versus predictive response probability distinguishes those quantities; the calculation here concerns the former.

Common Mistakes

  • Multiplying or sampling marginal posteriors as if they were independent. This is justified only if the joint posterior actually factorizes. Otherwise it discards the dependence that the joint draws must preserve.
  • Choosing the arm with the largest posterior mean and calling that Thompson sampling. A largest-mean rule is a plug-in choice. Thompson sampling randomizes according to the posterior probability of being best.
  • Treating a small Monte Carlo error as evidence that the model is correct. Monte Carlo precision measures simulation noise under the fitted posterior; it does not diagnose prior sensitivity or model misspecification.
  • Pairing arm values from different iterations. A row of treatment effects must be a joint draw. Rearranging columns independently changes the dependence and can change the estimated allocation probabilities.
Key takeaway: With correlated treatment posteriors, estimate each arm’s Thompson-sampling probability by identifying the maximum within each complete joint posterior draw and counting how often each arm wins. Preserving the joint structure is essential.

Check Your Understanding

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

  1. For two arms, a joint posterior gives \(\theta_1-\theta_2\sim N(0.06,0.04)\), where the second argument is the variance. What is the posterior probability that Arm 1 is best?
  2. In 5,000 independent joint draws, Arm A is largest 2,500 times and Arm B is largest 1,500 times. What is the estimated best-arm probability for the remaining arm?
  3. Why can independently shuffling the columns of a set of hierarchical posterior draws give incorrect best-arm probabilities?
  4. A simulation reports \(\widehat q_A=0.40\) based on 10,000 independent draws. Give its approximate Monte Carlo standard error and state what it measures.

Solutions. (1) The standard deviation of the difference is \(\sqrt{0.04}=0.20\), so \(P(\theta_1>\theta_2\mid D)=\Phi(0.06/0.20)=\Phi(0.30)\approx0.6179\). (2) The remaining arm wins \(5000-2500-1500=1000\) draws, so its estimated probability is \(1000/5000=0.2000\). (3) Shuffling breaks the within-draw dependence induced by shared parameters; the newly paired values may not represent draws from the joint posterior, so their maxima estimate probabilities under an artificial distribution. (4) The approximate standard error is \(\sqrt{0.40(0.60)/10000}=\sqrt{0.000024}\approx0.00490\). It measures Monte Carlo error in estimating the posterior best-arm probability under independent posterior draws, not uncertainty about model adequacy or a frequentist sampling error for the trial estimate.

Clinical Biostats