14  Computation and AI Agents

For most of the twentieth century the practical objection to Bayesian trial design was computational: posteriors for realistic models could not be computed, and designs could not be simulated at the scale needed to establish their operating characteristics. By 2026 that objection has gone.

14.1 Conjugate updates and quadrature

Most interim decisions in a trial need only a conjugate update: a beta posterior for a response rate, a normal posterior for a log hazard ratio, a gamma posterior for an event rate. These take microseconds, which is what makes continuous monitoring and response adaptive randomization operationally possible. When a model has two or three parameters, as the Bayesian logistic regression model for dose finding of the companion volume, Bayesian Clinical Trials, does, grid evaluation or Gaussian quadrature is exact enough and easy to audit. Early Bayesian work at CIBA-GEIGY in Basel used numerical integration, which its authors found routine for problems of up to five or six dimensions (Racine et al. 1986). Where the full numerical analysis showed that a simple analytic approximation was accurate, as for a two parameter model of the median lethal dose, the approximation was then used for routine work.

14.2 Markov chain Monte Carlo

Hierarchical models with many parameters need simulation. The Gibbs sampler draws each block of parameters from its full conditional distribution given the others. For the hierarchical normal model \(y_{ij}\sim N(\theta_i,\sigma^2)\), \(\theta_i\sim N(\mu,\tau^2)\), with a normal prior on \(\mu\) and inverse gamma priors on \(\sigma^2\) and \(\tau^2\), every full conditional is normal or inverse gamma, and the sampler cycles through them; Gelfand et al. (1990) illustrated the method for statisticians with exactly such models. The Metropolis Hastings algorithm handles conditionals that are not of standard form, and Hamiltonian Monte Carlo, implemented in Stan, uses gradients to move efficiently through high dimensional posteriors such as population pharmacokinetic models.

For trial work the practical points are diagnostic and procedural. Chains must be run long enough and checked for convergence; random seeds must be recorded; and the code that produces a posterior on which a regulatory decision rests must be validated and archived like any other computerized system.

14.3 Pólya Gamma augmentation for binary outcomes

Binary endpoints with covariates, response by treatment and biomarker, toxicity by dose and exposure, lead to logistic regression, whose posterior has no conjugate form. Polson, Scott, and Windle (2013) showed that the logistic likelihood is a mixture of Gaussians. For \(y_i\) successes in \(n_i\) trials with linear predictor \(\psi_i = x_i^\top\beta\),

\[ \frac{(e^{\psi_i})^{y_i}}{(1+e^{\psi_i})^{n_i}} = 2^{-n_i}e^{\kappa_i\psi_i}\int_0^\infty e^{-\omega_i\psi_i^2/2}\,p(\omega_i\mid n_i,0)\,d\omega_i, \qquad \kappa_i = y_i - n_i/2, \tag{14.1}\]

where \(p(\omega\mid n,0)\) is the Pólya Gamma density. Conditional on the latent \(\omega_i\) the likelihood is Gaussian in \(\beta\), so with a \(N(b,B)\) prior the Gibbs sampler alternates

\[ \omega_i\mid\beta\sim\mathrm{PG}(n_i,x_i^\top\beta),\qquad \beta\mid\omega\sim N(m_\omega,V_\omega), \]

with \(V_\omega = (X^\top\Omega X + B^{-1})^{-1}\), \(m_\omega = V_\omega(X^\top\kappa + B^{-1}b)\) and \(\Omega = \mathrm{diag}(\omega_i)\). Both steps are exact draws, so the sampler has no tuning parameters, which is a real advantage when a design must be simulated thousands of times without human supervision. The same augmentation handles negative binomial counts and multinomial outcomes.

14.4 Sequential Monte Carlo for monitoring

A trial that is monitored continuously needs the posterior after every patient. Rerunning a Markov chain from scratch each time is wasteful. Sequential Monte Carlo carries a weighted sample of parameter values forward, reweighting each particle by the likelihood of the new observation and resampling (Chopin 2002). For static parameters a move step, a few Markov chain iterations on each particle, restores diversity. The cost per update is small, and it stays roughly constant when the move step uses sufficient statistics rather than the full data, which matches the operational rhythm of a trial.

A beta binomial model shows the mechanism, because the exact posterior is available for comparison. The sketch below carries 5000 particles for a response rate through 100 patients with a true rate of 0.3 and a uniform prior. After each patient it reweights, resamples every time, and applies one random walk Metropolis move to each particle, which keeps the particles from collapsing onto a few distinct values. Without the move step the 5000 particles had already collapsed onto about 50 distinct values after 100 patients, and the upper quantile was off.

Show the R code
set.seed(13)
y <- rbinom(100, 1, 0.3); th <- runif(5000); s <- 0
for (i in seq_along(y)) {
  s <- s + y[i]
  th <- sample(th, replace = TRUE, prob = if (y[i]) th else 1 - th)
  prop <- abs(th + rnorm(5000, 0, 0.05)); prop <- ifelse(prop > 1, 2 - prop, prop)
  lr <- s * log(prop / th) + (i - s) * log((1 - prop) / (1 - th))
  th <- ifelse(log(runif(5000)) < lr, prop, th)
}
a <- 1 + sum(y); b <- 1 + sum(1 - y)
knitr::kable(data.frame(method = c("SMC", "Exact"),
  mean = c(mean(th), a / (a + b)), sd = c(sd(th), sqrt(a * b / ((a + b)^2 * (a + b + 1)))),
  upper95 = c(unname(quantile(th, 0.975)), qbeta(0.975, a, b))), digits = 3)
Table 14.1: Sequential Monte Carlo (5000 particles, resampling and one Metropolis move at every patient) against the exact beta posterior after 100 patients.
method mean sd upper95
SMC 0.255 0.043 0.340
Exact 0.255 0.043 0.343

14.5 Simulating designs

The operating characteristics of a Bayesian design, its type I error under the monitoring plan, power, expected sample size and expected duration, are computed by simulating thousands of trials under each scenario, and each simulated trial may require dozens of posterior computations. For conjugate designs this is cheap. For designs with hierarchical models it can be expensive, and three techniques help: precomputing posterior summaries on a grid of sufficient statistics; using importance sampling to reuse simulations across scenarios; and emulating the design surface, the expected utility as a function of design parameters, with a smooth regression fitted to a moderate number of simulations, as Müller and Parmigiani (1995) proposed.

14.6 Generative Bayesian computation

Generative Bayesian computation (Polson, Ruggeri, and Sokolov 2024) learns the map from data to posterior once, by training a neural network on simulated pairs of parameters and data, and then evaluates it on any new data set at negligible cost. For trial design this is well suited: the same model is applied to millions of simulated trials, and to the real trial’s data at each interim, so the cost of training is amortized across the whole design exercise. The network can output posterior quantiles directly, which are what decision rules use. The method also handles models whose likelihood is intractable but which can be simulated, such as agent based models of recruitment or complex multistate disease models. Its outputs must be validated against exact posteriors on cases where those are available, and that validation is part of the design documentation.

14.7 AI agents as computerized systems

AI agents, language models that can run code, query databases and draft documents, were beginning to be used in trial operations in 2026. Chapter 9 of Sokolova and Sokolov (2026) sets out the principle that governs them: an agent is a computerized system and must withstand inspection. Every use requires validation, an audit trail, and a named person accountable for each decision. Uses that support a named person, such as filing in the trial master file, generating data queries, and prescreening patients for eligibility as decision support, are easier to validate and audit than uses that would replace investigator judgment.

For Bayesian design specifically, agents can do four useful things. They can run the simulation report, executing the validated design code under each scenario and assembling the operating characteristics. They can check calibration, verifying that the realized type I error under the monitoring plan matches what the protocol claims. They can draft the statistical analysis plan from a machine readable protocol written to the ICH M11 template and technical specification, final since November 2025 (International Council for Harmonisation 2025), or to the CDISC Unified Study Definitions Model, which is aligned with M11 (CDISC 2025). And they can recompute a registered prior and the resulting posterior or e value from the deposited data and code.

The last of these matters for the argument of Chapter 12. A regulator that can cheaply recompute a sponsor’s analysis has a cheaper audit technology, and a cheaper audit technology optimally buys a larger permitted analysis set, under the conditions of Proposition 12.1. AI agents that make reproduction routine therefore support the move from regulating the protocol to regulating the prior.

14.8 What must be documented

A Bayesian analysis submitted to a regulator should include the prior, its derivation and its effective sample size; the likelihood; the decision rule; the code, with versions and random seeds; the simulation report with the scenarios considered; and diagnostics for any Monte Carlo computation. The January 2026 FDA draft guidance (FDA 2026) asks for a simulation report with the simulation code, and, for the trial analysis, the software versions, the analysis code and the Markov chain Monte Carlo seed numbers, and every computational choice in this chapter should be made with that requirement in mind.

NoteKey points
  • Conjugate updates and quadrature cover most interim decisions; Gibbs sampling and Hamiltonian Monte Carlo cover hierarchical models, with recorded seeds and convergence checks.
  • Pólya Gamma augmentation gives exact Gibbs draws for logistic models with no tuning parameters.
  • Sequential Monte Carlo and generative Bayesian computation update posteriors at a small, steady cost per interim look, and must be validated against exact posteriors where these exist.
  • An AI agent is a computerized system: it needs validation, an audit trail and a named accountable person.
  • Cheap reproduction by agents strengthens the case for regulating the prior rather than the protocol.
TipDiscussion questions
  1. Write a Gibbs sampler for the hierarchical normal model and apply it to a small multi arm data set on the log odds scale. Compare with the analytic shrinkage.
  2. Derive the full conditional of \(\beta\) in the Pólya Gamma sampler from the mixture representation.
  3. Remove the move step from the sequential Monte Carlo sketch, and compare the posterior after 100 patients with the exact beta posterior over repeated runs, counting the distinct particle values.
  4. Design a validation plan for a neural network that outputs the posterior probability \(\Pr(\theta>0\mid y)\), where \(\theta\) is the difference in response rates (treatment minus control) in a two arm binary trial.