Tutorials › Propensity Score Matching and Instrumental Variables › Implementing Rosenbaum Bounds in Statistical Software

Rosenbaum Bounds and E-Values · Tutorial 364 of 699

Implementing Rosenbaum Bounds in Statistical Software

You will learn to prepare matched-set inputs and verify one-sided worst-case p-values from a sign statistic over a grid of Gamma values.

Advanced 12 min read

What You'll Learn

  • Represent matched pairs and matched sets with their set identifiers and treatment assignments
  • State the sharp-null and assignment assumptions behind a Rosenbaum sensitivity calculation
  • Calculate worst-case one-sided sign-test p-values at specified Gamma values
  • Verify software results using exact binomial tails and hand calculations
  • Diagnose coding, tie-handling, and interpretation errors
  • Understand when a different test statistic or sensitivity method is needed

Why Software Inputs and Test Statistics Matter

A sensitivity analysis can produce a precise-looking p-value while answering the wrong question if the matched sets are encoded incorrectly or the test statistic is misunderstood. In a Rosenbaum sensitivity analysis, \(\Gamma\) limits how different the treatment assignment odds may be for two units who are matched on measured covariates. The analysis then asks how large a p-value could be under the most unfavorable assignment probabilities allowed by that limit.

This tutorial uses matched pairs and a one-sided sign statistic to make the software calculations transparent. The same principles of checking set structure, direction, and the meaning of the reported bound apply when software uses other statistics. The calculations here are sensitivity analyses of a sharp null, not estimates of a treatment effect and not probabilities that the null is true.

Definition: In a matched-pair design, each set \(i\) contains one treated unit and one control unit. Let \(Y_{iT}\) and \(Y_{iC}\) be their observed outcomes, and define the observed difference \(d_i=Y_{iT}-Y_{iC}\). For a one-sided test that treatment increases the outcome, the sign statistic is \(S=\sum_{i=1}^n I(d_i>0)\), where \(n\) is the number of non-tied pairs included in the test. A Rosenbaum sensitivity parameter \(\Gamma\geq1\) bounds the ratio of treatment assignment odds within a matched set; \(\Gamma=1\) corresponds to equal assignment odds.

What the Software Needs to Represent

For pair-based calculations, the minimum useful input is a pair identifier, an indicator of which unit was treated, and the outcome for each unit. Keep one record per unit rather than collapsing the data before you have checked the matching structure. Each pair should have exactly two records and exactly one treated unit. A pair identifier must identify the matched set—not the person, treatment group, or row number.

A matched set with more than two units is not automatically a matched pair. Many sensitivity procedures can handle sets with one treated unit and multiple controls, but their assignment probabilities and test-statistic calculations differ from the pairwise sign calculation below. Do not split a larger set into artificial pairs unless the design and analysis specifically justify that operation.

The sign statistic also requires a clear direction. For a hypothesized increase, count treated-minus-control differences above zero. If the software instead forms control-minus-treated differences, the signs reverse. Tied pairs have \(d_i=0\): they contribute neither a positive nor a negative sign and should be handled according to the selected test. For the sign test, omit them and report the resulting number of non-tied pairs.

Worked Example: Checking Pair Structure and Signs

Suppose a hypothetical data set has four matched pairs. The outcome is measured in points, and the alternative is that treatment increases the outcome.

PairTreated outcomeControl outcomeDifference \(d_i\)Sign
112102Positive
289-1Negative
315114Positive
4770Tie

The sign-test input contains three non-tied pairs, of which two have positive differences. Thus \(n=3\) and \(S=2\). The fourth pair is not counted as a positive or negative sign. Before running software, a useful check is to independently recompute these differences from the treated and control columns and confirm that the alternative agrees with the sign being counted.

Assignment Model and Worst-Case Sign-Test Bound

The sensitivity calculation is based on the sharp null hypothesis that treatment has no effect on any unit’s outcome. Under this null, the outcomes are fixed while the treatment label within each pair is varied. The assignment model assumes one treated unit per pair, independent assignment across pairs conditional on the matched design, and treatment-odds ratios within each pair bounded by \(\Gamma\). Under the sharp null and \(\Gamma=1\), each of the two assignments in a pair has probability one-half.

For \(\Gamma>1\), the assignment can favor the member of a pair whose outcome makes the observed direction look more consistent with a treatment effect. In any pair, the probability of that favorable orientation is at most \[ \frac{\Gamma}{1+\Gamma}. \] For the one-sided sign statistic, the worst-case upper-tail probability is therefore the upper tail of a binomial random variable with \(n\) trials and success probability \(\Gamma/(1+\Gamma)\):

$$ \overline{p}_{\Gamma} = P\!\left\{X\geq S\right\}, \qquad X\sim \operatorname{Binomial}\!\left(n,\frac{\Gamma}{1+\Gamma}\right). $$

This is a worst-case p-value bound for the specified statistic, alternative, matched-pair structure, and \(\Gamma\). It is not a confidence interval for an effect. To see why the bound has this form, let \(I_i\) indicate whether pair \(i\) has the favorable sign under assignment. Each \(I_i\) is a Bernoulli variable whose success probability is at most \(q=\Gamma/(1+\Gamma)\). With independent assignment across pairs, the sum of these indicators is stochastically no larger than a binomial sum with all success probabilities equal to \(q\). Consequently, its probability of reaching or exceeding the observed \(S\) is at most the binomial upper tail shown above. Setting every probability to its allowed maximum gives the worst case for this upper-tail test.

The derivation depends on the sign statistic and the stated assignment model. A signed-rank statistic, a rank-sum statistic, or a statistic using the magnitudes of differences does not generally have this same binomial formula. Use the formula only when the analysis is actually a one-sided sign test on independent matched pairs.

Worked Example: Calculating One Bound by Hand

Return to the four-pair example. There are \(n=3\) non-tied pairs and \(S=2\) positive differences. At \(\Gamma=2\), the maximum probability of a favorable sign is \(q=2/(1+2)=2/3\). Therefore,

$$ \overline{p}_{2} = \sum_{j=2}^{3}\binom{3}{j} \left(\frac{2}{3}\right)^j \left(\frac{1}{3}\right)^{3-j} = 3\left(\frac{4}{9}\right)\left(\frac{1}{3}\right) +\frac{8}{27} = \frac{20}{27} \approx 0.7407. $$

At \(\Gamma=1\), the same calculation gives \(P\{\operatorname{Binomial}(3,0.5)\geq2\}=4/8=0.5000\). The bound increases as \(\Gamma\) allows more unequal assignment odds. At a conventional significance level of \(0.05\), neither bound rejects the one-sided sharp null. The p-value is not the probability that the null is true; it is a tail probability calculated under the null and the stated assignment model.

Implementing and Verifying a Gamma Grid

A software workflow should make the analysis reproducible: define the matched sets and outcome direction, choose the statistic, specify a grid of \(\Gamma\) values, and verify selected results independently. For the sign statistic, the software calculation can be checked with a binomial survival function. In R, for example, the upper-tail probability \(P(X\geq S)\) can be computed as `pbinom(S - 1, size = n, prob = Gamma/(1 + Gamma), lower.tail = FALSE)`. Subtracting one is essential because the function’s upper tail is strictly greater than its first argument.

The following grid uses seven non-tied pairs with five positive differences. Every value is calculated from the same statistic and data; only \(\Gamma\) changes.

Worked Example: Verifying a Grid of Worst-Case P-Values

Suppose the hypothetical pair signs are \(+,+,+,+,+,-,-\), so \(n=7\) and \(S=5\). For \(\Gamma=1\), the binomial success probability is \(1/2\):

$$ \overline{p}_{1} = \sum_{j=5}^{7}\binom{7}{j}(1/2)^7 = \frac{21+7+1}{128} = \frac{29}{128} \approx 0.2266. $$

For \(\Gamma=1.5\), \(q=1.5/2.5=0.6\), giving

$$ \overline{p}_{1.5} = 21(0.6)^5(0.4)^2 +7(0.6)^6(0.4) +(0.6)^7 = 0.419904 \approx 0.4199. $$

For \(\Gamma=2\), \(q=2/3\). The three terms have numerators \(672\), \(448\), and \(128\) over \(2187\), respectively:

$$ \overline{p}_{2} = \sum_{j=5}^{7}\binom{7}{j}(2/3)^j(1/3)^{7-j} = \frac{672+448+128}{2187} = \frac{1248}{2187} \approx 0.5706. $$

For \(\Gamma=3\), \(q=3/4\), so

$$ \overline{p}_{3} = \frac{21(3^5)(1^2)+7(3^6)(1)+3^7}{4^7} = \frac{12393}{16384} \approx 0.7564. $$

A software result should agree, up to rounding, with these calculations for the corresponding inputs. The increasing sequence \(0.2266, 0.4199, 0.5706, 0.7564\) is a useful diagnostic: allowing more hidden bias should not make this one-sided worst-case upper-tail bound smaller. Monotonicity is a check, not a substitute for confirming the data, direction, and statistic.

Practical Checks and Common Failure Modes

A disciplined implementation separates data checks from sensitivity calculations. First confirm the number of matched sets, the number of treated units per set, and the outcome difference direction. Then compute the statistic independently. Finally, compare at least one software output with a hand calculation or an exact distribution calculation. If the software accepts a general matched-set object, verify that its documented test statistic and assignment model match the intended analysis.

  • Wrong unit or set identifier: If records from different matched sets share an identifier, the program may treat them as one larger set. Check that every pair has exactly two units and one treated unit.
  • Reversed alternative: Counting control-minus-treated positives answers the opposite directional question from counting treated-minus-control positives. Confirm the alternative and the software’s sign convention.
  • Including ties as negative signs: A zero difference is not a negative difference. For the sign test, exclude ties from both \(n\) and \(S\).
  • Using the wrong tail: A lower-tail or two-sided calculation is not the one-sided upper-tail bound defined here. Check the tail convention and whether the survival-function argument is \(S-1\).
  • Changing the statistic without changing the calculation: The binomial tail applies to the sign count. A software option for signed ranks or another statistic requires its own sensitivity calculation.

A common mistake is to see a p-value rise with \(\Gamma\) and report it as the probability that unmeasured confounding exists or that the treatment effect is absent. Neither interpretation is correct. The bound describes the largest one-sided p-value for a specified sharp-null test under the assignment probabilities allowed by that \(\Gamma\); it does not estimate the prevalence of confounding or assign probability to a hypothesis.

The exact binomial sign test is attractive because its inputs and worst-case tail are easy to audit. Other test statistics can use more information in the outcomes, such as their ranks or magnitudes, but may require different software routines and more involved calculations. E-values are another sensitivity metric, but they answer a different question and should not be substituted for a Rosenbaum p-value bound. The choice among approaches should follow the estimand, design, and inferential question, not whichever software output is easiest to obtain.

Finally, \(\Gamma\) is a sensitivity parameter, not something estimated from the matched outcomes. A value such as \(\Gamma=2\) permits treatment assignment odds to differ by as much as a factor of two within a matched pair due to hidden bias, under the model. The interpretation is conditional on the sensitivity model being a useful description of the remaining assignment bias; it does not establish that any particular hidden confounder has that strength.

Worked Example: Checking a Software Survival Probability

Suppose a hypothetical analysis has six non-tied pairs and four positive signs. At \(\Gamma=2\), the success probability is \(2/3\). A software survival-function calculation should evaluate \(P(X>3)\), which is the same as \(P(X\geq4)\), for \(X\sim\operatorname{Binomial}(6,2/3)\). In R the corresponding call is `pbinom(3, size = 6, prob = 2/3, lower.tail = FALSE)`.

$$ \overline{p}_{2} = \binom{6}{4}(2/3)^4(1/3)^2 +\binom{6}{5}(2/3)^5(1/3) +(2/3)^6 = \frac{240+192+64}{729} = \frac{496}{729} \approx 0.6804. $$

If software instead reports a value corresponding to \(P(X\geq3)\), the threshold was likely entered without subtracting one in a strictly-greater-than survival function. If it reports a value corresponding to \(P(X\geq5)\), the observed sign count may have been entered with an off-by-one error. Checking the event in words—at least four favorable signs—often reveals the problem immediately.

Key takeaway: A reproducible Rosenbaum sign-test calculation requires correct matched-pair records, an explicit one-sided direction, correct handling of ties, and a clearly specified \(\Gamma\) grid. Verify the reported worst-case p-values against \(P\{\operatorname{Binomial}(n,\Gamma/(1+\Gamma))\geq S\}\) before interpreting them.

Check Your Understanding

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

  1. A pair has treated outcome 14 and control outcome 16. For an alternative that treatment increases the outcome, what sign does this pair contribute?
  2. For \(n=5\), \(S=4\), and \(\Gamma=1\), calculate the one-sided sign-test p-value.
  3. At \(\Gamma=2\), what is the maximum favorable-sign probability in a matched pair?
  4. A program computes an upper tail using a survival function and enters \(S\) as the cutoff. What cutoff should it use instead, and why?
  5. Why should a tied pair not be counted as a negative sign in the sign test?

Solutions. (1) The difference is \(14-16=-2\), so it contributes a negative sign. (2) At \(\Gamma=1\), \(q=0.5\), so \(P\{\operatorname{Binomial}(5,0.5)\geq4\}=[\binom{5}{4}+\binom{5}{5}]/32=6/32=0.1875\). (3) The maximum probability is \(2/(1+2)=2/3\). (4) Enter \(S-1\), because a survival function with that cutoff computes \(P(X>S-1)=P(X\geq S)\). (5) A tie has difference zero, so it is neither positive nor negative; counting it as negative changes both the sample size and the observed statistic.

Clinical Biostats