Theoremresearch
Polyhedral lemma
Also called Lee-Sun-Sun-Taylor lemma, exact post-selection inference for the lasso.
The lasso selection event is a polyhedron in y, so a linear contrast of y given the event has a truncated normal law. This gives exact post-selection intervals.
The polyhedral lemma, also called the Lee-Sun-Sun-Taylor lemma, gives the exact law of a linear function of a normal vector given that fell in a polyhedron . Given the event and the part of that is independent of , the law is a normal law truncated to an interval whose ends are computed from the data. The truncated normal CDF at the observed value is then exactly uniform, which gives exact tests and intervals after selection. The lemma is the engine of post-selection inference for the lasso, forward stepwise regression and least angle regression, whose selection events are polyhedra. Its other name, exact post-selection inference for the lasso, comes from the title of the paper of Lee, Sun, Sun and Taylor.
Statement
Let , , and . (Lee et al. write for ; here is kept for regression coefficients.) For , and in , let be the CDF of the normal law truncated to :
Conditions.
- with known; may be singular.
- and are fixed, and .
- is fixed and .
Write , , and , and define
with and .
Theorem (Lee, Sun, Sun and Taylor 2016). Under conditions 1 to 3:
- .
- and are independent.
- For almost every with , the law of given and is truncated to .
- The pivot has the uniform law on given .
In plain words
Suppose a rule looked at noisy data and chose what to report. Most rules of this kind can be written as a list of straight-line checks on the data, so the data sets that lead to the same choice fill a region with flat sides. Now take one number we want to study, say the effect of the chosen variable. Split the data into this number and the rest, which is unrelated to it. Hold the rest fixed. The flat-sided region then allows the number to move only between a lowest and a highest value. So, given the choice, the number is a bell-curve draw that was forced to land in that range. We know exactly how such a draw behaves, so we can compute an honest p-value and an honest interval that take the choice into account.
Proof
Part 1 (the event on a line). Since , holds if and only if for every row . A row with says ; a row with says, after division by a negative number, ; and a row with says and does not involve . The rows of the first kind together say , those of the second kind , those of the third kind .
Part 2 (independence). The pair is a linear function of the normal vector , so it is jointly normal. Its cross covariance is
For a jointly normal vector, zero cross covariance between two blocks means independence of the blocks, also when the covariance is singular, because the joint characteristic function then factors.
Part 3 (the truncated law). Write , , and for . By Part 1, . The functions , and are measurable, being maxima and minima of finitely many affine functions. By Part 2, is independent of and has the law , so for every Borel set , by the substitution rule for conditional expectations of independent variables,
With this gives . Where this is positive, the ratio of the two is , the truncated normal law.
Part 4 (the uniform pivot). Let and . If has a continuous CDF , then . Apply this to the truncated law of Part 3, which has a continuous CDF, for a fixed with and :
If or , both and are 0. So almost surely. Taking expectations gives , and dividing by gives .
Consequences
Tests. To test against , reject when . By Part 4 the level is exactly given the selection event, and so also given the selected model.
Intervals. For , the map is strictly decreasing. Proof. The truncated law has density proportional to on , a one-parameter exponential family. Differentiating under the integral, for with this law, and the mean of a law with a density, restricted to its part below , is smaller than the full mean. As the law piles up at and ; as it piles up at , or moves to if , and . So there are unique with and , and , which has probability given the event by Part 4. A bisection on finds and .
Selection events that are polyhedra. The lemma needs , and fixed, so in use one conditions on the event for the model that was selected, and lets , for example the row of for one coefficient. Then the lemma applies whenever , or a finer event inside it, is a polyhedron.
- Largest . Selecting with sign is the event .
- The lasso. Let minimize with fixed ; here is the coefficient vector. Let be the active set, its signs, of full column rank, and . Up to a set of probability 0, is the polyhedron of the two conditions
Proof. By the KKT conditions, solves the problem if and only if with where and elsewhere. If and , the rows in give , so the first condition is ; the rows outside give equal to the vector inside the absolute value, using ; and in some coordinate has probability 0. Conversely, if satisfies both conditions, the vector with these and satisfies the KKT conditions, so it is a solution. All solutions have the same fit , because the loss is strictly convex in and the objective is convex, so they have the same , and forces off ; since has full rank, the solution is unique.
- Forward stepwise and least angle regression. Each step compares the candidates by inner products with the current residual, and the event "this variable entered with this sign at this step" is again a set of linear inequalities in (Tibshirani et al. 2016).
Conditioning only on , without the signs, gives a union of polyhedra; on a line through this is a union of intervals, and the same proof gives a normal law truncated to that union, with shorter intervals.
A hand example. Take , the largest- rule and the observed . The rule picks with sign , so , , and . Every row of has coefficient on , so for all rows, , and : given the event and , is a normal variable truncated to . The selective p-value for against is , where , against the naive one-sided . The 95% interval is , against the naive . Moving and keeping and :
| selective 95% interval | selective p | naive one-sided p | |
|---|---|---|---|
| 1.05 | 0.926 | 0.147 | |
| 1.2 | 0.725 | 0.115 | |
| 1.5 | 0.421 | 0.0668 | |
| 2.0 | 0.143 | 0.0228 | |
| 2.5 | 0.0391 | 0.0062 | |
| 3.0 | 0.0085 | 0.0013 | |
| 4.0 | 0.0002 | 0.00003 |
Far from the edge the selective and naive answers agree; near it the data barely passed the selection, and the interval becomes long on the left.
A measured check. With 5 coordinates, 4000 draws (seed 20261114) and the same rule, the Kolmogorov-Smirnov distance of the 4000 pivots from the uniform law was 0.0114 for and 0.0161 for . The naive pivot gave 0.7249 and 0.3593. These distances are measurements of one simulation; the uniformity itself is what Part 4 proves.
Tightness
Normality. Part 2 uses that uncorrelated parts of a normal vector are independent. For other error laws, and are uncorrelated but not independent, the law of given is not normal, and the pivot is only approximately uniform. Asymptotic versions need extra conditions, and they are less well understood near the edges of the selection region.
Known covariance. The pivot uses . With estimated from the same data, the plug-in pivot is not exactly uniform, and the estimate is not independent of the selection when it uses the residuals of the selected model.
Fixed , and . If the analyst chooses after looking at more than the selection event, for example at itself, Part 4 fails.
Length of the intervals. In the table, as moves down to , the lower end of the interval goes to . Kivaranovic and Leeb (2021) proved that, in common settings, the expected length of these intervals is infinite. The lemma is exact, but it can be very uninformative.
Power. Conditioning on and on the signs uses less of the data than is available. Conditioning on the selected model alone (the union of polyhedra above), or randomizing the selection step (Tian and Taylor 2018), gives shorter intervals with the same exact guarantee.
Code
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/polyhedral-lemma/. The authors are listed in prov/TA2HX1.jsonl.
"""The polyhedral lemma of Lee, Sun, Sun and Taylor (2016), and the selective test and interval it gives.
Let y ~ N(mu, Sigma) and let the selection event be a polyhedron {A y <= b}.
For a direction eta set c = Sigma eta / (eta^T Sigma eta) and z = y - c eta^T y.
Then {A y <= b} = {V-(z) <= eta^T y <= V+(z), V0(z) >= 0} with
alpha = A c,
V-(z) = max over alpha_j < 0 of (b_j - (A z)_j) / alpha_j,
V+(z) = min over alpha_j > 0 of (b_j - (A z)_j) / alpha_j,
V0(z) = min over alpha_j = 0 of b_j - (A z)_j,
and z is independent of eta^T y. So, given the event and z, eta^T y is normal
with mean eta^T mu and variance eta^T Sigma eta, truncated to [V-, V+], and
its truncated CDF at the observed value is uniform on (0, 1).
The truncated CDF uses log tails, so it stays accurate when both limits are
far out in the same tail (the case that a plain difference of Phi values gets
wrong).
"""
import math
_SQRT2 = math.sqrt(2.0)
_LOG_SQRT_2PI = 0.5 * math.log(2.0 * math.pi)
def log_norm_sf(x):
"""log P(Z > x) for a standard normal Z, accurate in the far upper tail."""
if x == math.inf:
return -math.inf
if x == -math.inf:
return 0.0
if x < 30.0:
return math.log(0.5 * math.erfc(x / _SQRT2))
# Asymptotic series of the Mills ratio; for x >= 30 the first omitted term is below 3e-14.
u = 1.0 / (x * x)
series = -u + 3.0 * u ** 2 - 15.0 * u ** 3 + 105.0 * u ** 4 - 945.0 * u ** 5
return -0.5 * x * x - math.log(x) - _LOG_SQRT_2PI + math.log1p(series)
def truncated_normal_cdf(x, mu, sd, a, b):
"""P(T <= x) for T normal with mean mu and standard deviation sd, conditioned on a <= T <= b."""
if not a < b:
raise ValueError("need a < b")
if x <= a:
return 0.0
if x >= b:
return 1.0
za, zb, zx = (a - mu) / sd, (b - mu) / sd, (x - mu) / sd
if za >= 0.0:
# Whole interval in the upper tail: (Q(za) - Q(zx)) / (Q(za) - Q(zb)), with ratios of tails.
la = log_norm_sf(za)
rx = math.exp(log_norm_sf(zx) - la)
rb = math.exp(log_norm_sf(zb) - la)
return (1.0 - rx) / (1.0 - rb)
if zb <= 0.0:
# Whole interval in the lower tail: mirror, Phi(t) = Q(-t).
lb = log_norm_sf(-zb)
rx = math.exp(log_norm_sf(-zx) - lb)
ra = math.exp(log_norm_sf(-za) - lb)
return (rx - ra) / (1.0 - ra)
lo = 0.5 * math.erfc(-za / _SQRT2)
hi = 0.5 * math.erfc(-zb / _SQRT2)
mid = 0.5 * math.erfc(-zx / _SQRT2)
return (mid - lo) / (hi - lo)
def truncation_limits(a_mat, b_vec, eta, sigma, y):
"""(V-, V+, V0, eta^T y, eta^T Sigma eta) for the event {A y <= b} and the direction eta."""
n = len(y)
s_eta = [math.fsum(sigma[i][k] * eta[k] for k in range(n)) for i in range(n)]
var = math.fsum(e * s for e, s in zip(eta, s_eta))
if not var > 0.0:
raise ValueError("eta^T Sigma eta must be positive")
c = [s / var for s in s_eta]
t = math.fsum(e * v for e, v in zip(eta, y))
z = [v - ci * t for v, ci in zip(y, c)]
vminus, vplus, v0 = -math.inf, math.inf, math.inf
for row, bj in zip(a_mat, b_vec):
alpha = math.fsum(r * ci for r, ci in zip(row, c))
rest = bj - math.fsum(r * zi for r, zi in zip(row, z))
if alpha > 0.0:
vplus = min(vplus, rest / alpha)
elif alpha < 0.0:
vminus = max(vminus, rest / alpha)
else:
v0 = min(v0, rest)
return vminus, vplus, v0, t, var
def max_abs_selection(y):
"""The index j and sign s of the largest |y_j|, and the polyhedron {A y <= 0} of that event."""
p = len(y)
j = max(range(p), key=lambda k: abs(y[k]))
s = 1.0 if y[j] >= 0.0 else -1.0
rows = []
for k in range(p):
if k == j:
continue
for sign in (1.0, -1.0):
row = [0.0] * p
row[j] = -s # -s y_j + sign * y_k <= 0, that is s y_j >= sign * y_k
row[k] = sign
rows.append(row)
row = [0.0] * p
row[j] = -s
rows.append(row) # s y_j >= 0
return j, s, rows, [0.0] * len(rows)
def selective_pivot(a_mat, b_vec, eta, sigma, y, mu_eta=0.0):
"""The truncated normal CDF of eta^T y at mean mu_eta; uniform on (0, 1) given the event when mu_eta is true."""
vm, vp, v0, t, var = truncation_limits(a_mat, b_vec, eta, sigma, y)
if v0 < 0.0 or not vm <= t <= vp:
raise ValueError("y is not in the selection event")
return truncated_normal_cdf(t, mu_eta, math.sqrt(var), vm, vp)
def selective_p_value(a_mat, b_vec, eta, sigma, y):
"""One-sided p-value for H0: eta^T mu = 0 against eta^T mu > 0, valid given the selection event."""
return 1.0 - selective_pivot(a_mat, b_vec, eta, sigma, y, 0.0)
def selective_interval(a_mat, b_vec, eta, sigma, y, level=0.95):
"""The equal-tailed interval for eta^T mu by inverting the pivot, which decreases in the mean."""
vm, vp, v0, t, var = truncation_limits(a_mat, b_vec, eta, sigma, y)
sd = math.sqrt(var)
alpha = 1.0 - level
def root(target):
lo, hi = t - sd, t + sd
while truncated_normal_cdf(t, lo, sd, vm, vp) < target:
lo -= 2.0 * (hi - lo)
while truncated_normal_cdf(t, hi, sd, vm, vp) > target:
hi += 2.0 * (hi - lo)
for _ in range(200):
mid = 0.5 * (lo + hi)
if truncated_normal_cdf(t, mid, sd, vm, vp) > target:
lo = mid
else:
hi = mid
return 0.5 * (lo + hi)
return root(1.0 - alpha / 2.0), root(alpha / 2.0)
test_polyhedral_lemma.py 111 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/polyhedral-lemma/. The authors are listed in prov/TA2HX1.jsonl.
import math
import random
import pytest
from polyhedral_lemma import (
log_norm_sf, max_abs_selection, selective_interval, selective_p_value, selective_pivot,
truncated_normal_cdf, truncation_limits,
)
def eye(p):
return [[1.0 if i == j else 0.0 for j in range(p)] for i in range(p)]
def ks_uniform(values):
v = sorted(values)
n = len(v)
return max(max((i + 1) / n - u, u - i / n) for i, u in enumerate(v))
def test_log_tail_is_continuous_and_accurate():
for x in (0.0, 1.0, 5.0, 20.0, 29.0):
assert math.isclose(log_norm_sf(x), math.log(0.5 * math.erfc(x / math.sqrt(2.0))), rel_tol=1e-13)
left = math.log(0.5 * math.erfc(30.0 / math.sqrt(2.0)))
assert math.isclose(log_norm_sf(30.0), left, rel_tol=1e-13)
assert math.isclose(log_norm_sf(30.0 + 1e-9), left, rel_tol=1e-9)
assert log_norm_sf(1e4) < -4.9e7
def test_truncated_cdf_far_in_the_tail():
# Mean 0, truncated to [40, inf): T - 40 is close to exponential with rate 40.
for d in (0.01, 0.05, 0.1):
f = truncated_normal_cdf(40.0 + d, 0.0, 1.0, 40.0, math.inf)
assert abs(f - (1.0 - math.exp(-40.0 * d - d * d / 2.0) * 40.0 / (40.0 + d))) < 2e-3
assert truncated_normal_cdf(-40.05, 0.0, 1.0, -math.inf, -40.0) == pytest.approx(
1.0 - truncated_normal_cdf(40.05, 0.0, 1.0, 40.0, math.inf), abs=1e-12)
# Inside the bulk it is the plain formula.
phi = lambda t: 0.5 * math.erfc(-t / math.sqrt(2.0))
assert truncated_normal_cdf(0.3, 0.0, 1.0, -1.0, 2.0) == pytest.approx((phi(0.3) - phi(-1.0)) / (phi(2.0) - phi(-1.0)), rel=1e-12)
def test_limits_describe_the_event_on_the_line():
rng = random.Random(20261114)
for _ in range(200):
p = 4
a = [[rng.uniform(-1, 1) for _ in range(p)] for _ in range(6)]
b = [rng.uniform(0.5, 2.0) for _ in range(6)]
m = [[rng.uniform(-1, 1) for _ in range(p)] for _ in range(p)]
sigma = [[math.fsum(m[i][k] * m[j][k] for k in range(p)) + (1.0 if i == j else 0.0) for j in range(p)] for i in range(p)]
eta = [rng.uniform(-1, 1) for _ in range(p)]
y = [0.0] * p # A 0 = 0 <= b, so y is inside the polyhedron
vm, vp, v0, t, var = truncation_limits(a, b, eta, sigma, y)
assert v0 >= 0.0 and vm <= t <= vp
s_eta = [math.fsum(sigma[i][k] * eta[k] for k in range(p)) for i in range(p)]
c = [s / var for s in s_eta]
z = [yi - ci * t for yi, ci in zip(y, c)]
for s in [vm - 0.01, vm + 0.01, vp - 0.01, vp + 0.01, t]:
if not math.isfinite(s):
continue
point = [zi + ci * s for zi, ci in zip(z, c)]
inside = all(math.fsum(r * q for r, q in zip(row, point)) <= bj + 1e-12 for row, bj in zip(a, b))
assert inside == (vm <= s <= vp)
def test_one_step_selection_hand_example():
y = [2.5, -1.0, 0.8]
j, s, a, b = max_abs_selection(y)
assert (j, s) == (0, 1.0)
eta = [1.0, 0.0, 0.0]
vm, vp, v0, t, var = truncation_limits(a, b, eta, eye(3), y)
assert (vm, vp, t) == (1.0, math.inf, 2.5)
q = lambda x: 0.5 * math.erfc(x / math.sqrt(2.0))
assert selective_p_value(a, b, eta, eye(3), y) == pytest.approx(q(2.5) / q(1.0), rel=1e-12)
lo, hi = selective_interval(a, b, eta, eye(3), y)
assert lo == pytest.approx(-0.34087, abs=1e-4)
assert hi == pytest.approx(4.45540, abs=1e-4)
assert lo < 2.5 - 1.96 # the selective interval is wider than the naive one on the left
assert selective_pivot(a, b, eta, eye(3), y, lo) == pytest.approx(0.975, abs=1e-9)
assert selective_pivot(a, b, eta, eye(3), y, hi) == pytest.approx(0.025, abs=1e-9)
def test_pivot_is_uniform_after_selection_monte_carlo():
# One-step selection of the largest |y_j| among p = 5, then inference on the selected mean.
# Tolerance: with 4000 draws the Kolmogorov-Smirnov distance of a true uniform sample exceeds
# 0.0258 with probability about 0.01, so 0.03 is a safe bound for the fixed seed.
rng = random.Random(20261114)
p, reps = 5, 4000
for mu in ([0.0] * p, [1.0, 0.5, 0.0, 0.0, -2.0]):
pivots, naive = [], []
for _ in range(reps):
y = [m + rng.gauss(0.0, 1.0) for m in mu]
j, s, a, b = max_abs_selection(y)
eta = [0.0] * p
eta[j] = s
pivots.append(selective_pivot(a, b, eta, eye(p), y, s * mu[j]))
naive.append(0.5 * math.erfc(-(s * y[j] - s * mu[j]) / math.sqrt(2.0)))
assert ks_uniform(pivots) < 0.03
assert ks_uniform(naive) > 0.15 # the pivot that ignores selection is far from uniform
def test_event_check():
y = [2.5, -1.0, 0.8]
_, _, a, b = max_abs_selection(y)
with pytest.raises(ValueError):
selective_pivot(a, b, [1.0, 0.0, 0.0], eye(3), [0.1, 3.0, 0.0])
with pytest.raises(ValueError):
truncated_normal_cdf(0.0, 0.0, 1.0, 1.0, 1.0)
History
Lockhart, Taylor, Tibshirani and Tibshirani (2014) gave the covariance test, an asymptotic test for variables entering along the lasso path. Lee, Sun, Sun and Taylor posted the exact result in 2013 and published it in the Annals of Statistics in 2016, with the lasso as the main application. Tibshirani, Taylor, Lockhart and Tibshirani (2016) used the same lemma for forward stepwise regression and least angle regression, and Taylor and Tibshirani (2015) placed it in a general framework of selective inference. Later work by Tian and Taylor (2018) and others added randomization for power, and Kivaranovic and Leeb (2021) studied the length of the intervals.
References
- Jason D. Lee, Dennis L. Sun, Yuekai Sun and Jonathan E. Taylor, Exact post-selection inference, with application to the lasso, Annals of Statistics 44(3), 2016, pp. 907 to 927, Sections 4 and 5 (the lasso selection event as a polyhedron, the polyhedral lemma and the truncated Gaussian pivot)
- Ryan J. Tibshirani, Jonathan Taylor, Richard Lockhart and Robert Tibshirani, Exact post-selection inference for sequential regression procedures, Journal of the American Statistical Association 111(514), 2016, pp. 600 to 620, Sections 2 to 4 (the polyhedral form of forward stepwise and least angle regression events, the pivot for general Sigma)
- Jonathan Taylor and Robert J. Tibshirani, Statistical learning and selective inference, Proceedings of the National Academy of Sciences 112(25), 2015, pp. 7629 to 7634, The whole paper (the lemma in the setting of selective inference)
- Danijel Kivaranovic and Hannes Leeb, On the length of post-model-selection confidence intervals conditional on polyhedral constraints, Journal of the American Statistical Association 116(534), 2021, pp. 845 to 857, The main theorems (infinite expected length of the intervals from the lemma)
- Xiaoying Tian and Jonathan Taylor, Selective inference with a randomized response, Annals of Statistics 46(2), 2018, pp. 679 to 710, The whole paper (randomized selection, which leaves more information for the inference than the lemma does)
- Richard Lockhart, Jonathan Taylor, Ryan J. Tibshirani and Robert Tibshirani, A significance test for the lasso, Annals of Statistics 42(2), 2014, pp. 413 to 468, The whole paper (the covariance test, an asymptotic test along the lasso path that came before the exact lemma)
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 | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag TA2HX1 Edit this page History Report an error Markdown