Algorithmadvanced
O'Brien-Fleming boundary
Also called O'Brien-Fleming stopping rule.
The group sequential boundary c_k = C sqrt(K/k), very strict at early looks and near the fixed-sample value at the last. C comes from recursive integration and bisection.
- Time
- O(B K m^2) worst
- Space
- O(m) extra
- Where
- B = the number of bisection steps on C; K = the number of analyses; m = the number of quadrature points per analysis
- Model
- Real RAM
- Properties
- deterministicexact up to quadratureofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Peter C. O'Brien, Thomas R. Fleming, 1979
The O'Brien-Fleming boundary is the most used stopping rule for a two-sided group sequential design. With analyses at information levels , it rejects at the first analysis with , where
which is for equally spaced analyses. Early critical values are very large, and the last one is only a little above the fixed-sample value: for and they are 4.56, 3.23, 2.63, 2.28 and 2.04. The constant is the solution of . The algorithm below computes this probability by recursive numerical integration over the canonical joint distribution of the , and finds by bisection. O'Brien and Fleming proposed the boundary in 1979; Pocock's constant boundary, from 1977, is the main alternative and is described under Variants.
In plain words
A trial will look at its data five times. At each look, a score measures the evidence that the treatment works. If the score crosses a line, the trial stops. The O'Brien-Fleming rule sets the lines so that early looks need overwhelming evidence and the last look needs about the usual amount. So a trial stops early only when the result is striking, and a trial that runs to the end is judged almost as if there had been no early looks. The algorithm finds the height of the lines. It tries a height, computes the chance of a false stop at any look when the treatment does nothing, and adjusts the height up or down until that chance is exactly the planned 5%.
The problem
Input. The number of analyses , the information levels (or only their ratios), and the two-sided level .
Model. Under , the scores satisfy and have independent increments , with . This is the canonical joint distribution of the group sequential design page; it is exact for normal data with known variance and holds approximately for most large-sample statistics.
Output. The constant such that
and the critical values . On the score scale the boundary is flat: means .
The algorithm
OBRIEN-FLEMING(K, α, I_1, ..., I_K)- 1
lo ← z_{1-α/2}, hi ← z_{1-α/(2K)} ▷ the root lies in [lo, hi] - 2
while hi - lo > tol do - 3
C ← (lo + hi)/2 - 4
if CROSS(C, I) > α then lo ← C else hi ← C - 5
return C and c_k = C·sqrt(I_K / I_k) for k = 1..K CROSS(C, I_1, ..., I_K) ▷ P_0(|S_k| ≥ C·sqrt(I_K) for some k)- 6
b ← C·sqrt(I_K) - 7
p ← 2Φ̄(b / sqrt(I_1)); g ← density of N(0, I_1) on [-b, b] - 8
for k ← 2 to K do - 9
σ ← sqrt(I_k - I_{k-1}) - 10
p ← p + ∫_{-b}^{b} g(u)[Φ((-b - u)/σ) + Φ̄((b - u)/σ)] du - 11
g(s) ← ∫_{-b}^{b} g(u) φ((s - u)/σ)/σ du for |s| < b - 12
return p
Lines L6 to L12. The function is the sub-density of on the event that no earlier analysis crossed; its total mass is the probability of reaching analysis . Line L7 handles the first analysis: it crosses with probability , and the rest of the density, restricted to , carries on. Line L10 adds the probability of crossing first at analysis : from a position inside the boundary, the next score is plus an independent step. Line L11 moves the sub-density one step forward by convolution with that step and drops the part outside . This is the recursion of Armitage, McPherson and Rowe (1969).
Lines L1 to L5. The crossing probability decreases as grows. At the last analysis alone crosses with probability , so the total is at least . At every , so each analysis crosses with probability at most and the total is at most . Bisection keeps the root inside and halves the interval each step.
Quadrature. The implementation evaluates the integrals of lines L10 and L11 by Simpson's rule on a grid over with spacing at most . Doubling the grid changes the crossing probability by less than in the examples below.
Example
Take equally spaced analyses, , and . Then and . The first bisection steps are:
| step | CROSS | new interval | |
|---|---|---|---|
| 1 | 2.2679 | 0.02755 | |
| 2 | 2.1139 | 0.04141 | |
| 3 | 2.0369 | 0.05040 | |
| 4 | 2.0754 | 0.04571 | |
| 5 | 2.0562 | 0.04800 | |
| 6 | 2.0466 | 0.04919 |
It converges to . The critical values and their parts of are:
| analysis | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| 4.5617 | 3.2256 | 2.6337 | 2.2809 | 2.0401 | |
| nominal two-sided p-value of | 0.000005 | 0.00126 | 0.00845 | 0.02256 | 0.04134 |
| 0.00001 | 0.00125 | 0.00764 | 0.01668 | 0.02442 |
The last critical value 2.040 corresponds to a nominal p-value of 0.041, so almost all of the 0.05 is still available at the end. With the plain value 1.96 at all five analyses, CROSS gives 0.061 for this shape, and 0.142 for a flat line at 1.96.
The constant for other numbers of analyses, equally spaced, two-sided:
| 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|
| O'Brien-Fleming | 1.9600 | 1.9774 | 2.0040 | 2.0243 | 2.0401 |
| Pocock constant | 1.9600 | 2.1783 | 2.2895 | 2.3613 | 2.4132 |
For the boundary is : each tail of the first analysis has probability 0.00258 and each tail of the second has first-crossing probability 0.02242.
Sample size. With 90% power, the maximum information must be times the fixed-sample information for . The expected information at stopping is 0.750 of the fixed-sample information when , 0.961 when and 1.019 when .
Correctness
The proof is in full below. In outline:
- The recursion is exact. By induction on , the function after line L11 at step is the sub-density of on the event that no analysis crossed. The induction step is the Chapman-Kolmogorov identity for the independent normal increment. So the value returned by line L12 is , before quadrature.
- Monotone in . If , the event "some " is contained in the event "some ", and the difference contains the event with no earlier crossing, which has positive probability. So CROSS is strictly decreasing. It is also continuous, because each has a continuous distribution.
- The bracket. CROSS and, by the union bound, CROSS, since for all .
- Bisection. By 2 and 3 there is exactly one root in , and each step of lines L3 and L4 keeps it inside. After steps the interval has width .
The only approximation is the quadrature in lines L10 and L11; its error is in the grid spacing for the smooth parts of the integrands.
Proof: CROSS computes the crossing probability, and bisection finds the unique O'Brien-Fleming constantfull
Notation is that of the page. Under , and the increments , , are independent with distribution , where and . For let . The O'Brien-Fleming test with constant rejects at the first with , which is the same as since . Let
We prove that CROSS equals when the integrals are exact, and that lines L1 to L5 converge to the unique solution of . Write for the density and , with the sure event.
Lemma 1 (the sub-densities). For and every Borel set ,
where and, for , . The same formula holds for every Borel .
Proof. By induction on . For , is sure and . For , , and the increment is independent of . By the induction hypothesis the restriction of the law of to has density . Conditioning on and using the independence of ,
Tonelli's theorem exchanges the integrals, which gives .
Lemma 2 (CROSS is the crossing probability). If the integrals of lines L10 and L11 are evaluated exactly, then after the iteration of line L8 for , and restricted to . In particular line L12 returns .
Proof. The first crossing happens at exactly one , so . Line L7 sets and on . At step , Lemma 1 with gives
with , which is the term that line L10 adds. Line L11 computes from by the formula of Lemma 1. Induction on completes the proof.
Lemma 3 (monotone and continuous). is continuous and strictly decreasing on .
Proof. Let , with and . Every path with some has , so . The difference is at least the probability of the event . By Lemma 1 with the bound , this probability is , and everywhere because it is a convolution of a positive function on with a normal density (for , is a normal density). So the difference is positive. For continuity, the events change with only through the event , which has probability at most . By continuity of probability along monotone sequences of events, is continuous from both sides.
Lemma 4 (the bracket). With and , .
Proof. The event of crossing contains , which has probability . For , the critical values are all at least , so by the union bound .
Theorem. If CROSS is evaluated exactly, there is exactly one with , and after every iteration of lines L2 to L4 it holds that . The loop stops after iterations, and line L5 returns a value within of , together with the boundary .
Proof. Existence follows from Lemmas 3 and 4 and the intermediate value theorem; uniqueness from strict monotonicity. Line L1 establishes by Lemma 4. At line L4, if then by Lemma 3, so setting keeps in the interval; otherwise and , so setting keeps it. Each iteration halves . Line L5 returns a point of the final interval, of width at most tol, which contains . By Lemma 2, CROSS.
Quadrature. In the implementation the integrals of lines L10 and L11 are computed by Simpson's rule on . The integrands are smooth on this closed interval, so each step has error in the grid spacing ; the computed CROSS is then a close approximation of , and the bisection finds the root of the approximation.
Complexity
One evaluation of CROSS on grid points per analysis costs for the convolution of line L11 and for line L10, so in all. With grid spacing and , , which is for equally spaced analyses. Bisection to width needs evaluations, so the total time is and the extra space is for two grids. For , and , this is about 30 evaluations of a few thousand grid operations each.
Properties
- Flat on the score scale. The rule is : the same bound on the sum at every analysis. This is why it spends so little error early, when the variance of is small.
- Last critical value near . grows slowly with , from 1.960 to 2.040 for . So the final analysis loses little power against the fixed-sample test.
- Small inflation. The maximum information is only 2.7% above the fixed-sample one for and 90% power.
- Dependence on the information levels. depends on the ratios . If the analyses do not occur at the planned levels, the boundary must be recomputed, or the alpha spending function approach used instead.
- A trade-off, not an optimum. Pocock's shape gives a smaller expected sample size when the effect is as large as planned. The O'Brien-Fleming shape gives a smaller maximum, and a smaller expected sample size when there is no effect.
Variants and improvements
Pocock boundary. Pocock (1977) uses the same critical value at every analysis. For and , . Compared with the O'Brien-Fleming boundary:
| , , power 90% | O'Brien-Fleming | Pocock |
|---|---|---|
| critical values | 4.562, 3.226, 2.634, 2.281, 2.040 | 2.413 at every analysis |
| of first crossing at analyses 1 to 5 | 0.00001, 0.00125, 0.00764, 0.01668, 0.02442 | 0.01581, 0.01171, 0.00902, 0.00731, 0.00615 |
| inflation factor | 1.0265 | 1.2065 |
| expected information, | 0.750 | 0.685 |
| expected information, | 0.961 | 1.052 |
| expected information, | 1.019 | 1.177 |
The Pocock design stops sooner when the effect is as planned, but its maximum sample size is 21% larger, and a trial that reaches the last analysis needs , a nominal p-value of 0.016. The same bisection computes it, with and the general crossing routine.
Other variants:
- Wang-Tsiatis family. with . is O'Brien-Fleming and is Pocock. Wang and Tsiatis (1987) searched this family for boundaries with a small expected sample size.
- Spending-function version. Lan and DeMets (1983) give the spending function , which produces boundaries close to O'Brien-Fleming for any times of analysis; see alpha spending function.
- One-sided boundary and futility. For a one-sided test, line L7 and line L10 count only the upper crossing, and an inner futility boundary can be added; the recursion is the same with a different integration range.
- Haybittle-Peto rule. A fixed critical value of 3 at the interim analyses and the fixed-sample value at the end. It resembles O'Brien-Fleming but does not keep the level exactly.
When to use it
Use the O'Brien-Fleming boundary for the efficacy analysis of a confirmatory trial with a few planned interim analyses, where early stopping should need overwhelming evidence and the final analysis should be almost unchanged. Use the Pocock boundary when early stopping for a large effect is the main goal and the larger maximum is acceptable. Use the alpha spending function when the times of the analyses are uncertain, and a fully sequential method such as the SPRT when the data are analysed after every observation.
Pitfalls
- Using 1.96 at the end. The final critical value is , not . A result with does not reject for .
- Analyses at unplanned times. The constant depends on the information ratios. Recompute it for the actual times, or use a spending function from the start.
- Too coarse a quadrature. With few grid points the recursion error can exceed the target accuracy of , mostly at early analyses where the sub-density is narrow. Choose the spacing relative to , as the implementation does.
- Normal approximation at the first analysis. The first critical value 4.56 sits far in the tail, where large-sample approximations for binary or survival data are least accurate.
- Bias after early stopping. The estimate at an early stop is biased away from 0; report a repeated confidence interval or an adjusted estimate.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/obrien-fleming-boundary/. The authors are listed in prov/C11SHN.jsonl.
"""O'Brien-Fleming and Pocock group sequential boundaries.
The statistics Z_1, ..., Z_K follow the canonical joint distribution: the score
S_k = Z_k sqrt(I_k) is a Brownian motion with drift theta observed at the
information levels I_1 < ... < I_K. A two-sided boundary c_1, ..., c_K rejects
H_0 at the first k with |Z_k| >= c_k.
The crossing probabilities are computed by recursive numerical integration
(Armitage, McPherson and Rowe 1969): the sub-density of S_k on the event that
no earlier boundary was crossed is carried from stage to stage on a Simpson
grid. The grid spacing is at most sqrt(I_k - I_(k-1)) / r, so the work of one
evaluation is O(K m^2) for m grid points per stage.
"""
import math
from collections.abc import Callable, Sequence
_SQRT2 = math.sqrt(2.0)
_INV_SQRT_2PI = 1.0 / math.sqrt(2.0 * math.pi)
def _norm_cdf(x: float) -> float:
return 0.5 * math.erfc(-x / _SQRT2)
def _norm_sf(x: float) -> float:
return 0.5 * math.erfc(x / _SQRT2)
def _norm_pdf(x: float) -> float:
return _INV_SQRT_2PI * math.exp(-0.5 * x * x)
def norm_quantile(p: float) -> float:
"""The lower p-quantile of the standard normal, by bisection on erfc to 1e-15."""
if not 0.0 < p < 1.0:
raise ValueError("p must be in (0, 1)")
lo, hi = -40.0, 40.0
for _ in range(200):
mid = 0.5 * (lo + hi)
if _norm_cdf(mid) < p:
lo = mid
else:
hi = mid
if hi - lo < 1e-15:
break
return 0.5 * (lo + hi)
def _simpson_grid(b: float, step: float) -> tuple[list[float], list[float]]:
"""Points and Simpson weights on [-b, b] with an even number of intervals of length <= step."""
n = max(2, 2 * math.ceil(b / step))
h = 2.0 * b / n
xs = [-b + i * h for i in range(n + 1)]
ws = [(1.0 if i in (0, n) else (4.0 if i % 2 else 2.0)) * h / 3.0 for i in range(n + 1)]
return xs, ws
def crossing_probabilities(c: Sequence[float], info: Sequence[float], theta: float = 0.0,
r: int = 16) -> list[tuple[float, float]]:
"""Per-stage crossing probabilities of the two-sided boundary c on the z scale.
Returns a list of pairs (upper_k, lower_k): the probabilities of stopping at
analysis k with Z_k >= c_k or with Z_k <= -c_k, with no earlier crossing,
when the score has drift theta per unit of information. Precondition:
0 < info[0] < info[1] < ..., c_k > 0. Cost O(K m^2) with m about
2 b_k r / sqrt(I_k - I_(k-1)) grid points at stage k.
"""
if len(c) != len(info) or not c:
raise ValueError("c and info must have the same positive length")
out = []
b = c[0] * math.sqrt(info[0])
sd = math.sqrt(info[0])
mu = theta * info[0]
out.append((_norm_sf((b - mu) / sd), _norm_cdf((-b - mu) / sd)))
xs, ws = _simpson_grid(b, sd / r)
g = [_norm_pdf((x - mu) / sd) / sd for x in xs]
for k in range(1, len(c)):
delta = info[k] - info[k - 1]
if delta <= 0:
raise ValueError("information levels must increase")
sd = math.sqrt(delta)
mu = theta * delta
b = c[k] * math.sqrt(info[k])
up = sum(w * gu * _norm_sf((b - u - mu) / sd) for u, w, gu in zip(xs, ws, g))
lo = sum(w * gu * _norm_cdf((-b - u - mu) / sd) for u, w, gu in zip(xs, ws, g))
out.append((up, lo))
if k + 1 < len(c):
nxs, nws = _simpson_grid(b, min(sd, math.sqrt(info[k + 1] - info[k])) / r)
wg = [w * gu for w, gu in zip(ws, g)]
g = [sum(a * _norm_pdf((s - u - mu) / sd) for u, a in zip(xs, wg)) / sd for s in nxs]
xs, ws = nxs, nws
return out
def total_crossing(c: Sequence[float], info: Sequence[float], theta: float = 0.0, r: int = 16) -> float:
"""P(|Z_k| >= c_k for some k) under drift theta (two-sided rejection probability)."""
return sum(u + l for u, l in crossing_probabilities(c, info, theta, r))
def _shape(kind: str, info: Sequence[float]) -> list[float]:
if kind == "obrien-fleming":
return [math.sqrt(info[-1] / i) for i in info]
if kind == "pocock":
return [1.0 for _ in info]
raise ValueError("kind must be 'obrien-fleming' or 'pocock'")
def boundary_constant(kind: str, k_looks: int, alpha: float = 0.05, info: Sequence[float] | None = None,
tol: float = 1e-9, r: int = 16,
cross: Callable[..., float] | None = None) -> tuple[float, list[float]]:
"""The constant C and the z-scale boundary c_k = C shape_k at two-sided level alpha.
kind is "obrien-fleming" (c_k = C sqrt(I_K / I_k)) or "pocock" (c_k = C).
info defaults to equal spacing 1, 2, ..., K. Bisection on C to width tol;
each step costs one evaluation of total_crossing.
"""
if info is None:
info = [float(i) for i in range(1, k_looks + 1)]
if len(info) != k_looks or k_looks < 1:
raise ValueError("info must have k_looks entries")
if not 0.0 < alpha < 1.0:
raise ValueError("alpha must be in (0, 1)")
cross = cross or total_crossing
shape = _shape(kind, info)
lo = norm_quantile(1.0 - alpha / 2.0) # @line L1
hi = norm_quantile(1.0 - alpha / (2.0 * k_looks)) # @line L1
while hi - lo > tol: # @line L2
mid = 0.5 * (lo + hi) # @line L3
if cross([mid * s for s in shape], info, 0.0, r) > alpha: # @line L4
lo = mid
else:
hi = mid
big_c = 0.5 * (lo + hi)
return big_c, [big_c * s for s in shape] # @line L5
def obrien_fleming_boundary(k_looks: int, alpha: float = 0.05, info: Sequence[float] | None = None,
tol: float = 1e-9, r: int = 16) -> tuple[float, list[float]]:
"""O'Brien-Fleming: c_k = C sqrt(I_K / I_k), two-sided level alpha.
Returns (C, [c_1, ..., c_K]). For K = 5 equally spaced looks and
alpha = 0.05, C is about 2.0401.
"""
return boundary_constant("obrien-fleming", k_looks, alpha, info, tol, r)
def pocock_boundary(k_looks: int, alpha: float = 0.05, info: Sequence[float] | None = None,
tol: float = 1e-9, r: int = 16) -> tuple[float, list[float]]:
"""Pocock: c_k = C at every look, two-sided level alpha."""
return boundary_constant("pocock", k_looks, alpha, info, tol, r)
def cross_on_score_scale(big_c: float, info: Sequence[float], r: int = 16) -> float:
"""CROSS(C, I) of the pseudocode: the O'Brien-Fleming boundary is |S_k| >= C sqrt(I_K)."""
b = big_c * math.sqrt(info[-1]) # @line L6
sd = math.sqrt(info[0])
p = 2.0 * _norm_sf(b / sd) # @line L7
xs, ws = _simpson_grid(b, sd / r)
g = [_norm_pdf(x / sd) / sd for x in xs] # @line L7
for k in range(1, len(info)): # @line L8
sd = math.sqrt(info[k] - info[k - 1]) # @line L9
p += sum(w * gu * (_norm_cdf((-b - u) / sd) + _norm_sf((b - u) / sd)) # @line L10
for u, w, gu in zip(xs, ws, g))
if k + 1 < len(info):
nxs, nws = _simpson_grid(b, min(sd, math.sqrt(info[k + 1] - info[k])) / r)
wg = [w * gu for w, gu in zip(ws, g)]
g = [sum(a * _norm_pdf((s - u) / sd) for u, a in zip(xs, wg)) / sd for s in nxs] # @line L11
xs, ws = nxs, nws
return p # @line L12
def expected_information(c: Sequence[float], info: Sequence[float], theta: float = 0.0, r: int = 16) -> float:
"""E[I_T], the expected information at stopping, where T is the stage of stopping (K if no crossing)."""
probs = crossing_probabilities(c, info, theta, r)
stop = [u + l for u, l in probs]
return sum(p * i for p, i in zip(stop[:-1], info[:-1])) + (1.0 - sum(stop[:-1])) * info[-1]
test_obrien_fleming_boundary.py 154 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/obrien-fleming-boundary/. The authors are listed in prov/C11SHN.jsonl.
import math
import random
import pytest
from obrien_fleming_boundary import (
boundary_constant,
cross_on_score_scale,
crossing_probabilities,
expected_information,
norm_quantile,
obrien_fleming_boundary,
pocock_boundary,
total_crossing,
)
def phi(x: float) -> float:
return math.exp(-0.5 * x * x) / math.sqrt(2.0 * math.pi)
def upper(x: float) -> float:
return 0.5 * math.erfc(x / math.sqrt(2.0))
def two_look_quadrature(c1: float, c2: float, t1: float, n: int = 400) -> float:
"""P(|Z1| >= c1 or (|Z1| < c1 and |Z2| >= c2)) with Z2 | Z1 = z ~ N(sqrt(t1) z, 1 - t1).
One-dimensional composite Simpson rule on the z scale: an oracle that does
not share the score-scale recursion of the code under test.
"""
s, v = math.sqrt(t1), math.sqrt(1.0 - t1)
h = 2.0 * c1 / n
acc = 0.0
for i in range(n + 1):
z = -c1 + i * h
w = 1.0 if i in (0, n) else (4.0 if i % 2 else 2.0)
acc += w * phi(z) * (upper((c2 - s * z) / v) + upper((c2 + s * z) / v))
return 2.0 * upper(c1) + acc * h / 3.0
def test_one_look_is_the_fixed_sample_test():
c, bounds = obrien_fleming_boundary(1)
assert abs(c - 1.959964) < 1e-6
assert bounds == [c]
p, _ = pocock_boundary(1)
assert abs(p - c) < 1e-9
def test_worked_example_five_looks():
c, bounds = obrien_fleming_boundary(5)
assert abs(c - 2.0401) < 1e-4
expected = [4.5617, 3.2256, 2.6337, 2.2809, 2.0401]
assert all(abs(a - b) < 1e-4 for a, b in zip(bounds, expected))
p, pb = pocock_boundary(5)
assert abs(p - 2.4132) < 1e-4
assert all(abs(x - p) < 1e-12 for x in pb)
@pytest.mark.parametrize("k", [2, 3, 4, 5])
def test_total_level_is_alpha(k):
for kind in ("obrien-fleming", "pocock"):
_, bounds = boundary_constant(kind, k)
assert abs(total_crossing(bounds, list(range(1, k + 1))) - 0.05) < 1e-6
def test_grid_doubling_converges():
info = [1.0, 2.0, 3.0, 4.0, 5.0]
p8, p16, p32 = (cross_on_score_scale(2.0401, info, r=r) for r in (8, 16, 32))
assert abs(p16 - p32) < 1e-8
assert abs(p8 - p32) < 1e-7
def test_score_scale_cross_matches_z_scale():
info = [1.0, 2.0, 3.0, 4.0, 5.0]
for c in (1.8, 2.04, 2.3):
z_bounds = [c * math.sqrt(5.0 / i) for i in info]
assert abs(cross_on_score_scale(c, info) - total_crossing(z_bounds, info)) < 1e-12
def test_crossing_decreases_in_c():
info = [1.0, 2.0, 3.0]
values = [cross_on_score_scale(c, info) for c in (1.5, 1.8, 2.0, 2.2, 2.5)]
assert all(a > b for a, b in zip(values, values[1:]))
def test_two_looks_against_quadrature():
for kind in ("obrien-fleming", "pocock"):
_, (c1, c2) = boundary_constant(kind, 2)
assert abs(two_look_quadrature(c1, c2, 0.5) - 0.05) < 1e-7
def test_random_two_look_boundaries_against_quadrature():
rng = random.Random(20260314)
for _ in range(500):
t1 = rng.uniform(0.1, 0.9)
c1 = rng.uniform(1.0, 4.0)
c2 = rng.uniform(1.0, 4.0)
got = total_crossing([c1, c2], [t1, 1.0])
# Both sides use Simpson grids; their discretization errors stay below 5e-7.
assert abs(got - two_look_quadrature(c1, c2, t1)) < 5e-7
def test_monte_carlo_level_and_stage_split():
rng = random.Random(7)
_, bounds = obrien_fleming_boundary(5)
reps = 20000
hits = 0
for _ in range(reps):
s = 0.0
for k in range(1, 6):
s += rng.gauss(0.0, 1.0)
if abs(s / math.sqrt(k)) >= bounds[k - 1]:
hits += 1
break
se = math.sqrt(0.05 * 0.95 / reps)
assert abs(hits / reps - 0.05) < 4 * se
def test_unequal_information_and_drift():
info = [0.3, 0.7, 1.0]
c, bounds = obrien_fleming_boundary(3, info=info)
assert abs(total_crossing(bounds, info) - 0.05) < 1e-6
# Under drift the rejection probability rises, and early stops cut the expected information.
assert total_crossing(bounds, [i * 10 for i in info], theta=1.0) > 0.5
assert expected_information(bounds, [i * 10 for i in info], theta=1.0) < 10.0
parts = crossing_probabilities(bounds, info)
assert all(abs(u - l) < 1e-12 for u, l in parts)
def test_inflation_factor_five_looks():
fixed = (norm_quantile(0.975) + norm_quantile(0.9)) ** 2
for kind, want in (("obrien-fleming", 1.0265), ("pocock", 1.2065)):
_, bounds = boundary_constant(kind, 5)
def power(imax: float) -> float:
return total_crossing(bounds, [k / 5 * imax for k in range(1, 6)], theta=1.0)
lo, hi = fixed, 2 * fixed
for _ in range(40):
mid = 0.5 * (lo + hi)
lo, hi = (mid, hi) if power(mid) < 0.9 else (lo, mid)
assert abs(lo / fixed - want) < 1e-3
def test_bad_input():
with pytest.raises(ValueError):
obrien_fleming_boundary(3, info=[1.0, 2.0])
with pytest.raises(ValueError):
total_crossing([2.0, 2.0], [1.0, 1.0])
with pytest.raises(ValueError):
boundary_constant("haybittle", 3)
History
Armitage, McPherson and Rowe (1969) showed how much repeated significance tests inflate the type I error and computed the inflation by recursive numerical integration. Pocock (1977) turned this into practical group sequential designs with a constant critical value. O'Brien and Fleming (1979) proposed critical values proportional to , so that early stopping needs very strong evidence; this shape became the standard for efficacy monitoring. Lan and DeMets (1983) gave the spending function that approximates it at analysis times not fixed in advance, and Wang and Tsiatis (1987) placed both boundaries in a one-parameter family.
References
- Peter C. O'Brien and Thomas R. Fleming, A multiple testing procedure for clinical trials, Biometrics 35(3) (1979), pages 549 to 556, the definition of the boundary, with critical values proportional to the square root of K/k
- Stuart J. Pocock, Group sequential methods in the design and analysis of clinical trials, Biometrika 64(2) (1977), pages 191 to 199, the constant boundary and its table of critical values for equally spaced analyses
- P. Armitage, C. K. McPherson and B. C. Rowe, Repeated significance tests on accumulating data, Journal of the Royal Statistical Society, Series A 132(2) (1969), the recursive numerical integration of the probability of crossing a boundary for sums of normal variables
- Samuel K. Wang and Anastasios A. Tsiatis, Approximately optimal one-parameter boundaries for group sequential trials, Biometrics 43(1) (1987), the family of boundaries proportional to (k/K) to the power Delta minus 1/2, which contains the O'Brien-Fleming and Pocock shapes
- Christopher Jennison and Bruce W. Turnbull, Group Sequential Methods with Applications to Clinical Trials, Chapman and Hall/CRC, 2000, Chapter 2 (the Pocock and O'Brien-Fleming tests, their constants and their inflation factors)
- K. K. Gordon Lan and David L. DeMets, Discrete sequential boundaries for clinical trials, Biometrika 70(3) (1983), pages 659 to 663, the spending function that approximates the O'Brien-Fleming boundary for analyses at times not fixed in advance
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag C11SHN Edit this page History Report an error Markdown