ShiftBounds([1..30], [21..50], 1e-4) = [-30, -10] where Shift = -20
Bounds fail to cover true shift with probability ≈misrate
ShiftBounds provides not just the estimated shift but also the uncertainty of that estimate. The function returns an interval of plausible shift values given the data. Set misrate to control how often the bounds might fail to contain the true shift: use 10−3 for everyday analysis or 10−6 for critical decisions where errors are costly. These bounds require no assumptions about your data distribution, so they remain valid for any continuous measurements. If the bounds exclude zero, that suggests a reliable difference between the two groups.
See also:Compare2 for comparing Shift against practical thresholds with automatic verdict generation.
Algorithm
The ShiftBounds estimator constructs distribution-free bounds on Shift(x,y) by selecting specific order statistics from the pairwise differences.
Given samples x=(x1,…,xn) and y=(y1,…,ym), the algorithm proceeds as follows:
Compute the margin Call PairwiseMargin(n,m,misrate) (see PairwiseMargin) to determine how many extreme pairwise differences to exclude from each tail.
Determine quantile ranks From the margin M, compute kleft=⌊M/2⌋+1 and kright=nm−⌊M/2⌋. These are the ranks of the order statistics that form the bounds.
Compute quantiles via Shift Use the Shift algorithm to compute the kleft-th and kright-th order statistics of all nm pairwise differences xi−yj. The Shift algorithms value-space binary search finds these quantiles in O((n+m)logL) time without materializing all differences.
Return bounds Return [z(kleft),z(kright)].
The PairwiseMargin function encodes the statistical theory: it determines which order statistics provide bounds with coverage 1−misrate. The Shift algorithm provides the computational machinery: it extracts those specific order statistics efficiently from the implicit matrix of pairwise differences.
Notes
Width Convergence
The table below shows how Width=U−L narrows as N grows, for x=y=(1,1+1/(N−1),…,2) (N evenly spaced points on [1,2]) and misrate=10−3. Dashes indicate N too small to achieve the target misrate.
The ShiftBounds test suite contains 63 test cases (3 demo + 9 natural + 6 property + 10 edge + 9 additive + 4 uniform + 5 misrate + 15 unsorted + 2 error). Since ShiftBounds returns bounds rather than a point estimate, tests validate that the bounds contain Shift(x,y) and satisfy equivariance properties. Each test case output is a JSON object with lower and upper fields representing the interval bounds. The domain constraint misrate≥2/(nn+m) is enforced; inputs violating this return a domain error.
Demo examples (n=m=5) — from manual introduction, validating basic bounds:
These cases illustrate how tighter misrates produce wider bounds and validate the identity property where identical samples yield bounds containing zero.
The asymmetric size combinations are particularly important for testing margin calculation with unbalanced samples.
Misrate variation (n=m=20, x=(0,2,4,…,38), y=(10,12,14,…,48)) — 5 tests from a loose achievable fixture misrate down to 10−6:
These tests use identical samples with varying misrates to validate the monotonicity property: smaller misrates (higher confidence) produce wider bounds. The sequence demonstrates how bound width increases as misrate decreases, helping implementations verify correct margin calculation.
Unsorted tests — verify independent sorting of x and y (15 tests):
unsorted-x-natural-5-5: x=(5,3,1,4,2), y=(1,2,3,4,5) (X reversed, Y sorted)
unsorted-y-natural-5-5: x=(1,2,3,4,5), y=(5,3,1,4,2) (X sorted, Y reversed)
unsorted-asymmetric-5-10: x=(2,5,1,3,4), y=(10,5,2,8,4,1,9,3,7,6) (asymmetric sizes, both unsorted)
unsorted-duplicates: x=(3,3,3,3,3), y=(5,5,5,5,5) (all duplicates, any order)
unsorted-mixed-duplicates-x: x=(2,1,3,2,1), y=(1,1,2,2,3) (X has unsorted duplicates)
unsorted-mixed-duplicates-y: x=(1,1,2,2,3), y=(3,2,1,3,2) (Y has unsorted duplicates)
These unsorted tests are critical because ShiftBounds computes bounds from pairwise differences, requiring both samples to be sorted independently. The variety ensures implementations dont incorrectly assume pre-sorted input or sort samples together. Each test must produce identical output to its sorted counterpart, validating that the implementation correctly handles the sorting step.
Error cases — input validation (2 tests):
error-empty-x: x=(), y=(1,2,3,4,5) — empty X array violates validity
error-empty-y: x=(1,2,3,4,5), y=() — empty Y array violates validity
No performance test — ShiftBounds uses the FastShift algorithm internally, which is already validated by the Shift performance test. Since bounds computation involves only two quantile calculations from the pairwise differences (at positions determined by PairwiseMargin), the performance characteristics are equivalent to computing two Shift estimates, which completes efficiently for large samples.