Algorithm Search⌘K

Algorithmresearch

Knockoff filter

Also called model-X knockoffs, Barber-Candes knockoffs.

Build copies of the features that keep their correlations but not their link to the response, and select features that beat their copies. Knockoff+ keeps the FDR at most q in finite samples.

Time
Θ(n p² + S p³) constructionΘ(n p + p log p) filter
Space
Θ(n p) extra
Where
S = the number of Jacobi sweeps; n = the number of observations; p = the number of features
Properties
randomizednot exactofflinerandomizediterative
Origin
Rina Foygel Barber, Emmanuel J. Candès, 2015

The knockoff filter selects features in a linear regression y=Xβ+zy = X\beta + z and controls the false discovery rate of the selected set, the expected share of selected features jj with βj=0\beta_j = 0. It does not use p-values. For each feature XjX_j it builds a knockoff X~j\tilde X_j, a fake feature with the same correlations to the other features as XjX_j but known to have no effect on yy. It then computes a statistic WjW_j for each pair, large and positive when XjX_j explains yy better than its knockoff, and with a sign that is a fair coin when βj=0\beta_j = 0. The negative WjW_j estimate how many null features pass any positive threshold, and the filter takes the lowest threshold TT at which the estimated FDR is at most qq. The version called knockoff+ adds 1 to the count of negatives and has FDR≤q\text{FDR} \le q in finite samples. The plain version controls only a modified FDR.

In plain words

You want to find which of many measured factors really affect an outcome, and you accept a set share of false finds. For each factor, make a fake twin: a made-up factor that is related to the other factors in the same way as the real one, but that cannot affect the outcome. Then let each real factor compete with its twin. A useless factor wins or loses at random, like a coin toss. A useful factor usually wins by a wide margin. Count how many twins win by a wide margin. That count tells you about how many useless factors also won by a wide margin by luck. Keep the factors that won by a margin large enough that this estimate of false finds stays below your limit.

The problem

Input. A design X∈Rn×pX \in \mathbb R^{n \times p} with n≥2pn \ge 2p and full column rank, a response y∈Rny \in \mathbb R^n, and a target q∈(0,1]q \in (0, 1]. The model is y=Xβ+zy = X\beta + z with z∼N(0,σ2In)z \sim N(0, \sigma^2I_n), XX fixed, and β\beta and σ\sigma unknown. The null hypotheses are Hj:βj=0H_j : \beta_j = 0; m0m_0 of the pp are true.

Output. A set S^\hat S of selected features.

Error rate controlled. For knockoff+, the FDR, E[V/max⁡(R,1)]≤qE[V/\max(R, 1)] \le q, where R=∣S^∣R = |\hat S| and VV is the number of null features in S^\hat S. For the plain knockoff filter, the modified FDR E[V/(R+q−1)]≤qE[V/(R + q^{-1})] \le q. Both bounds hold for every β\beta, so the control is strong.

Dependence assumption. None on the features beyond full rank: the knockoffs absorb the correlations of XX. The assumptions are the Gaussian linear model with fixed XX and n≥2pn \ge 2p. Model-X knockoffs, the variant named in the aliases, replace them by a known joint law of the rows of XX and work for any nn and pp.

Exact or asymptotic. Finite-sample, as an inequality. The proof is a theorem of Barber and Candès, cited and not proved here; the page proves the steps that lead to it.

The algorithm

Normalize the columns so that Σ=X⊤X\Sigma = X^\top X has unit diagonal. With s∈(0,2λmin⁡(Σ)]s \in (0, 2\lambda_{\min}(\Sigma)], the knockoffs are

X~=X(I−sΣ−1)+U~C,C⊤C=2sI−s2Σ−1,\tilde X = X(I - s\Sigma^{-1}) + \tilde UC, \qquad C^\top C = 2sI - s^2\Sigma^{-1},

where U~\tilde U is n×pn \times p with orthonormal columns orthogonal to those of XX. Then X~⊤X~=Σ\tilde X^\top\tilde X = \Sigma and X⊤X~=Σ−sIX^\top\tilde X = \Sigma - sI: the knockoffs have the correlations of XX, and ⟨Xj,X~j⟩=1−s\langle X_j, \tilde X_j\rangle = 1 - s. The equicorrelated choice is s=min⁡(2λmin⁡(Σ),1)s = \min(2\lambda_{\min}(\Sigma), 1), the largest equal value allowed.

  1. KNOCKOFF-FILTER(X, y, q, plus)
  2. 1normalize the columns of X; Σ ← XᵀX
  3. 2s ← min(2 λ_min(Σ), 1) ▷ Jacobi eigenvalues of Σ
  4. 3C ← a square root of 2sI - s²Σ⁻¹, so CᵀC = 2sI - s²Σ⁻¹
  5. 4Ũ ← n × p orthonormal, orthogonal to X ▷ Gram-Schmidt
  6. 5X̃ ← X(I - sΣ⁻¹) + ŨC; W ← statistics on [X X̃] and y
  7. 6sort the distinct values t of |W_j| ≠ 0 in increasing order
  8. 7T ← the first t with (plus + #{W_j ≤ -t}) ≤ q · max(#{W_j ≥ t}, 1), or ∞
  9. 8return {j : W_j ≥ T}

Here plus is 1 for knockoff+ and 0 for the plain filter. The statistic must satisfy two rules. Sufficiency: WW depends on the data only through [X X~]⊤[X X~][X\ \tilde X]^\top[X\ \tilde X] and [X X~]⊤y[X\ \tilde X]^\top y. Antisymmetry: swapping XjX_j and X~j\tilde X_j changes the sign of WjW_j and leaves the other WkW_k unchanged. The code gives two such statistics: the marginal Wj=∣Xj⊤y∣−∣X~j⊤y∣W_j = |X_j^\top y| - |\tilde X_j^\top y|, and the least-squares Wj=∣b^j∣−∣b^j+p∣W_j = |\hat b_j| - |\hat b_{j+p}| from the regression of yy on [X X~][X\ \tilde X]. The usual choice in practice is a lasso statistic, such as the value of the penalty at which XjX_j enters the lasso path, signed by whether it enters before its knockoff.

The equicorrelated ss makes 2sI−s2Σ−12sI - s^2\Sigma^{-1} singular when s=2λmin⁡s = 2\lambda_{\min}, so [X X~][X\ \tilde X] has rank below 2p2p. The lasso and marginal statistics do not mind; the least-squares statistic needs a slightly smaller ss, and the tests use 0.90.9 times the equicorrelated value.

Example

The threshold by hand. Take p=14p = 14 statistics

W=(9,8,7.5,7,6,5.5,−5,4,3,−2.5,2,−1,0.5,−0.3)W = (9, 8, 7.5, 7, 6, 5.5, -5, 4, 3, -2.5, 2, -1, 0.5, -0.3)

and q=0.2q = 0.2. Line L7 scans tt upward:

tt #{Wj≥t}\#\{W_j \ge t\} #{Wj≤−t}\#\{W_j \le -t\} knockoff+ ratio plain ratio
0.3 10 4 0.5 0.4
1 9 3 0.444 0.333
2 9 2 0.333 0.222
2.5 8 2 0.375 0.25
3 8 1 0.25 0.125
5 6 1 0.333 0.167
5.5 6 0 0.167 0.167

The plain filter stops at T=3T = 3 and selects the 8 features with Wj≥3W_j \ge 3. Knockoff+ needs (1+#neg)≤0.2⋅#pos(1 + \#\text{neg}) \le 0.2 \cdot \#\text{pos}, first true at T=5.5T = 5.5, and selects 6. Since the numerator is at least 1, knockoff+ selects nothing unless it can select at least 1/q1/q features.

Why the +1. With one feature, null, and W1>0W_1 > 0, the plain ratio is 0/1≤q0/1 \le q and the plain filter selects it. This happens with probability 1/21/2, so its FDR is 1/21/2 for every qq. Knockoff+ has ratio 1/1>q1/1 > q and never selects it.

Two correlated features. If Σ\Sigma has off-diagonal ρ=0.6\rho = 0.6, then λmin⁡=0.4\lambda_{\min} = 0.4, s=0.8s = 0.8, and ⟨Xj,X~j⟩=0.2\langle X_j, \tilde X_j\rangle = 0.2: the knockoff is nearly orthogonal to its original. If ρ=0.9\rho = 0.9, then s=0.2s = 0.2 and ⟨Xj,X~j⟩=0.8\langle X_j, \tilde X_j\rangle = 0.8. A knockoff so close to its original is hard to beat, and power drops.

A simulation. In the tests, a fixed design has n=40n = 40, p=10p = 10 and column correlation about 0.2, so s=0.455s = 0.455. Five coefficients are 4, five are 0, σ=1\sigma = 1, and q=0.2q = 0.2. Over 1000 responses:

method FDR power
knockoff+, marginal WW 0.120 0.462
knockoff+, least-squares WW (ss times 0.9) 0.111 0.402
plain knockoff, marginal WW 0.227 0.853
BH on exact zz-tests, σ\sigma known 0.101 0.925

Knockoff+ stays below qq, as proved. The plain filter goes above it, by more than four standard errors (the standard error is about 0.005): its guarantee is for the modified FDR only. With only 10 features the knockoff+ rule needs 5 selections before it can select anything, and Benjamini-Hochberg, which is given the true σ\sigma here, is far more powerful. Knockoffs gain when pp is in the hundreds or thousands, when σ\sigma is unknown, and when a good selection statistic like the lasso is used.

Correctness

Three facts lead to the guarantee, and the correctness proof proves them. First, the construction gives [X X~]⊤[X X~]=G[X\ \tilde X]^\top[X\ \tilde X] = G with Σ\Sigma on the diagonal blocks and Σ−sI\Sigma - sI off them, and it exists exactly when s≤2λmin⁡(Σ)s \le 2\lambda_{\min}(\Sigma). Second, swapping XjX_j and X~j\tilde X_j for any set of null features leaves the Gram matrix unchanged and, under the Gaussian model, leaves the law of [X X~]⊤y[X\ \tilde X]^\top y unchanged, because Xj⊤Xβ=X~j⊤XβX_j^\top X\beta = \tilde X_j^\top X\beta when βj=0\beta_j = 0. Third, with sufficiency and antisymmetry, this makes the signs of the null WjW_j independent fair coins, independent of all ∣Wj∣|W_j| and of the non-null signs (Lemma 1 of Barber and Candès).

So among the features with ∣Wj∣≥t|W_j| \ge t, the nulls split into Wj≥tW_j \ge t and Wj≤−tW_j \le -t like coin tosses, and #{Wj≤−t}\#\{W_j \le -t\} overestimates the number of nulls with Wj≥tW_j \ge t. The step from there to FDR≤q\text{FDR} \le q at the data-dependent threshold is Theorem 2 of Barber and Candès, proved with a supermartingale and optional stopping; it is cited here. The tests check it in the coin model: for 150 random sets of magnitudes and non-null signs, they enumerate all 2m02^{m_0} null sign patterns and compute the FDR of knockoff+ and the modified FDR of the plain filter in exact rational arithmetic, and both are at most qq. In the same enumeration the plain filter's FDR exceeds qq.

Proof: Fixed-X knockoffs have the required Gram matrix, and the signs of the null statistics are independent fair coins; FDR control of knockoff+ is citedpartial

We prove what the lines compute and the exchangeability facts on which the FDR guarantee rests: the threshold at lines L6 and L7 is the one of the definition (Lemma 1); the construction at lines L1 to L5 gives the knockoff Gram matrix, and it exists exactly when s≤2λmin⁡(Σ)s \le 2\lambda_{\min}(\Sigma) (Proposition 2); swapping null features with their knockoffs changes neither the Gram matrix nor the law of the inner products with yy (Lemmas 3 and 4); and so the signs of the null statistics are independent fair coins (Lemma 5). The step from Lemma 5 to FDR≤q\text{FDR} \le q for knockoff+, and to the modified FDR bound for the plain filter, is Theorems 1 and 2 of Barber and Candès (2015). We cite them and do not prove them. The tests check them in the coin model by exact enumeration, and measure them in one simulation.

Setting. X∈Rn×pX \in \mathbb R^{n \times p} has full column rank, n≥2pn \ge 2p, and unit column norms after line L1; Σ=X⊤X\Sigma = X^\top X, so Σjj=1\Sigma_{jj} = 1, and λmin⁡>0\lambda_{\min} > 0 is its smallest eigenvalue. y=Xβ+zy = X\beta + z with z∼N(0,σ2In)z \sim N(0, \sigma^2I_n). A feature is null when βj=0\beta_j = 0. Write A=[X X~]∈Rn×2pA = [X\ \tilde X] \in \mathbb R^{n \times 2p}, and for S⊆{1,…,p}S \subseteq \{1, \dots, p\} let Aswap(S)A_{\text{swap}(S)} be AA with columns jj and j+pj + p exchanged for each j∈Sj \in S. A statistic W=w(A,y)∈RpW = w(A, y) \in \mathbb R^p has the sufficiency property if w(A,y)=f(A⊤A,A⊤y)w(A, y) = f(A^\top A, A^\top y) for some function ff, and the antisymmetry property if w(Aswap(S),y)j=−w(A,y)jw(A_{\text{swap}(S)}, y)_j = -w(A, y)_j for j∈Sj \in S and =w(A,y)j= w(A, y)_j for j∉Sj \notin S.

Lemma 1 (the threshold). For q>0q > 0 and c∈{0,1}c \in \{0, 1\}, let W={∣Wj∣:Wj≠0}\mathcal W = \{|W_j| : W_j \ne 0\} and T=min⁡{t∈W:c+#{j:Wj≤−t}≤qmax⁡(#{j:Wj≥t},1)}T = \min\{t \in \mathcal W : c + \#\{j : W_j \le -t\} \le q\max(\#\{j : W_j \ge t\}, 1)\}, or T=∞T = \infty if no tt qualifies. Lines L6 and L7 return TT, and {j:Wj≥T}={j:Wj≥t∗}\{j : W_j \ge T\} = \{j : W_j \ge t^*\} for the smallest t∗>0t^* > 0 in the closure of the set of all positive tt that satisfy the inequality, when that set is not empty.

Proof. Line L6 lists W\mathcal W in increasing order, and line L7 returns the first element that satisfies the inequality, which is the minimum. The counts #{Wj≥t}\#\{W_j \ge t\} and #{Wj≤−t}\#\{W_j \le -t\} are constant for tt in each interval (a,b](a, b] between consecutive elements of {0}∪W\{0\} \cup \mathcal W, and both are 0 for t>max⁡Wt > \max\mathcal W, where the inequality reads c≤qc \le q. So a positive tt satisfies the inequality exactly when the right end bb of its interval does, with the same selected set, or when t>max⁡Wt > \max\mathcal W, where nothing is selected. Hence restricting to t∈Wt \in \mathcal W changes neither the selected set nor whether some tt qualifies, except that a tt beyond max⁡W\max\mathcal W selects nothing, as T=∞T = \infty does. The tests compare the lines with this definition on random integer statistics. □\square

For knockoff+ (c=1c = 1) with q<1q < 1 and T<∞T < \infty, 1≤q#{Wj≥T}1 \le q\#\{W_j \ge T\}, so the filter selects at least 1/q1/q features or none.

Proposition 2 (the construction). Let 0<s0 < s, D=sID = sI, and suppose 2sI−s2Σ−1⪰02sI - s^2\Sigma^{-1} \succeq 0, with CC any matrix with C⊤C=2sI−s2Σ−1C^\top C = 2sI - s^2\Sigma^{-1}, and U~\tilde U with orthonormal columns and U~⊤X=0\tilde U^\top X = 0. Then X~=X(I−sΣ−1)+U~C\tilde X = X(I - s\Sigma^{-1}) + \tilde UC satisfies

A⊤A=G=(ΣΣ−DΣ−DΣ).A^\top A = G = \begin{pmatrix}\Sigma & \Sigma - D\\ \Sigma - D & \Sigma\end{pmatrix}.

Moreover, 2sI−s2Σ−1⪰02sI - s^2\Sigma^{-1} \succeq 0 if and only if s≤2λmin⁡s \le 2\lambda_{\min}, and a matrix X~\tilde X with A⊤A=GA^\top A = G exists only if s≤2λmin⁡s \le 2\lambda_{\min}. Such U~\tilde U exists because n≥2pn \ge 2p.

Proof. Using U~⊤X=0\tilde U^\top X = 0, U~⊤U~=I\tilde U^\top\tilde U = I and the symmetry of Σ−1\Sigma^{-1}:

X⊤X~=Σ(I−sΣ−1)=Σ−sI,X^\top\tilde X = \Sigma(I - s\Sigma^{-1}) = \Sigma - sI,
X~⊤X~=(I−sΣ−1)Σ(I−sΣ−1)+C⊤C=Σ−2sI+s2Σ−1+2sI−s2Σ−1=Σ.\tilde X^\top\tilde X = (I - s\Sigma^{-1})\Sigma(I - s\Sigma^{-1}) + C^\top C = \Sigma - 2sI + s^2\Sigma^{-1} + 2sI - s^2\Sigma^{-1} = \Sigma.

The eigenvalues of 2sI−s2Σ−12sI - s^2\Sigma^{-1} are 2s−s2/λ2s - s^2/\lambda over the eigenvalues λ\lambda of Σ\Sigma; all are ≥0\ge 0 exactly when s≤2λs \le 2\lambda for all λ\lambda, that is, s≤2λmin⁡s \le 2\lambda_{\min}. For the necessity, the orthogonal change of basis (u,v)↦((u+v)/2,(u−v)/2)(u, v) \mapsto ((u + v)/\sqrt2, (u - v)/\sqrt2) turns GG into the block diagonal matrix with blocks 2Σ−D2\Sigma - D and DD. A Gram matrix is positive semidefinite, so 2Σ−sI⪰02\Sigma - sI \succeq 0, that is, s≤2λmin⁡s \le 2\lambda_{\min}. Finally, the orthogonal complement of the column space of XX has dimension n−p≥pn - p \ge p, so pp orthonormal vectors in it exist; line L4 finds them by Gram-Schmidt on the columns of XX followed by random vectors, which are independent of the columns with probability 1. □\square

The code computes C=diag⁡(μ)V⊤C = \operatorname{diag}(\sqrt{\mu})V^\top from the eigendecomposition Vdiag⁡(μ)V⊤V\operatorname{diag}(\mu)V^\top of 2sI−s2Σ−12sI - s^2\Sigma^{-1}, so C⊤C=Vdiag⁡(μ)V⊤C^\top C = V\operatorname{diag}(\mu)V^\top as required; it clips eigenvalues that are negative only by rounding. The equicorrelated choice s=min⁡(2λmin⁡,1)s = \min(2\lambda_{\min}, 1) is allowed by Proposition 2, and ⟨Xj,X~j⟩=1−s\langle X_j, \tilde X_j\rangle = 1 - s. The tests check the two Gram identities numerically.

Lemma 3 (swapping keeps the Gram matrix). For every SS, Aswap(S)⊤Aswap(S)=A⊤AA_{\text{swap}(S)}^\top A_{\text{swap}(S)} = A^\top A.

Proof. By Proposition 2, for j≠kj \ne k all four inner products Xj⊤XkX_j^\top X_k, Xj⊤X~kX_j^\top\tilde X_k, X~j⊤Xk\tilde X_j^\top X_k and X~j⊤X~k\tilde X_j^\top\tilde X_k equal Σjk\Sigma_{jk}, since Σ−D\Sigma - D and Σ\Sigma agree off the diagonal. And Xj⊤Xj=X~j⊤X~j=1X_j^\top X_j = \tilde X_j^\top\tilde X_j = 1, Xj⊤X~j=1−sX_j^\top\tilde X_j = 1 - s. So the inner product of two columns depends only on their feature indices j,kj, k and, when j=kj = k, on whether they are the same column. Exchanging XjX_j and X~j\tilde X_j preserves both. □\square

Lemma 4 (swapping nulls keeps the law of A⊤yA^\top y). If every j∈Sj \in S is null, then Aswap(S)⊤yA_{\text{swap}(S)}^\top y has the same law as A⊤yA^\top y.

Proof. For any fixed n×2pn \times 2p matrix BB, B⊤y∼N(B⊤Xβ,σ2B⊤B)B^\top y \sim N(B^\top X\beta, \sigma^2B^\top B). The covariances for B=AB = A and B=Aswap(S)B = A_{\text{swap}(S)} agree by Lemma 3. For the means, the entries of A⊤XβA^\top X\beta are Xj⊤XβX_j^\top X\beta and X~j⊤Xβ=∑kX~j⊤Xkβk\tilde X_j^\top X\beta = \sum_k\tilde X_j^\top X_k\beta_k. By Proposition 2, X~j⊤Xk=Xj⊤Xk\tilde X_j^\top X_k = X_j^\top X_k for k≠jk \ne j and X~j⊤Xj=Xj⊤Xj−s\tilde X_j^\top X_j = X_j^\top X_j - s, so X~j⊤Xβ=Xj⊤Xβ−sβj\tilde X_j^\top X\beta = X_j^\top X\beta - s\beta_j. For j∈Sj \in S, βj=0\beta_j = 0, so the two entries that the swap exchanges are equal, and the means agree. Two Gaussian vectors with equal means and covariances have the same law. □\square

Lemma 5 (i.i.d. signs for the nulls; Barber and Candès, Lemma 1). Let WW satisfy sufficiency and antisymmetry. Let ε∈{±1}p\varepsilon \in \{\pm1\}^p be independent of WW, with εj=1\varepsilon_j = 1 for non-null jj and εj\varepsilon_j independent uniform signs for null jj. Then (ε1W1,…,εpWp)(\varepsilon_1W_1, \dots, \varepsilon_pW_p) has the same law as WW.

Proof. Fix a set SS of nulls and let εS\varepsilon^S be −1-1 on SS and +1+1 elsewhere. By antisymmetry, εS⋅W=w(Aswap(S),y)\varepsilon^S \cdot W = w(A_{\text{swap}(S)}, y). By sufficiency this is f(Aswap(S)⊤Aswap(S),Aswap(S)⊤y)=f(A⊤A,Aswap(S)⊤y)f(A_{\text{swap}(S)}^\top A_{\text{swap}(S)}, A_{\text{swap}(S)}^\top y) = f(A^\top A, A_{\text{swap}(S)}^\top y), using Lemma 3, and by Lemma 4 it has the same law as f(A⊤A,A⊤y)=Wf(A^\top A, A^\top y) = W. So εS⋅W\varepsilon^S \cdot W has the law of WW for every fixed SS, and a random ε\varepsilon independent of WW is a mixture of such fixed patterns. □\square

Corollary 6 (the coin model). Given (∣W1∣,…,∣Wp∣)(|W_1|, \dots, |W_p|) and the signs of the non-null WjW_j, the signs of the null WjW_j with Wj≠0W_j \ne 0 are independent and uniform on {±1}\{\pm1\}.

Proof. For any fixed null sign pattern εS\varepsilon^S, Lemma 5 says that WW and εS⋅W\varepsilon^S \cdot W have the same law. The map W↦εS⋅WW \mapsto \varepsilon^S \cdot W keeps the magnitudes and the non-null signs, and on the nonzero null coordinates it changes a sign pattern aa into εSa\varepsilon^Sa. So, given the magnitudes and the non-null signs, the patterns aa and εSa\varepsilon^Sa have the same conditional probability, for every SS. The group of sign changes acts transitively on patterns, so the conditional law is uniform, which is independence with fair signs. □\square

The two statistics in the code have the properties. The marginal Wj=∣Xj⊤y∣−∣X~j⊤y∣W_j = |X_j^\top y| - |\tilde X_j^\top y| is a function of A⊤yA^\top y, and a swap exchanges Xj⊤yX_j^\top y and X~j⊤y\tilde X_j^\top y, which flips its sign. For the least-squares statistic, AA has full rank 2p2p when s<2λmin⁡s < 2\lambda_{\min} (by the block form in Proposition 2, G≻0G \succ 0 then), and b^=(A⊤A)−1A⊤y\hat b = (A^\top A)^{-1}A^\top y is a function of A⊤AA^\top A and A⊤yA^\top y. A swap is A↦APA \mapsto AP for a permutation matrix PP, which gives b^↦P⊤b^\hat b \mapsto P^\top\hat b, so b^j\hat b_j and b^j+p\hat b_{j+p} exchange and Wj=∣b^j∣−∣b^j+p∣W_j = |\hat b_j| - |\hat b_{j+p}| changes sign. The tests check both flips numerically.

What is cited. Barber and Candès (2015, Theorem 2) prove that knockoff+ has E[V/max⁡(R,1)]≤qE[V/\max(R, 1)] \le q, and (Theorem 1) that the plain filter has E[V/(R+q−1)]≤qE[V/(R + q^{-1})] \le q, for statistics with sufficiency and antisymmetry, in the setting above. Their proof starts from Corollary 6 and uses a supermartingale argument with optional stopping. Candès, Fan, Janson and Lv (2018) prove the model-X version. These are not proved here.

What is checked and measured. In the coin model of Corollary 6, the tests draw 150 random sets of magnitudes, non-null signs and null sets, enumerate all 2m02^{m_0} null sign patterns, and compute, in exact rational arithmetic, the FDR of knockoff+ and the modified FDR of the plain filter at q=1/5q = 1/5. Both are at most qq in every case, as the cited theorems predict, while the FDR of the plain filter exceeds qq in some cases. A Monte Carlo run on one fixed design measures FDR 0.120 for knockoff+ and 0.227 for the plain filter at q=0.2q = 0.2.

Complexity

On a real RAM, forming Σ\Sigma costs Θ(np2)\Theta(np^2). The Jacobi eigenvalue algorithm costs Θ(p3)\Theta(p^3) per sweep and is used twice, for λmin⁡(Σ)\lambda_{\min}(\Sigma) and Σ−1\Sigma^{-1} and for the square root CC. Gram-Schmidt on 2p2p vectors of length nn costs Θ(np2)\Theta(np^2), and so do the products at line L5. A Cholesky decomposition of 2sI−s2Σ−12sI - s^2\Sigma^{-1} also works when ss is below 2λmin⁡2\lambda_{\min}. The marginal statistic costs Θ(np)\Theta(np), and the threshold at lines L6 and L7 costs Θ(plog⁡p)\Theta(p\log p): sort once, then count with binary search or a two-pointer sweep. The space is Θ(np)\Theta(np) for X~\tilde X. With a fixed design the knockoffs are built once, and each new response costs only the statistic and the threshold.

Properties

  • FDR control of knockoff+ in finite samples, for any β\beta and any fixed design with n≥2pn \ge 2p. Cited.
  • Modified FDR control of the plain filter. Cited. Its FDR can exceed qq; shown by a hand example and measured.
  • Signs of null statistics are fair coins. Proved.
  • No p-values and no σ\sigma. The filter never estimates the noise level, and it allows any statistic with the two properties.
  • Randomized. U~\tilde U is random, so the selected set depends on a random draw. Two runs on the same data can select different sets.
  • Needs at least 1/q1/q selections. Knockoff+ selects nothing if fewer than 1/q1/q features would be selected.

Variants and improvements

  • Model-X knockoffs. Candès, Fan, Janson and Lv (2018) treat the rows of XX as random with a known law, and build X~\tilde X so that swapping any XjX_j and X~j\tilde X_j leaves the joint law of (X,X~)(X, \tilde X) unchanged and X~\tilde X is independent of yy given XX. Then knockoff+ controls the FDR for any model of yy given XX, linear or not, and for p>np > n. For Gaussian rows with covariance Σ\Sigma, X~\tilde X given XX is Gaussian with mean X−XΣ−1DX - X\Sigma^{-1}D and covariance 2D−DΣ−1D2D - D\Sigma^{-1}D, the same algebra as here.
  • SDP knockoffs. Choose a different sjs_j for each feature to minimize ∑j(1−sj)\sum_j(1 - s_j) subject to diag⁡(s)⪯2Σ\operatorname{diag}(s) \preceq 2\Sigma, a semidefinite program. It gives more power than equicorrelated knockoffs when the features have unequal correlations.
  • p<n<2pp < n < 2p. Barber and Candès add 2p−n2p - n synthetic rows to yy and XX, using an estimate of σ\sigma from the full regression.
  • Multiple knockoffs, derandomized knockoffs and e-values. Several knockoff copies or repeated runs reduce the randomness of the selected set; one way to aggregate is through e-values.

When to use it

Use knockoffs to select variables in a regression with FDR control when the p-values for individual coefficients are unreliable or unavailable, when σ\sigma is unknown, or when you want to use a selection method such as the lasso and still have a finite-sample guarantee. Fixed-X knockoffs need n≥2pn \ge 2p and a Gaussian linear model; model-X knockoffs need a good model of the features, as in genetics, where the law of genotypes is well understood. With few features, or when exact p-values are available, Benjamini-Hochberg or Storey's method are simpler and often stronger.

Pitfalls

  • Using the plain filter and calling it FDR control. Only knockoff+ controls the FDR. The plain filter controls E[V/(R+q−1)]E[V/(R + q^{-1})], which is close to the FDR only when many features are selected.
  • Statistics that break antisymmetry. A statistic that treats XjX_j and X~j\tilde X_j differently, for example through the order of a coordinate descent with ties, or that uses yy in a way other than through the inner products, loses the coin-flip property.
  • Building knockoffs from yy. The knockoffs must be computed from XX alone. Choosing ss or U~\tilde U after looking at yy voids the proof.
  • Unnormalized columns. The equicorrelated formula s=min⁡(2λmin⁡,1)s = \min(2\lambda_{\min}, 1) assumes unit column norms.
  • Too few features. With pp small, knockoff+ often selects nothing at the usual qq, since it needs at least 1/q1/q selections.
  • Wrong feature model in model-X. The guarantee holds for the law used to build the knockoffs. If that law is estimated badly, the FDR can be above qq.

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.

knockoff_filter.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/knockoff-filter/. The authors are listed in prov/WNY22A.jsonl.
"""The fixed-X knockoff filter of Barber and Candes (2015), in pure Python.

knockoffs(X) normalizes the columns of the n x p design X (n >= 2p) and builds
equicorrelated knockoffs Xk with
  Xk^T Xk = Sigma,  X^T Xk = Sigma - s I,  Sigma = X^T X,
where s = min(2 lambda_min(Sigma), 1), as
  Xk = X (I - s Sigma^{-1}) + U C,  C^T C = 2 s I - s^2 Sigma^{-1},
with U an n x p orthonormal matrix orthogonal to the columns of X.

A statistic W_j is large and positive when X_j beats its knockoff. Two choices are
given: the marginal one |X_j^T y| - |Xk_j^T y|, and the OLS one on [X Xk].
The filter selects {j : W_j >= T}, with
  T = min{t in {|W_j| : W_j != 0} : (offset + #{W_j <= -t}) / max(#{W_j >= t}, 1) <= q},
offset = 1 for knockoff+ (FDR <= q) and 0 for the plain knockoff (modified FDR <= q).
"""

import math
import random
from bisect import bisect_left
from collections.abc import Callable, Sequence


def _dot(a: Sequence[float], b: Sequence[float]) -> float:
    return sum(x * y for x, y in zip(a, b))


def _transpose(a: Sequence[Sequence[float]]) -> list[list[float]]:
    return [list(r) for r in zip(*a)]


def _matmul(a: Sequence[Sequence[float]], b: Sequence[Sequence[float]]) -> list[list[float]]:
    bt = _transpose(b)
    return [[_dot(row, col) for col in bt] for row in a]


def jacobi_eigen(a: Sequence[Sequence[float]], tol: float = 1e-13, max_sweeps: int = 100):
    """Eigenvalues and eigenvectors of a symmetric matrix by cyclic Jacobi rotations: a = V diag(w) V^T."""
    n = len(a)
    a = [list(map(float, row)) for row in a]
    v = [[1.0 if i == j else 0.0 for j in range(n)] for i in range(n)]
    scale = max(1.0, max((abs(x) for row in a for x in row), default=0.0))
    for _ in range(max_sweeps):
        off = math.sqrt(sum(a[i][j] ** 2 for i in range(n) for j in range(i + 1, n)))
        if off <= tol * scale:
            break
        for p in range(n):
            for q in range(p + 1, n):
                if a[p][q] == 0.0:
                    continue
                theta = (a[q][q] - a[p][p]) / (2.0 * a[p][q])
                t = (1.0 if theta >= 0 else -1.0) / (abs(theta) + math.sqrt(theta * theta + 1.0))
                c = 1.0 / math.sqrt(t * t + 1.0)
                s = t * c
                for k in range(n):
                    akp, akq = a[k][p], a[k][q]
                    a[k][p], a[k][q] = c * akp - s * akq, s * akp + c * akq
                for k in range(n):
                    apk, aqk = a[p][k], a[q][k]
                    a[p][k], a[q][k] = c * apk - s * aqk, s * apk + c * aqk
                for k in range(n):
                    vkp, vkq = v[k][p], v[k][q]
                    v[k][p], v[k][q] = c * vkp - s * vkq, s * vkp + c * vkq
    return [a[i][i] for i in range(n)], v


def _orthonormal_complement(x: Sequence[Sequence[float]], k: int, rng: random.Random) -> list[list[float]]:
    """An n x k matrix with orthonormal columns, orthogonal to the columns of x (Gram-Schmidt, twice)."""
    n, p = len(x), len(x[0])
    basis: list[list[float]] = []
    candidates = [[x[i][j] for i in range(n)] for j in range(p)]
    candidates += [[rng.gauss(0.0, 1.0) for _ in range(n)] for _ in range(k)]
    for v in candidates:
        norm0 = math.sqrt(_dot(v, v))
        for _ in range(2):
            for b in basis:
                c = _dot(b, v)
                v = [vi - c * bi for vi, bi in zip(v, b)]
        norm = math.sqrt(_dot(v, v))
        if norm <= 1e-10 * max(norm0, 1.0):
            raise ValueError("the design does not have full column rank, or n < 2p")
        basis.append([vi / norm for vi in v])
    return _transpose(basis[p:])


def knockoffs(x: Sequence[Sequence[float]], s: float | None = None, rng: random.Random | None = None):
    """Return (Xn, Xk, s): the column-normalized design, its equicorrelated fixed-X knockoffs, and s."""
    n, p = len(x), len(x[0])
    if n < 2 * p:
        raise ValueError("fixed-X knockoffs need n >= 2p")
    rng = rng or random.Random(0)
    norms = [math.sqrt(sum(x[i][j] ** 2 for i in range(n))) for j in range(p)]
    xn = [[x[i][j] / norms[j] for j in range(p)] for i in range(n)]  # @line L1
    sigma = _matmul(_transpose(xn), xn)
    w, v = jacobi_eigen(sigma)
    if min(w) <= 1e-12:
        raise ValueError("the design does not have full column rank")
    if s is None:
        s = min(2.0 * min(w), 1.0)  # @line L2
    if not 0 < s <= 2.0 * min(w) + 1e-12:
        raise ValueError("need 0 < s <= 2 lambda_min(Sigma)")
    sigma_inv = [[sum(v[i][k] * v[j][k] / w[k] for k in range(p)) for j in range(p)] for i in range(p)]
    a = [[(2.0 * s if i == j else 0.0) - s * s * sigma_inv[i][j] for j in range(p)] for i in range(p)]
    mu, vv = jacobi_eigen(a)
    c = [[math.sqrt(max(mu[k], 0.0)) * vv[j][k] for j in range(p)] for k in range(p)]  # @line L3
    u = _orthonormal_complement(xn, p, rng)  # @line L4
    shrink = [[(1.0 if i == j else 0.0) - s * sigma_inv[i][j] for j in range(p)] for i in range(p)]
    left, right = _matmul(xn, shrink), _matmul(u, c)
    xk = [[left[i][j] + right[i][j] for j in range(p)] for i in range(n)]  # @line L5
    return xn, xk, s


def marginal_statistic(xn: Sequence[Sequence[float]], xk: Sequence[Sequence[float]]) -> Callable:
    """y -> W with W_j = |X_j^T y| - |Xk_j^T y|."""
    xt, xkt = _transpose(xn), _transpose(xk)
    return lambda y: [abs(_dot(a, y)) - abs(_dot(b, y)) for a, b in zip(xt, xkt)]


def ols_statistic(xn: Sequence[Sequence[float]], xk: Sequence[Sequence[float]]) -> Callable:
    """y -> W with W_j = |b_j| - |b_{j+p}|, b the least-squares fit of y on [X Xk]. Needs s < 2 lambda_min."""
    p = len(xn[0])
    aug = [list(r1) + list(r2) for r1, r2 in zip(xn, xk)]
    w, v = jacobi_eigen(_matmul(_transpose(aug), aug))
    if min(w) <= 1e-9 * max(w):
        raise ValueError("[X Xk] is singular; choose s below 2 lambda_min(Sigma)")
    gram_inv = [[sum(v[i][k] * v[j][k] / w[k] for k in range(2 * p)) for j in range(2 * p)] for i in range(2 * p)]
    m = _matmul(gram_inv, _transpose(aug))

    def stat(y: Sequence[float]) -> list[float]:
        b = [_dot(row, y) for row in m]
        return [abs(b[j]) - abs(b[j + p]) for j in range(p)]

    return stat


def knockoff_threshold(w: Sequence, q, plus: bool = True):
    """The smallest t in {|W_j| : W_j != 0} with (offset + #{W <= -t}) <= q max(#{W >= t}, 1); inf if none."""
    offset = 1 if plus else 0
    ts = sorted({abs(x) for x in w if x != 0})  # @line L6
    neg = sorted(-x for x in w if x < 0)
    pos = sorted(x for x in w if x > 0)
    for t in ts:
        n_neg = len(neg) - bisect_left(neg, t)
        n_pos = len(pos) - bisect_left(pos, t)
        if offset + n_neg <= q * max(n_pos, 1):  # @line L7
            return t
    return math.inf


def knockoff_select(w: Sequence, q, plus: bool = True) -> list[bool]:
    t = knockoff_threshold(w, q, plus)
    return [x >= t for x in w]  # @line L8
test_knockoff_filter.py 219 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/knockoff-filter/. The authors are listed in prov/WNY22A.jsonl.

import itertools
import math
import random
import statistics
from fractions import Fraction

import pytest

from knockoff_filter import (
    jacobi_eigen,
    knockoff_select,
    knockoff_threshold,
    knockoffs,
    marginal_statistic,
    ols_statistic,
)

HAND_W = [9, 8, 7.5, 7, 6, 5.5, -5, 4, 3, -2.5, 2, -1, 0.5, -0.3]


def design(rng: random.Random, n: int, p: int, rho: float = 0.5) -> list[list[float]]:
    """Rows share a common factor, so the columns are positively correlated."""
    rows = []
    for _ in range(n):
        z = rng.gauss(0, 1)
        rows.append([rho * z + rng.gauss(0, 1) for _ in range(p)])
    return rows


def gram(a: list, b: list) -> list[list[float]]:
    return [[sum(a[i][j] * b[i][k] for i in range(len(a))) for k in range(len(b[0]))] for j in range(len(a[0]))]


def threshold_brute_force(w: list, q, plus: bool):
    """Smallest admissible t > 0 by the definition: the counts are constant on each interval between |W| values,
    so test every |W_j|, every midpoint and a point below the smallest; return the selected set there."""
    mags = sorted({abs(x) for x in w if x != 0})
    if not mags:
        return [False] * len(w)
    candidates = sorted(set(mags) | {(a + b) / 2 for a, b in zip(mags, mags[1:])} | {mags[0] / 2})
    offset = 1 if plus else 0
    for t in candidates:
        if Fraction(offset + sum(1 for x in w if x <= -t)) / max(sum(1 for x in w if x >= t), 1) <= q:
            return [x >= t for x in w]
    return [False] * len(w)


def test_hand_example() -> None:
    # knockoff+ at q = 0.2: at t = 5.5 there are 6 positives and no negatives at or beyond -5.5, so (1 + 0)/6 <= 0.2,
    # and every smaller t fails, for example t = 5 gives (1 + 1)/6.
    assert knockoff_threshold(HAND_W, Fraction(1, 5)) == 5.5
    assert sum(knockoff_select(HAND_W, Fraction(1, 5))) == 6
    # The plain knockoff stops at t = 3: 8 positives, 1 negative (-5), 1/8 <= 0.2; t = 2.5 gives 2/8.
    assert knockoff_threshold(HAND_W, Fraction(1, 5), plus=False) == 3
    assert sum(knockoff_select(HAND_W, Fraction(1, 5), plus=False)) == 8
    # One null feature with a positive statistic: the plain filter selects it, knockoff+ cannot.
    assert knockoff_select([2.0], Fraction(1, 10), plus=False) == [True]
    assert knockoff_select([2.0], Fraction(1, 10)) == [False]
    assert knockoff_select([0, 0], Fraction(1, 2)) == [False, False]


def test_threshold_matches_definition() -> None:
    rng = random.Random(2015)
    for _ in range(2000):
        p = rng.randint(1, 12)
        w = [rng.choice([-1, 1]) * rng.randint(0, 8) for _ in range(p)]
        q = Fraction(rng.randint(1, 10), 10)
        for plus in (True, False):
            assert knockoff_select(w, q, plus) == threshold_brute_force(w, q, plus)


def test_jacobi_eigen() -> None:
    rng = random.Random(1846)
    for _ in range(30):
        n = rng.randint(1, 7)
        b = [[rng.uniform(-1, 1) for _ in range(n)] for _ in range(n)]
        a = [[b[i][j] + b[j][i] for j in range(n)] for i in range(n)]
        w, v = jacobi_eigen(a)
        for i in range(n):
            for j in range(n):
                assert sum(v[i][k] * w[k] * v[j][k] for k in range(n)) == pytest.approx(a[i][j], abs=1e-10)
                assert sum(v[k][i] * v[k][j] for k in range(n)) == pytest.approx(1.0 if i == j else 0.0, abs=1e-10)


def test_knockoff_gram_identities() -> None:
    rng = random.Random(7)
    for n, p in ((8, 3), (20, 6), (30, 10)):
        x = design(rng, n, p)
        xn, xk, s = knockoffs(x, rng=random.Random(1))
        sigma = gram(xn, xn)
        lam_min = min(jacobi_eigen(sigma)[0])
        assert s == pytest.approx(min(2 * lam_min, 1.0))
        kk, xkx = gram(xk, xk), gram(xn, xk)
        for i in range(p):
            assert sigma[i][i] == pytest.approx(1.0)
            for j in range(p):
                assert kk[i][j] == pytest.approx(sigma[i][j], abs=1e-9)
                assert xkx[i][j] == pytest.approx(sigma[i][j] - (s if i == j else 0.0), abs=1e-9)


def test_swap_leaves_gram_and_flips_statistics() -> None:
    """Swapping X_j and Xk_j for j in S keeps the Gram matrix of [X Xk] and flips the sign of W_j for j in S."""
    rng = random.Random(11)
    n, p = 24, 5
    x = design(rng, n, p)
    xn, xk, s = knockoffs(x, s=None)
    _, _, s_small = knockoffs(x)
    xn2, xk2, _ = knockoffs(x, s=0.9 * s_small)
    y = [rng.gauss(0, 1) for _ in range(n)]
    for subset in [(0,), (1, 3), (0, 2, 4)]:
        xs = [[xk[i][j] if j in subset else xn[i][j] for j in range(p)] for i in range(n)]
        xks = [[xn[i][j] if j in subset else xk[i][j] for j in range(p)] for i in range(n)]
        aug, aug_s = [a + b for a, b in zip(xn, xk)], [a + b for a, b in zip(xs, xks)]
        g, g_s = gram(aug, aug), gram(aug_s, aug_s)
        assert all(g[i][j] == pytest.approx(g_s[i][j], abs=1e-9) for i in range(2 * p) for j in range(2 * p))
        w, w_s = marginal_statistic(xn, xk)(y), marginal_statistic(xs, xks)(y)
        assert all(w_s[j] == pytest.approx(-w[j] if j in subset else w[j], abs=1e-9) for j in range(p))
        xs2 = [[xk2[i][j] if j in subset else xn2[i][j] for j in range(p)] for i in range(n)]
        xks2 = [[xn2[i][j] if j in subset else xk2[i][j] for j in range(p)] for i in range(n)]
        w, w_s = ols_statistic(xn2, xk2)(y), ols_statistic(xs2, xks2)(y)
        assert all(w_s[j] == pytest.approx(-w[j] if j in subset else w[j], abs=1e-7) for j in range(p))


def test_invalid_input() -> None:
    with pytest.raises(ValueError):
        knockoffs([[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]])  # n < 2p
    with pytest.raises(ValueError):
        knockoffs([[1.0, 2.0], [2.0, 4.0], [3.0, 6.0], [1.0, 2.0]])  # collinear columns
    rng = random.Random(3)
    x = design(rng, 10, 3)
    with pytest.raises(ValueError):
        ols_statistic(*knockoffs(x)[:2])  # s = 2 lambda_min makes [X Xk] singular, unless s was capped at 1
    assert knockoff_threshold([], Fraction(1, 10)) == math.inf


def test_exact_fdr_under_coin_flips() -> None:
    """Condition on |W| and the non-null signs; flip the null signs as fair coins, as the sign-flip lemma gives.
    Enumerating all 2^m0 patterns gives the exact FDR. knockoff+ stays <= q and the plain filter's
    E[V / (R + 1/q)] stays <= q (these are the two theorems of Barber and Candes); the plain filter's
    FDR can exceed q."""
    rng = random.Random(4)
    q = Fraction(1, 5)
    worst_plain = Fraction(0)
    for _ in range(150):
        p = rng.randint(1, 9)
        m0 = rng.randint(1, p)
        mags = [Fraction(rng.randint(1, 30)) for _ in range(p)]
        alt_signs = [rng.choice([1, 1, 1, -1]) for _ in range(p - m0)]
        fdr_plus = fdr_plain = mfdr_plain = Fraction(0)
        for signs in itertools.product([1, -1], repeat=m0):
            w = [s * a for s, a in zip(list(signs) + alt_signs, mags)]
            for plus in (True, False):
                sel = knockoff_select(w, q, plus)
                r, v = sum(sel), sum(sel[:m0])
                if plus:
                    fdr_plus += Fraction(v, max(r, 1))
                else:
                    fdr_plain += Fraction(v, max(r, 1))
                    mfdr_plain += v / (r + 1 / q)
        total = 2**m0
        assert fdr_plus / total <= q
        assert mfdr_plain / total <= q
        worst_plain = max(worst_plain, fdr_plain / total)
    assert worst_plain > q


def test_monte_carlo_fdr_on_a_fixed_design() -> None:
    rng = random.Random(2018)
    n, p, k, amp, sigma_noise = 40, 10, 5, 4.0, 1.0
    q, reps = 0.2, 1000
    x = design(rng, n, p)
    xn, xk, s = knockoffs(x, rng=random.Random(5))
    stat = marginal_statistic(xn, xk)
    xn2, xk2, _ = knockoffs(x, s=0.9 * s, rng=random.Random(6))
    stat_ols = ols_statistic(xn2, xk2)
    beta = [amp] * k + [0.0] * (p - k)
    # BH on two-sided z-tests of the OLS coefficients, with the noise level known, for comparison.
    ev, evec = jacobi_eigen(gram(xn, xn))
    sinv = [[sum(evec[i][m] * evec[j][m] / ev[m] for m in range(p)) for j in range(p)] for i in range(p)]
    nd = statistics.NormalDist()
    results = {"plus": [0.0, 0.0], "plain": [0.0, 0.0], "ols_plus": [0.0, 0.0], "bh": [0.0, 0.0]}
    signs_null = 0
    for _ in range(reps):
        y = [sum(xn[i][j] * beta[j] for j in range(p)) + sigma_noise * rng.gauss(0, 1) for i in range(n)]
        y2 = [sum(xn2[i][j] * beta[j] for j in range(p)) + sigma_noise * rng.gauss(0, 1) for i in range(n)]
        w, w2 = stat(y), stat_ols(y2)
        signs_null += sum(1 for v in w[k:] if v > 0)
        xty = [sum(xn[i][j] * y[i] for i in range(n)) for j in range(p)]
        z = [sum(sinv[j][m] * xty[m] for m in range(p)) / math.sqrt(sinv[j][j]) for j in range(p)]
        pv = sorted((2 * (1 - nd.cdf(abs(z[j]))), j) for j in range(p))
        r_bh = max([i + 1 for i in range(p) if pv[i][0] <= (i + 1) * q / p] or [0])
        sel_bh = [False] * p
        for _, j in pv[:r_bh]:
            sel_bh[j] = True
        rules = {
            "plus": knockoff_select(w, q),
            "plain": knockoff_select(w, q, plus=False),
            "ols_plus": knockoff_select(w2, q),
            "bh": sel_bh,
        }
        for name, sel in rules.items():
            r = sum(sel)
            results[name][0] += sum(sel[k:]) / max(r, 1)
            results[name][1] += sum(sel[:k]) / k
    fdr = {name: v[0] / reps for name, v in results.items()}
    power = {name: v[1] / reps for name, v in results.items()}
    # Null statistics are positive half the time: 5000 signs, standard error 0.007.
    assert abs(signs_null / ((p - k) * reps) - 0.5) < 0.03
    # knockoff+ has FDR <= q = 0.2 by the theorem; 1000 runs give a standard error near 0.005.
    # With this seed: knockoff+ 0.12 (marginal W) and 0.11 (OLS W); the plain knockoff 0.23, above q.
    assert fdr["plus"] <= q + 0.02 and fdr["ols_plus"] <= q + 0.02
    assert fdr["plain"] > q
    # With p = 10, knockoff+ needs at least 1/q = 5 selections; BH on exact z-tests is more powerful here.
    assert 0.3 < power["plus"] < power["plain"] and power["ols_plus"] > 0.3
    assert power["bh"] > power["plus"]
    assert fdr["bh"] <= q

History

Rina Foygel Barber and Emmanuel Candès introduced the knockoff filter in a paper published in the Annals of Statistics in 2015. They proved the FDR control with a martingale argument that also covers a class of sequential testing problems. Candès, Fan, Janson and Lv (2018) extended the idea to random designs with model-X knockoffs, which removed the limit n≥2pn \ge 2p and the linear model. Later work studied power, knockoffs for hidden Markov models in genetics, derandomized and multiple knockoffs, and robustness to a misspecified feature law.

References

  1. Rina Foygel Barber and Emmanuel J. Candès, Controlling the false discovery rate via knockoffs, Annals of Statistics 43(5) (2015), pages 2055 to 2085, Definitions 1 and 2 (the knockoff and knockoff+ thresholds), Theorems 1 and 2 (modified FDR and FDR control), Section 2.1 (construction and the equicorrelated choice), Section 2.2 (sufficiency, antisymmetry and example statistics), Lemmas 1 to 3 in Section 2.3 (i.i.d. signs for the nulls)
  2. Emmanuel Candès, Yingying Fan, Lucas Janson and Jinchi Lv, Panning for gold, model-X knockoffs for high dimensional controlled variable selection, Journal of the Royal Statistical Society Series B 80(3) (2018), pages 551 to 577, model-X knockoffs for a known distribution of the features, with FDR control of knockoff+ for any n and p, and the Gaussian construction

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of correctness
  • a full proof of time.construction
  • a full proof of time.filter
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • at least three sources
  • a scene preset for the example