Signature
m_mu = sum_(i=1)^k [y_i / (s_i^2 + tau2)] / sum_(i=1)^k [1 / (s_i^2 + tau2)]; sd_mu = sqrt(1 / sum_(i=1)^k [1 / (s_i^2 + tau2)])
| Inputs | Definition | Unit |
|---|---|---|
y_i | Effect estimate reported by trial i on a scale where it is approximately normal, such as a log odds ratio | the effect scale |
s_i | Standard error of y_i; its square s_i^2 is the within-trial variance, treated as known | the effect scale |
tau2 | Between-study variance, the square of the between-study standard deviation tau, held at a chosen value | squared units of the effect scale |
m_mu | Posterior mean of the mean effect mu given the trial data and a fixed tau2 | the effect scale, for example a log odds ratio |
|---|---|---|
sd_mu | Posterior standard deviation of mu given the trial data and a fixed tau2 | the effect scale |
kNumber of trials pooled, equal to the length of the y_i and s_i lists (count)
Function
Bayesian random-effects posterior for a pairwise meta-analysis
Maps each trial's effect estimate y_i and standard error s_i, together with priors for the mean effect mu and the between-study standard deviation tau, to a joint posterior distribution for mu and tau. The trial-level true effects are integrated out, so each estimate contributes a normal likelihood with variance s_i^2 + tau^2. The posterior of the mean effect, shrunken trial estimates and the predictive distribution of the effect in a new setting all follow from this joint posterior, and posterior draws can pass directly into a probabilistic cost-effectiveness model. Frequentist pooling of the same data, including the DerSimonian and Laird estimate, Cochran's Q, I-squared and the prediction interval, is covered under aggregate data meta-analysis (HE-FN-ADMA-001).
Computational function
Computational function: grid posterior over the between-study standard deviation in a Bayesian meta-analysis
Takes the trial estimates and standard errors of a pairwise meta-analysis and a prior for the between-study standard deviation tau, and returns the posterior median of tau and the posterior probability that the mean effect mu is below zero by numerical integration over a fine grid of tau values. At each grid value it applies HE-FM-BMA-001 to get the conditional posterior mean and precision of mu, weights the grid value by its prior density times the marginal likelihood of the data with mu integrated out, and normalises the weights. The inputs differ from the formula's variables: the formula takes one fixed tau2, while the function takes a prior over tau and a grid and averages over them. This is the numerical integration route that Turner and colleagues describe as an alternative to MCMC for a summary-data meta-analysis.
Inputs and outputs:
y: Vector of trial effect estimates on the log odds ratio scale; required, at least two trials. Unit: log odds ratio.;s: Vector of the standard errors of y, in the same order; required, all above zero. Unit: log odds ratio.;logprior: Log prior density of tau up to a constant, as a function of tau: 0 for U(0, 2), or-log(t)-(2*log(t)+3.95)^2/(2*1.34^2)for tau2 ~ LN(-3.95, 1.34^2), where the first term converts a density for tau2 into one for tau; required. Unit: none.;J: Number of grid points; optional, default 20000. Unit: count.;tmax: Upper end of the grid for tau; optional, default 2. Unit: log odds ratio.;post_j: Posterior probability of grid point j. Unit: probability.;tau_med: Posterior median of tau. Unit: log odds ratio.;P_mu_neg: Posterior probability that mu is below zero. Unit: probability.Assumption: Each estimate is normal with known variance s_i^2, the true effects are exchangeable draws from N(mu, tau^2) and mu has a flat prior, which gives the same results to the decimals shown as the N(0, 100^2) prior used in the article. The prior for tau places a negligible share of its probability above tmax: none for U(0, 2), and well under 0.1% for the Turner mortality prior. Grid points are the midpoints (j-0.5)*tmax/J, so tau = 0 is never evaluated.
Worked example (Four mortality trials under the vague U(0, 2) prior): The article's analysis A gives a posterior median of tau of about 0.280 and a probability of about 0.890 that the mean log odds ratio is below zero.
y = (-0.45, -0.10, -0.60, 0.05); s = (0.20, 0.15, 0.30, 0.25); logprior = 0; J = 20000; tmax = 2; tau_med = 0.280; P_mu_neg = 0.890Worked example (Four mortality trials under the Turner mortality prior): The article's analysis B, with tau2 ~ LN(-3.95, 1.34^2), gives a posterior median of tau of about 0.133 and a probability of about 0.961 that the mean log odds ratio is below zero.
y = (-0.45, -0.10, -0.60, 0.05); s = (0.20, 0.15, 0.30, 0.25); logprior = -log(t)-(2*log(t)+3.95)^2/(2*1.34^2); J = 20000; tmax = 2; tau_med = 0.133; P_mu_neg = 0.961Excel:
=(ROW()-1.5)*0.0001in A2,=SUMPRODUCT(1/(StudySE^2+A2^2))in B2,=SUMPRODUCT(StudyEst/(StudySE^2+A2^2))/B2in C2,=0.5*SUMPRODUCT(LN(1/(StudySE^2+A2^2))-(StudyEst-C2)^2/(StudySE^2+A2^2))-0.5*LN(B2)in D2,=-LN(A2)-(2*LN(A2)+3.95)^2/(2*1.34^2)in E2 (or 0 for the U(0, 2) prior),=D2+E2in F2,=EXP(F2-$L$1)in G2,=G2/$L$2in H2,=H2in I2 and=I2+H3in I3,=H2*NORM.S.DIST(-C2*SQRT(B2),TRUE)in J2, with=MAX(F2:F20001)in L1,=SUM(G2:G20001)in L2,=INDEX(A2:A20001,MATCH(TRUE,INDEX(I2:I20001>=0.5,0),0))in L3 and=SUM(J2:J20001)in L4. With the trial estimates in a range named StudyEst and the standard errors in StudySE, rows 2 to 20001 hold the grid of 20000 values of tau from 0 to 2 (I3 is filled down to I20001, the other columns from row 2), L3 returns tau_med and L4 returns P_mu_neg.R:
bma_grid <- function(y, s, logprior, J = 20000, tmax = 2) { tau <- (seq_len(J)-0.5)*tmax/J; W <- sapply(tau, function(t) sum(1/(s^2+t^2))); m <- sapply(tau, function(t) sum(y/(s^2+t^2)))/W; lp <- sapply(seq_len(J), function(j) { w <- 1/(s^2+tau[j]^2); 0.5*sum(log(w)-w*(y-m[j])^2) })-0.5*log(W)+logprior(tau); post <- exp(lp-max(lp)); post <- post/sum(post); c(tau_med = tau[which(cumsum(post) >= 0.5)[1]], P_mu_neg = sum(post*pnorm(-m*sqrt(W)))) }Vectorised over the grid;bma_grid(c(-0.45, -0.10, -0.60, 0.05), c(0.20, 0.15, 0.30, 0.25), function(t) 0*t)reproduces analysis A andfunction(t) -log(t)-(2*log(t)+3.95)^2/(2*1.34^2)as the third argument reproduces analysis B.Python:
def bma_grid(y, s, logprior, J=20000, tmax=2.0): tau = [(j+0.5)*tmax/J for j in range(J)]; W = [sum(1/(si**2+t**2) for si in s) for t in tau]; m = [sum(yi/(si**2+t**2) for yi, si in zip(y, s))/Wj for t, Wj in zip(tau, W)]; lp = [0.5*sum(math.log(1/(si**2+t**2))-(yi-mj)**2/(si**2+t**2) for yi, si in zip(y, s))-0.5*math.log(Wj)+logprior(t) for t, Wj, mj in zip(tau, W, m)]; top = max(lp); post = [math.exp(v-top) for v in lp]; tot = sum(post); post = [p/tot for p in post]; tau_med = next(t for t, c in zip(tau, itertools.accumulate(post)) if c >= 0.5); P_mu_neg = sum(p*0.5*math.erfc(mj*math.sqrt(Wj)/math.sqrt(2)) for p, mj, Wj in zip(post, m, W)); return tau_med, P_mu_negUses the math and itertools modules and plain lists; math.erfc gives the normal tail probability, and logprior is a function of a single value of tau, for examplelambda t: 0.0.Test (Posterior grid weights sum to one): The normalised weights in H2:H20001 add up to 1. Expected result: TRUE. Excel check:
=ABS(SUM(H2:H20001)-1)<1E-9Test (Halving the number of grid points leaves the results unchanged): Rerunning with J = 10000 changes tau_med and P_mu_neg by less than 0.001 for the article's trials under either prior. Expected result: TRUE. R check, with y, s and the log prior lp set as in the worked examples:
all(abs(bma_grid(y, s, lp, J = 10000)-bma_grid(y, s, lp)) < 0.001)Common error (Leaving out the change of variable when a tau2 prior is used on a tau grid): The Turner priors are densities for tau2. Using the log-normal term without the leading -log(t) treats the density for tau2 as a density for tau and, for the article's trials, gives a posterior median of tau of about 0.187 instead of 0.133 and a probability of about 0.943 instead of 0.961 that mu is below zero.
Source: Turner RM, Jackson D, Wei Y, Thompson SG, Higgins JPT. Predictive distributions for between-study heterogeneity and simple methods for their application in Bayesian meta-analysis. Statistics in Medicine. 2015;34(6):984-998. Section 2.2, which evaluates the constant of proportionality, posterior moments and cumulative distribution functions of the mean effect and tau2 by numerical integration and finds percentiles with a search algorithm. The vague U(0, 2) prior on tau is from Dias S, Welton NJ, Sutton AJ, Ades AE. NICE DSU TSD 2, section 6.2.
tau_j = (j - 0.5) * tmax / J; w_ij = 1 / (s_i^2 + tau_j^2); W_j = sum_i(w_ij); m_j = sum_i(w_ij * y_i) / W_j; lp_j = 0.5 * sum_i(log(w_ij) - w_ij * (y_i - m_j)^2) - 0.5 * log(W_j) + logprior(tau_j); post_j = exp(lp_j - max(lp)) / sum_j(exp(lp_j - max(lp))); tau_med = smallest tau_j with sum_(l<=j)(post_l) >= 0.5; P_mu_neg = sum_j(post_j * Phi(-m_j * sqrt(W_j)))
Try this function
Implementations
Excel
Conditional posterior mean and standard deviation of mu from two ranges
With the trial estimates in a range named StudyEst, their standard errors in a range of the same size named StudySE and the fixed between-study variance in a cell named BetweenVar, the first formula returns m_mu and the second sd_mu.
=SUMPRODUCT(StudyEst/(StudySE^2+BetweenVar))/SUMPRODUCT(1/(StudySE^2+BetweenVar)); =SQRT(1/SUMPRODUCT(1/(StudySE^2+BetweenVar)))
Assumptions
Normal summary likelihood with known within-trial variances in a Bayesian meta-analysis
Each trial estimate y_i is approximately normal around the trial's true effect with variance s_i^2, treated as known. NICE DSU TSD 2 works mainly with arm-level likelihoods such as binomial counts; this summary-effect form applies when trials report an effect estimate and its standard error.
Flat or vague prior on the mean effect in a Bayesian meta-analysis
The prior on mu is flat or so diffuse that it adds almost nothing to the summed weights. The N(0, 100^2) prior used in the article adds a precision of 0.0001 against summed weights of about 62, which changes the result only beyond the fourth decimal place. An informative prior on mu would add its own precision and pull the mean towards the prior mean.
Exchangeable trial effects in a Bayesian random-effects model
The true trial effects are treated as exchangeable draws from N(mu, tau2): the trial labels carry no information about which trials have larger effects. Trials that differ in effect modifiers or risk of bias break this assumption, and no prior repairs it.
Worked examples
Four mortality trials at the Turner prior median of tau2
Four illustrative placebo-controlled trials report log odds ratios for all-cause mortality of -0.45, -0.10, -0.60 and 0.05 with standard errors of 0.20, 0.15, 0.30 and 0.25. At tau2 = 0.0193, the median of the Turner prior used in the article, the weights are about 16.863, 23.923, 9.149 and 12.225, summing to about 62.16. The conditional posterior mean is about -0.239 with a standard deviation of about 0.127, as in the article.
k = 4; y_i = [-0.45,-0.10,-0.60,0.05]; s_i = [0.20,0.15,0.30,0.25]; tau2 = 0.0193; m_mu = -0.2390; sd_mu = 0.1268
Four mortality trials with tau2 set to zero
With tau2 set to zero the weights are the common-effect weights of about 25, 44.444, 11.111 and 16, and the result is the common-effect estimate of about -0.2233 with a standard deviation of about 0.1018. The mean moves towards trial 2, the most precise trial, compared with -0.2390 at tau2 = 0.0193.
k = 4; y_i = [-0.45,-0.10,-0.60,0.05]; s_i = [0.20,0.15,0.30,0.25]; tau2 = 0; m_mu = -0.2233; sd_mu = 0.1018
Common errors
Reporting the posterior of mu at one fixed tau as the full posterior
The formula conditions on one value of tau2 and ignores uncertainty about it. At tau2 = 0.0193 a 95% interval of the conditional posterior gives odds ratios of about 0.614 to 1.010, while the article's full posterior gives 0.593 to 1.032 under the Turner prior and 0.432 to 1.352 under the vague U(0, 2) prior on tau. The gap widens when the prior on tau allows large values.
Entering standard errors where squared standard errors are needed in a Bayesian meta-analysis
The weights need the squared standard errors. Entering 0.20, 0.15, 0.30 and 0.25 as if they were variances gives a conditional posterior mean of about -0.2505 with a standard deviation of about 0.2403 at tau2 = 0.0193, instead of -0.2390 and 0.1268, and makes tau2 look small against the within-trial variation.
Sources
Joint posterior and normal approximation for the mean effect in Turner and colleagues
Turner RM, Jackson D, Wei Y, Thompson SG, Higgins JPT. Predictive distributions for between-study heterogeneity and simple methods for their application in Bayesian meta-analysis. Statistics in Medicine. 2015;34(6):984-998. Section 2, which gives the joint posterior for the mean effect and tau2 with a normal likelihood of variance s_i^2 plus tau2 for each study, and section 2.3, which uses the normal distribution with inverse-variance mean at a fixed tau2 as the usual approximation to the distribution of the average intervention effect.
Hierarchical Bayesian model for meta-analysis in Higgins and colleagues
Higgins JPT, Thompson SG, Spiegelhalter DJ. A re-evaluation of random-effects meta-analysis. Journal of the Royal Statistical Society: Series A. 2009;172(1):137-159. Section 4, which sets out the hierarchical Bayesian model for estimates with known variances, notes that prior independence of mu and tau2 is standard and that minimally informative priors are appropriate without good reason for prior information, and warns that the choice of prior can have substantial effects on the results.
Vague priors for relative effects in NICE DSU TSD 2
Dias S, Welton NJ, Sutton AJ, Ades AE. NICE DSU Technical Support Document 2: A generalised linear modelling framework for pairwise and network meta-analysis of randomised controlled trials. Sheffield: Decision Support Unit, ScHARR, University of Sheffield; 2011, last updated September 2016. Section 6.2, which recommends vague or flat priors such as N(0, 100^2) for trial baselines and relative effects and says that informative priors for relative effects would require special justification.
Canonical Identity
Stable URI · Machine-readable · Resolvable · CC BY 4.0