Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Conformal p-values, PRDS, FDR procedures and calibration-conditional adjustments

Definition
ConformalOutlierTesting_Basic

by Xeroth · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

conformal-inferencefalse-discovery-ratemultiple-testingoutlier-detectionprds

Objects of Sections 1–4 and Appendix A of Bates, Candès, Lei, Romano and Sesia, Testing for Outliers with Conformal p-values (arXiv:2104.08279v3). The training data are held fixed, so every object is a function of the scores s^(X)\hat s(X)s^(X).

  1. Scores and their law. There are nnn calibration scores s=(s1,…,sn)s=(s_1,\dots,s_n)s=(s1​,…,sn​) and mmm test scores t=(t1,…,tm)t=(t_1,\dots,t_m)t=(t1​,…,tm​). Their joint law is μ⊗n⊗⨂j=1mνj\mu^{\otimes n}\otimes\bigotimes_{j=1}^m\nu_jμ⊗n⊗⨂j=1m​νj​. Here μ\muμ is the law of s^(X)\hat s(X)s^(X) for X∼PXX\sim P_XX∼PX​, and νj\nu_jνj​ is the score law of test point jjj, with νj=μ\nu_j=\muνj​=μ for an inlier. So the calibration scores are i.i.d., and all test scores are independent of each other and of the calibration data.
  2. Marginal conformal p-value (eq. 3). u^(marg)(x)=1+∣{i:si≤x}∣n+1\hat u^{(\mathrm{marg})}(x)=\dfrac{1+|\{i:s_i\le x\}|}{n+1}u^(marg)(x)=n+11+∣{i:si​≤x}∣​. The vector of test p-values is pj=u^(marg)(tj)p_j=\hat u^{(\mathrm{marg})}(t_j)pj​=u^(marg)(tj​).
  3. Order statistics. s(1)≤⋯≤s(n)s_{(1)}\le\dots\le s_{(n)}s(1)​≤⋯≤s(n)​ is the sorted vector.
  4. PRDS (Definition 1). A set A⊆RmA\subseteq\mathbb R^mA⊆Rm is increasing if a∈Aa\in Aa∈A and b⪰ab\succeq ab⪰a coordinatewise imply b∈Ab\in Ab∈A. A random vector XXX is PRDS on I0I_0I0​ if, for every i∈I0i\in I_0i∈I0​ and every measurable increasing AAA, the conditional probability P[X∈A∣Xi=x]\mathbb P[X\in A\mid X_i=x]P[X∈A∣Xi​=x] has a version that is nondecreasing in xxx.
  5. FDR (eq. 7). For a rejection set R\mathcal RR and true nulls H0\mathcal H_0H0​, the false discovery proportion is ∣R∩H0∣/max⁡{1,∣R∣}|\mathcal R\cap\mathcal H_0|/\max\{1,|\mathcal R|\}∣R∩H0​∣/max{1,∣R∣}, and the FDR is its expectation.
  6. BH. R(α)=max⁡{r∈{0,…,m}:∣{i:pi≤rα/m}∣≥r}R(\alpha)=\max\{r\in\{0,\dots,m\}:|\{i:p_i\le r\alpha/m\}|\ge r\}R(α)=max{r∈{0,…,m}:∣{i:pi​≤rα/m}∣≥r}, and the procedure rejects {i:pi≤αR(α)/m}\{i:p_i\le\alpha R(\alpha)/m\}{i:pi​≤αR(α)/m}.
  7. Storey–BH (Appendix A.4). Let A=∑iI(pi≥λ)A=\sum_i I(p_i\ge\lambda)A=∑i​I(pi​≥λ) and π^0=(1+A)/(m(1−λ))\hat\pi_0=(1+A)/(m(1-\lambda))π^0​=(1+A)/(m(1−λ)). Let R=max⁡{r:p(r)≤αr/(mπ^0), p(r)<λ}R=\max\{r:p_{(r)}\le\alpha r/(m\hat\pi_0),\ p_{(r)}<\lambda\}R=max{r:p(r)​≤αr/(mπ^0​), p(r)​<λ}, with R=0R=0R=0 if no rrr qualifies. The procedure rejects {i:pi≤αR/(mπ^0), pi<λ}\{i:p_i\le\alpha R/(m\hat\pi_0),\ p_i<\lambda\}{i:pi​≤αR/(mπ^0​), pi​<λ}.
  8. Calibration-conditional adjustment (eqs. 10–11). A sequence b0=0≤b1≤⋯≤bn≤bn+1=1b_0=0\le b_1\le\dots\le b_n\le b_{n+1}=1b0​=0≤b1​≤⋯≤bn​≤bn+1​=1 satisfies the band condition at level δ\deltaδ if P[U(1)≤b1,…,U(n)≤bn]≥1−δ\mathbb P[U_{(1)}\le b_1,\dots,U_{(n)}\le b_n]\ge1-\deltaP[U(1)​≤b1​,…,U(n)​≤bn​]≥1−δ for U1,…,UnU_1,\dots,U_nU1​,…,Un​ i.i.d. uniform on [0,1][0,1][0,1]. The adjustment function is h(t)=b⌈(n+1)t⌉h(t)=b_{\lceil(n+1)t\rceil}h(t)=b⌈(n+1)t⌉​.
  9. False positive rate (eq. 9). FPR(α;D)=μ{x:u^(marg)(x)≤α}\mathrm{FPR}(\alpha;\mathcal D)=\mu\{x:\hat u^{(\mathrm{marg})}(x)\le\alpha\}FPR(α;D)=μ{x:u^(marg)(x)≤α}, as a function of the calibration scores.
  10. Fisher's test. The statistic is −2∑ilog⁡u^(marg)(ti)-2\sum_i\log\hat u^{(\mathrm{marg})}(t_i)−2∑i​logu^(marg)(ti​). χ2(k;q)\chi^2(k;q)χ2(k;q) is the qqq-quantile inf⁡{x:F(x)≥q}\inf\{x:F(x)\ge q\}inf{x:F(x)≥q} of the chi-square law with kkk degrees of freedom, which is the gamma law with shape k/2k/2k/2 and rate 1/21/21/2. zqz_qzq​ is the qqq-quantile of N(0,1)N(0,1)N(0,1) and Φˉ=1−Φ\bar\Phi=1-\PhiΦˉ=1−Φ. The conditional type-I error given D\mathcal DD is the μ⊗m\mu^{\otimes m}μ⊗m-probability of rejection with the calibration scores fixed.
  11. Correlation. Cor[X,Y]=Cov[X,Y]/VarX VarY\mathrm{Cor}[X,Y]=\mathrm{Cov}[X,Y]/\sqrt{\mathrm{Var}X\,\mathrm{Var}Y}Cor[X,Y]=Cov[X,Y]/VarXVarY​.

Formalization Note The test scores are modelled as independent of each other and of the calibration data, as in Section 1.1. Theorem 2 as printed asks only that the inliers be independent. Its proof assumes this full independence (see the note on Theorem 2). The Storey–BH estimate uses I(pi≥λ)I(p_i\ge\lambda)I(pi​≥λ), as in Appendix A.4 and its proofs. The main text (Section 2.3) writes I(pi>λ)I(p_i>\lambda)I(pi​>λ).

Definition code
import Mathlib

/-!
Bates, Candès, Lei, Romano and Sesia, *Testing for Outliers with Conformal p-values*,
arXiv:2104.08279v3: marginal conformal p-values (Section 1.1, eq. (3)), positive regression
dependence (Section 2.2, Definition 1), the false discovery rate with the Benjamini–Hochberg and
Storey–BH procedures (Section 2.2, eq. (7); Appendix A.4), calibration-conditional adjustments
(Section 3.2, eqs. (10)–(11)), the pointwise false positive rate (Section 3.1, eq. (9)) and the
quantities of Fisher's combination test (Section 2.1).

The training data are treated as fixed (Section 1.1), so every object is a function of the scores
`ŝ(X_i)`: calibration scores `s : Fin n → ℝ` and test scores `t : Fin m → ℝ`.
-/

open MeasureTheory ProbabilityTheory

noncomputable section

namespace ConformalOutlierTesting

variable {n m : ℕ}

/-- Section 1.1, eq. (3): the marginal conformal p-value of a test score `x` given calibration
scores `s₁, …, sₙ`, `û^(marg)(x) = (1 + |{i : sᵢ ≤ x}|) / (n + 1)`. -/
def margPval (s : Fin n → ℝ) (x : ℝ) : ℝ :=
  (1 + ((Finset.univ.filter fun i => s i ≤ x).card : ℝ)) / (n + 1)

/-- The order statistics `s₍₁₎ ≤ ⋯ ≤ s₍ₙ₎` of a vector, indexed from `0`: `orderStat s k = s₍ₖ₊₁₎`
(Section 3.2, Theorem 4; Appendix A.3, `Z = (S₍₁₎, …, S₍ₙ₎)`). -/
def orderStat (s : Fin n → ℝ) : Fin n → ℝ :=
  s ∘ Tuple.sort s

/-- Section 1.1 and Theorem 2: the joint law of the calibration scores and the test scores. The
`n` calibration scores are i.i.d. with law `μ` (the law of `ŝ(X)` for `X ∼ P_X`), the `m` test
scores are independent of them and of each other, and test point `j` has score law `ν j`
(equal to `μ` for an inlier). -/
def scoreLaw (μ : Measure ℝ) (ν : Fin m → Measure ℝ) :
    Measure ((Fin n → ℝ) × (Fin m → ℝ)) :=
  (Measure.pi fun _ : Fin n => μ).prod (Measure.pi ν)

/-- Section 2.2: the vector `(û^(marg)(X_{2n+1}), …, û^(marg)(X_{2n+m}))` of marginal conformal
p-values of the test points, as a function of (calibration scores, test scores). -/
def margPvals (ω : (Fin n → ℝ) × (Fin m → ℝ)) : Fin m → ℝ :=
  fun j => margPval ω.1 (ω.2 j)

/-- Section 2.2, Definition 1: a random vector `X = (X₁, …, X_m)` is PRDS on `I₀` if for every
`i ∈ I₀` and every (measurable) increasing set `A`, `P[X ∈ A | X_i = x]` is nondecreasing in `x`,
i.e. this conditional probability has a nondecreasing version `f(x)`. -/
def IsPRDS {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) (X : Ω → Fin m → ℝ)
    (I₀ : Finset (Fin m)) : Prop :=
  ∀ i ∈ I₀, ∀ A : Set (Fin m → ℝ), IsUpperSet A → MeasurableSet A →
    ∃ f : ℝ → ℝ, Monotone f ∧
      (fun ω => f (X ω i)) =ᵐ[P]
        condExp (MeasurableSpace.comap (fun ω => X ω i) inferInstance) P
          ((X ⁻¹' A).indicator fun _ => (1 : ℝ))

/-- Section 2.2, eq. (7): the false discovery proportion `|R ∩ H₀| / max{1, |R|}` of a rejection
set `R` when the true nulls are `H₀`. -/
def fdp (R H₀ : Finset (Fin m)) : ℝ :=
  ((R ∩ H₀).card : ℝ) / max 1 (R.card : ℝ)

/-- Section 2.2, eq. (7): the false discovery rate `E[|R ∩ H₀| / max{1, |R|}]` of a random
rejection set. -/
def fdr {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) (rej : Ω → Finset (Fin m))
    (H₀ : Finset (Fin m)) : ℝ :=
  ∫ ω, fdp (rej ω) H₀ ∂P

/-- Section 2.2 (Corollary 1) and Section 3.6.4: the number of BH rejections at level `α`,
`R(α) = max{r ∈ {0, …, m} : |{i : p_i ≤ rα/m}| ≥ r}`. -/
def bhCount (α : ℝ) (p : Fin m → ℝ) : ℕ :=
  ((Finset.range (m + 1)).filter fun r : ℕ =>
    r ≤ (Finset.univ.filter fun i => p i ≤ ((r : ℕ) : ℝ) * α / m).card).sup id

/-- Section 2.2 (Corollary 1) and Section 3.6.4: the BH procedure at level `α` rejects every
hypothesis with `p_i ≤ α R(α) / m`. -/
def bhRej (α : ℝ) (p : Fin m → ℝ) : Finset (Fin m) :=
  Finset.univ.filter fun i => p i ≤ (bhCount α p : ℝ) * α / m

/-- Appendix A.4: `A = Σᵢ I(p_i ≥ λ)`, the number of p-values at least `λ`. -/
def storeyA (lam : ℝ) (p : Fin m → ℝ) : ℕ :=
  (Finset.univ.filter fun i => lam ≤ p i).card

/-- Appendix A.4: Storey's estimate `π̂₀ = (1 + A) / (m (1 - λ))` of the proportion of nulls. -/
def storeyPi0 (lam : ℝ) (p : Fin m → ℝ) : ℝ :=
  (1 + (storeyA lam p : ℝ)) / (m * (1 - lam))

/-- Appendix A.4: `R = max{r : p₍ᵣ₎ ≤ α r / (m π̂₀), p₍ᵣ₎ < λ}` (and `R = 0` if no `r ∈ {1, …, m}`
qualifies); the index `r : Fin m` stands for `r + 1`. -/
def storeyCount (α lam : ℝ) (p : Fin m → ℝ) : ℕ :=
  (Finset.univ.filter fun r : Fin m =>
    orderStat p r ≤ α * ((r : ℕ) + 1 : ℝ) / (m * storeyPi0 lam p) ∧ orderStat p r < lam).sup
    fun r => (r : ℕ) + 1

/-- Section 2.3 and Appendix A.4: the rejection set of the Storey–BH procedure,
`R = {i : p_i ≤ α R / (m π̂₀), p_i < λ}`. -/
def storeyRej (α lam : ℝ) (p : Fin m → ℝ) : Finset (Fin m) :=
  Finset.univ.filter fun i =>
    p i ≤ α * (storeyCount α lam p : ℝ) / (m * storeyPi0 lam p) ∧ p i < lam

/-- Section 3.2, Theorem 4: the uniform law on `[0, 1]`. -/
def unifLaw : Measure ℝ :=
  (volume : Measure ℝ).restrict (Set.Icc 0 1)

/-- Section 3.2, Theorem 4, eq. (10): `b₀ = 0`, `b_{n+1} = 1`, `0 ≤ b₁ ≤ ⋯ ≤ bₙ ≤ 1`, and for
`U₁, …, Uₙ` i.i.d. uniform on `[0, 1]`, `P[U₍₁₎ ≤ b₁, …, U₍ₙ₎ ≤ bₙ] ≥ 1 - δ`. -/
def IsCCVSequence (n : ℕ) (δ : ℝ) (b : ℕ → ℝ) : Prop :=
  b 0 = 0 ∧ b (n + 1) = 1 ∧ (∀ i, 1 ≤ i → i ≤ n → 0 ≤ b i ∧ b i ≤ 1) ∧
    (∀ i, 1 ≤ i → i < n → b i ≤ b (i + 1)) ∧
    ENNReal.ofReal (1 - δ) ≤
      (Measure.pi fun _ : Fin n => unifLaw) {u | ∀ k : Fin n, orderStat u k ≤ b ((k : ℕ) + 1)}

/-- Section 3.2, Theorem 4, eq. (11): the piecewise-constant adjustment function
`h(t) = b_{⌈(n+1)t⌉}`, `t ∈ [0, 1]`. -/
def adjFun (b : ℕ → ℝ) (n : ℕ) (t : ℝ) : ℝ :=
  b ⌈((n : ℝ) + 1) * t⌉₊

/-- Section 3.1, eq. (9): the conditional false positive rate
`FPR(α; D) = P[û^(marg)(X_{2n+1}) ≤ α | D]` of an inlier test point whose score has law `μ`, as a
function of the calibration scores. -/
def fpr (μ : Measure ℝ) (s : Fin n → ℝ) (α : ℝ) : ℝ :=
  (μ {x | margPval s x ≤ α}).toReal

/-- Section 2.1: the `q`-quantile `inf{x : F_ν(x) ≥ q}` of a law `ν` on `ℝ`. -/
def quantile (ν : Measure ℝ) (q : ℝ) : ℝ :=
  sInf {x | q ≤ cdf ν x}

/-- Section 2.1: the chi-square law with `k` degrees of freedom, the gamma law with shape `k/2`
and rate `1/2`. -/
def chiSqLaw (k : ℕ) : Measure ℝ :=
  gammaMeasure ((k : ℝ) / 2) (1 / 2)

/-- Section 2.1: the standard normal law `N(0, 1)`. -/
def stdNormal : Measure ℝ :=
  gaussianReal 0 1

/-- Section 2.1, Theorem 1: the survival function `Φ̄(x) = 1 - Φ(x)` of `N(0, 1)`. -/
def normSurv (x : ℝ) : ℝ :=
  1 - cdf stdNormal x

/-- Section 2.1: Fisher's combination statistic `-2 Σᵢ log û^(marg)(X_{2n+i})` of the test
scores `t` given calibration scores `s`. -/
def fisherStat (s : Fin n → ℝ) (t : Fin m → ℝ) : ℝ :=
  -2 * ∑ i, Real.log (margPval s (t i))

/-- Section 2.1, Theorem 1, eq. (5): under the global null, the conditional type-I error
`P[-2 Σᵢ log û^(marg)(X_{2n+i}) ≥ χ²(2m; 1-α) | D]` of Fisher's combination test, as a function of
the calibration scores (the `m` test scores are i.i.d. with law `μ`, independent of `D`). -/
def condFisherRejProb (μ : Measure ℝ) (m : ℕ) (α : ℝ) (s : Fin n → ℝ) : ℝ :=
  ((Measure.pi fun _ : Fin m => μ)
    {t | quantile (chiSqLaw (2 * m)) (1 - α) ≤ fisherStat s t}).toReal

/-- Section 2.1, Lemma 1: the correlation `Cor[X, Y] = Cov[X, Y] / √(Var X · Var Y)`. -/
def corr {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) (X Y : Ω → ℝ) : ℝ :=
  covariance X Y P / Real.sqrt (variance X P * variance Y P)

end ConformalOutlierTesting
Source
Bates, Candès, Lei, Romano and Sesia, Testing for Outliers with Conformal p-values, arXiv:2104.08279v3 (2022), Section 1.1 eq. (3), Section 2.1, Section 2.2 Definition 1 and eq. (7), Section 3.1 eq. (9), Section 3.2 eqs. (10)-(11), Section 3.6.4, Appendix A.4 (p. 42)
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

margPval (marginal conformal p-value). Let n∈Nn \in \mathbb{N}n∈N, let s=(s1,…,sn)∈Rns = (s_1, \dots, s_n) \in \mathbb{R}^ns=(s1​,…,sn​)∈Rn be calibration scores, and let x∈Rx \in \mathbb{R}x∈R. The value is

u^(x)  =  1+#{ i∈{1,…,n}:si≤x }n+1.\hat u(x) \;=\; \frac{1 + \#\{\, i \in \{1,\dots,n\} : s_i \le x \,\}}{n+1}.u^(x)=n+11+#{i∈{1,…,n}:si​≤x}​.

The count uses the non-strict inequality si≤xs_i \le xsi​≤x, so the value increases with xxx: more calibration scores at or below xxx give a larger p-value. The value always lies in [1n+1,1]\big[\tfrac{1}{n+1}, 1\big][n+11​,1] and is strictly positive. When n=0n = 0n=0 it equals 111 for every xxx.


orderStat (order statistics). For s∈Rns \in \mathbb{R}^ns∈Rn, this is the vector (s(1),…,s(n))(s_{(1)}, \dots, s_{(n)})(s(1)​,…,s(n)​), the entries of sss rearranged in nondecreasing order. It is indexed from 000, so entry k∈{0,…,n−1}k \in \{0, \dots, n-1\}k∈{0,…,n−1} is s(k+1)s_{(k+1)}s(k+1)​, the (k+1)(k+1)(k+1)-th smallest entry. Tied values are repeated according to their multiplicity. When n=0n = 0n=0 it is the empty vector.


scoreLaw (joint law of the scores). Given a measure μ\muμ on R\mathbb{R}R and measures ν1,…,νm\nu_1, \dots, \nu_mν1​,…,νm​ on R\mathbb{R}R, this is the product measure on Rn×Rm\mathbb{R}^n \times \mathbb{R}^mRn×Rm:

μ⊗n⊗(ν1⊗⋯⊗νm).\mu^{\otimes n} \otimes (\nu_1 \otimes \cdots \otimes \nu_m).μ⊗n⊗(ν1​⊗⋯⊗νm​).
  • The first factor is the law of the calibration vector sss.
  • The second factor is the law of the test vector ttt.

The definition places no requirement that μ\muμ or the νj\nu_jνj​ be probability measures (or even finite). It builds the product measure from whatever measures are supplied.


margPvals (vector of test p-values). For a pair ω=(s,t)\omega = (s, t)ω=(s,t) with s∈Rns \in \mathbb{R}^ns∈Rn and t∈Rmt \in \mathbb{R}^mt∈Rm, this is the vector in Rm\mathbb{R}^mRm whose jjj-th entry is

u^(tj)=1+#{i:si≤tj}n+1.\hat u(t_j) = \frac{1 + \#\{i : s_i \le t_j\}}{n+1}.u^(tj​)=n+11+#{i:si​≤tj​}​.

This is the marginal conformal p-value above, applied to test score tjt_jtj​ with calibration scores sss.


IsPRDS (positive regression dependence on a subset). Let (Ω,P)(\Omega, P)(Ω,P) be a measurable space with an arbitrary measure PPP, which is not required to be a probability measure. Let X:Ω→RmX : \Omega \to \mathbb{R}^mX:Ω→Rm be a function, not assumed measurable, and let I0⊆{1,…,m}I_0 \subseteq \{1, \dots, m\}I0​⊆{1,…,m}. The property holds when, for every i∈I0i \in I_0i∈I0​ and every measurable upper set A⊆RmA \subseteq \mathbb{R}^mA⊆Rm, there is a nondecreasing function f:R→Rf : \mathbb{R} \to \mathbb{R}f:R→R such that, for PPP-almost every ω\omegaω,

f(Xi(ω))  =  EP ⁣[1{X∈A} | σ(Xi)](ω).f\big(X_i(\omega)\big) \;=\; \mathbb{E}_P\!\left[\mathbf{1}\{X \in A\} \,\middle|\, \sigma(X_i)\right](\omega).f(Xi​(ω))=EP​[1{X∈A}∣σ(Xi​)](ω).
  • An upper set is taken in the coordinatewise order: if x∈Ax \in Ax∈A and y≥xy \ge xy≥x in every coordinate, then y∈Ay \in Ay∈A.
  • σ(Xi)\sigma(X_i)σ(Xi​) is the σ\sigmaσ-algebra generated by the iii-th coordinate XiX_iXi​.

Degenerate cases:

  • If I0=∅I_0 = \emptysetI0​=∅, the property holds vacuously.
  • The conditional expectation is the library's: it is defined to be 000 whenever its prerequisites fail. This happens, for example, if XiX_iXi​ or XXX is not measurable (so σ(Xi)\sigma(X_i)σ(Xi​) is not contained in the ambient σ\sigmaσ-algebra, or the indicator is not integrable), or if PPP is not σ\sigmaσ-finite on σ(Xi)\sigma(X_i)σ(Xi​). In those situations f≡0f \equiv 0f≡0 works and the property holds trivially.
  • fff only needs to match on the range of XiX_iXi​, up to PPP-null sets. Elsewhere it is unconstrained apart from being nondecreasing.

fdp (false discovery proportion). For finite sets R,H0⊆{1,…,m}R, H_0 \subseteq \{1, \dots, m\}R,H0​⊆{1,…,m}, the value is

FDP(R;H0)=∣R∩H0∣max⁡{1,∣R∣}.\mathrm{FDP}(R; H_0) = \frac{|R \cap H_0|}{\max\{1, |R|\}}.FDP(R;H0​)=max{1,∣R∣}∣R∩H0​∣​.

It equals 000 when R=∅R = \emptysetR=∅, and it always lies in [0,1][0,1][0,1].


fdr (false discovery rate). Let (Ω,P)(\Omega, P)(Ω,P) be a measurable space with an arbitrary measure PPP. Let ω↦R(ω)\omega \mapsto R(\omega)ω↦R(ω) assign a subset of {1,…,m}\{1, \dots, m\}{1,…,m} to each outcome, and let H0⊆{1,…,m}H_0 \subseteq \{1,\dots,m\}H0​⊆{1,…,m}. The value is the integral

FDR=∫Ω∣R(ω)∩H0∣max⁡{1,∣R(ω)∣} dP(ω).\mathrm{FDR} = \int_\Omega \frac{|R(\omega) \cap H_0|}{\max\{1, |R(\omega)|\}} \, dP(\omega).FDR=∫Ω​max{1,∣R(ω)∣}∣R(ω)∩H0​∣​dP(ω).

This is the (Bochner) integral, which is set to 000 whenever the integrand is not PPP-integrable. That happens, for example, if ω↦R(ω)\omega \mapsto R(\omega)ω↦R(ω) is not measurable, or if PPP is an infinite measure and the integrand is not integrable. PPP is not required to be a probability measure. When PPP is one and the integrand is measurable, the value lies in [0,1][0,1][0,1].


bhCount (number of Benjamini–Hochberg rejections). For α∈R\alpha \in \mathbb{R}α∈R, which is not restricted in sign or size, and p=(p1,…,pm)∈Rmp = (p_1, \dots, p_m) \in \mathbb{R}^mp=(p1​,…,pm​)∈Rm, the value is

R(α)=max⁡{ r∈{0,1,…,m}  :  #{i:pi≤rα/m}≥r }.R(\alpha) = \max\Big\{\, r \in \{0, 1, \dots, m\} \;:\; \#\{ i : p_i \le r\alpha/m \} \ge r \,\Big\}.R(α)=max{r∈{0,1,…,m}:#{i:pi​≤rα/m}≥r}.
  • r=0r = 0r=0 always qualifies, so the maximum exists and R(α)≥0R(\alpha) \ge 0R(α)≥0.
  • When m=0m = 0m=0, the quotient rα/mr\alpha/mrα/m is taken to be 000 and R(α)=0R(\alpha) = 0R(α)=0.
  • The pip_ipi​ are arbitrary reals and need not lie in [0,1][0,1][0,1].

bhRej (Benjamini–Hochberg rejection set). For α∈R\alpha \in \mathbb{R}α∈R and p∈Rmp \in \mathbb{R}^mp∈Rm, the set is

{ i∈{1,…,m}:pi≤αR(α)/m },\{\, i \in \{1, \dots, m\} : p_i \le \alpha R(\alpha)/m \,\},{i∈{1,…,m}:pi​≤αR(α)/m},

with R(α)R(\alpha)R(α) as in bhCount. If R(α)=0R(\alpha) = 0R(α)=0 (or m=0m = 0m=0), the threshold is 000. In that case every iii with pi≤0p_i \le 0pi​≤0 is still included, which can only occur when α<0\alpha < 0α<0.


storeyA. For λ∈R\lambda \in \mathbb{R}λ∈R and p∈Rmp \in \mathbb{R}^mp∈Rm, this is the count

A=#{ i:pi≥λ }.A = \#\{\, i : p_i \ge \lambda \,\}.A=#{i:pi​≥λ}.

storeyPi0 (Storey's null-proportion estimate). For λ∈R\lambda \in \mathbb{R}λ∈R and p∈Rmp \in \mathbb{R}^mp∈Rm, the value is

π^0=1+Am(1−λ),\hat\pi_0 = \frac{1 + A}{m(1 - \lambda)},π^0​=m(1−λ)1+A​,

with AAA as in storeyA. There is no restriction on λ\lambdaλ:

  • If m=0m = 0m=0 or λ=1\lambda = 1λ=1, the denominator is 000 and the value is defined to be 000.
  • If λ>1\lambda > 1λ>1, the value is negative.

storeyCount (number of Storey–BH rejections). For α,λ∈R\alpha, \lambda \in \mathbb{R}α,λ∈R and p∈Rmp \in \mathbb{R}^mp∈Rm, let p(1)≤⋯≤p(m)p_{(1)} \le \dots \le p_{(m)}p(1)​≤⋯≤p(m)​ be the sorted entries of ppp. The value RRR is the largest r∈{1,…,m}r \in \{1, \dots, m\}r∈{1,…,m} satisfying both

p(r)≤α rm π^0andp(r)<λ,p_{(r)} \le \frac{\alpha\, r}{m\, \hat\pi_0} \quad\text{and}\quad p_{(r)} < \lambda,p(r)​≤mπ^0​αr​andp(r)​<λ,

and R=0R = 0R=0 if no such rrr exists. When mπ^0=0m\hat\pi_0 = 0mπ^0​=0, the right-hand side of the first condition is defined to be 000. This covers the cases m=0m = 0m=0 and λ=1\lambda = 1λ=1. When m≥1m \ge 1m≥1 and λ≠1\lambda \ne 1λ=1, we have mπ^0=(1+A)/(1−λ)m\hat\pi_0 = (1+A)/(1-\lambda)mπ^0​=(1+A)/(1−λ).


storeyRej (Storey–BH rejection set). For α,λ∈R\alpha, \lambda \in \mathbb{R}α,λ∈R and p∈Rmp \in \mathbb{R}^mp∈Rm, the set is

{ i∈{1,…,m}:pi≤αRmπ^0 and pi<λ },\Big\{\, i \in \{1, \dots, m\} : p_i \le \frac{\alpha R}{m \hat\pi_0} \ \text{and}\ p_i < \lambda \,\Big\},{i∈{1,…,m}:pi​≤mπ^0​αR​ and pi​<λ},

with RRR from storeyCount and π^0\hat\pi_0π^0​ from storeyPi0. If mπ^0=0m\hat\pi_0 = 0mπ^0​=0, the first threshold is 000.


unifLaw (uniform law on [0,1][0,1][0,1]). This is Lebesgue measure on R\mathbb{R}R restricted to the closed interval [0,1][0,1][0,1]. It is a probability measure.


IsCCVSequence (calibration-conditional adjustment sequence). Given n∈Nn \in \mathbb{N}n∈N, δ∈R\delta \in \mathbb{R}δ∈R and a sequence b=(b0,b1,b2,… )b = (b_0, b_1, b_2, \dots)b=(b0​,b1​,b2​,…) of reals indexed by all of N\mathbb{N}N, the property holds when all of the following are true:

  • b0=0b_0 = 0b0​=0 and bn+1=1b_{n+1} = 1bn+1​=1;
  • 0≤bi≤10 \le b_i \le 10≤bi​≤1 for 1≤i≤n1 \le i \le n1≤i≤n;
  • bi≤bi+1b_i \le b_{i+1}bi​≤bi+1​ for 1≤i<n1 \le i < n1≤i<n, so that b1≤⋯≤bnb_1 \le \dots \le b_nb1​≤⋯≤bn​;
  • with U1,…,UnU_1, \dots, U_nU1​,…,Un​ i.i.d. uniform on [0,1][0,1][0,1] and order statistics U(1)≤⋯≤U(n)U_{(1)} \le \dots \le U_{(n)}U(1)​≤⋯≤U(n)​,
max⁡{0, 1−δ}  ≤  P[ U(k)≤bk for all k=1,…,n ].\max\{0,\, 1 - \delta\} \;\le\; P\big[\, U_{(k)} \le b_k \ \text{for all } k = 1, \dots, n \,\big].max{0,1−δ}≤P[U(k)​≤bk​ for all k=1,…,n].

Edge cases:

  • The values bib_ibi​ for i>n+1i > n+1i>n+1 are unconstrained.
  • If δ≥1\delta \ge 1δ≥1, the probability condition holds trivially.
  • If δ<0\delta < 0δ<0, it is impossible to satisfy, since the probability is at most 1<1−δ1 < 1 - \delta1<1−δ.
  • For n=0n = 0n=0, the event is certain, so the condition reduces to δ≥0\delta \ge 0δ≥0, together with b0=0b_0 = 0b0​=0 and b1=1b_1 = 1b1​=1.

adjFun (piecewise-constant adjustment function). For a sequence b=(b0,b1,… )b = (b_0, b_1, \dots)b=(b0​,b1​,…), n∈Nn \in \mathbb{N}n∈N and t∈Rt \in \mathbb{R}t∈R, the value is

h(t)=b⌈(n+1)t⌉+,h(t) = b_{\lceil (n+1)t \rceil_+},h(t)=b⌈(n+1)t⌉+​​,

where ⌈y⌉+\lceil y \rceil_+⌈y⌉+​ is the smallest natural number ≥y\ge y≥y, taken to be 000 when y≤0y \le 0y≤0. The argument ttt is not restricted to [0,1][0,1][0,1]:

  • For t≤0t \le 0t≤0 the value is b0b_0b0​.
  • For t>1t > 1t>1 the index exceeds n+1n+1n+1, and the value is whatever the sequence holds there.

fpr (conditional false positive rate). For a measure μ\muμ on R\mathbb{R}R, which is not required to be a probability measure, calibration scores s∈Rns \in \mathbb{R}^ns∈Rn and α∈R\alpha \in \mathbb{R}α∈R, the value is

FPR(α;s)=μ({ x∈R:u^(x)≤α }),\mathrm{FPR}(\alpha; s) = \mu\big(\{\, x \in \mathbb{R} : \hat u(x) \le \alpha \,\}\big),FPR(α;s)=μ({x∈R:u^(x)≤α}),

where u^(x)=1+#{i:si≤x}n+1\hat u(x) = \frac{1 + \#\{i : s_i \le x\}}{n+1}u^(x)=n+11+#{i:si​≤x}​. It is converted to a real number, and it is 000 if this measure is infinite.


quantile. For a measure ν\nuν on R\mathbb{R}R and q∈Rq \in \mathbb{R}q∈R, the value is

inf⁡{ x∈R:Fν(x)≥q }.\inf\{\, x \in \mathbb{R} : F_\nu(x) \ge q \,\}.inf{x∈R:Fν​(x)≥q}.
  • FνF_\nuFν​ is the library's cumulative distribution function. It equals x↦ν((−∞,x])x \mapsto \nu((-\infty, x])x↦ν((−∞,x]) when ν\nuν is a probability measure; for other measures it is a library-defined default function rather than ν\nuν's distribution function.
  • The infimum of a real set is taken to be 000 when the set is empty or unbounded below. Hence the value is 000 when q≤0q \le 0q≤0 (the set is all of R\mathbb{R}R), when q>1q > 1q>1, and whenever the level qqq is never reached. The last case includes q=1q = 1q=1 for laws whose distribution function never attains 111.

chiSqLaw (chi-square law). For k∈Nk \in \mathbb{N}k∈N, this is the gamma law with shape k/2k/2k/2 and rate 1/21/21/2, which has density (1/2)k/2Γ(k/2)xk/2−1e−x/2\frac{(1/2)^{k/2}}{\Gamma(k/2)} x^{k/2 - 1} e^{-x/2}Γ(k/2)(1/2)k/2​xk/2−1e−x/2 for x≥0x \ge 0x≥0 and 000 for x<0x < 0x<0. For k=0k = 0k=0 the shape is 000. The library takes Γ(0)=0\Gamma(0) = 0Γ(0)=0 and division by 000 to give 000, so the density is identically zero and the result is the zero measure, not a probability measure.


stdNormal. This is the standard normal law N(0,1)N(0,1)N(0,1) on R\mathbb{R}R.


normSurv. For x∈Rx \in \mathbb{R}x∈R, the value is Φˉ(x)=1−Φ(x)\bar\Phi(x) = 1 - \Phi(x)Φˉ(x)=1−Φ(x), where Φ\PhiΦ is the cumulative distribution function of N(0,1)N(0,1)N(0,1).


fisherStat (Fisher's combination statistic). For calibration scores s∈Rns \in \mathbb{R}^ns∈Rn and test scores t∈Rmt \in \mathbb{R}^mt∈Rm, the value is

−2∑i=1mlog⁡u^(ti),u^(ti)=1+#{j:sj≤ti}n+1.-2 \sum_{i=1}^m \log \hat u(t_i), \qquad \hat u(t_i) = \frac{1 + \#\{j : s_j \le t_i\}}{n+1}.−2i=1∑m​logu^(ti​),u^(ti​)=n+11+#{j:sj​≤ti​}​.
  • Each u^(ti)\hat u(t_i)u^(ti​) lies in (0,1](0,1](0,1], so the logarithms are well defined and the statistic is always ≥0\ge 0≥0.
  • It equals 000 when m=0m = 0m=0.

condFisherRejProb (conditional rejection probability of Fisher's test). Let μ\muμ be a measure on R\mathbb{R}R (not required to be a probability measure), m∈Nm \in \mathbb{N}m∈N, α∈R\alpha \in \mathbb{R}α∈R, and s∈Rns \in \mathbb{R}^ns∈Rn. Let q=quantile(χ2m2, 1−α)q = \mathrm{quantile}(\chi^2_{2m},\, 1 - \alpha)q=quantile(χ2m2​,1−α), with the quantile and the law χ2m2\chi^2_{2m}χ2m2​ as defined above. The value is

μ⊗m({ t∈Rm:q≤−2∑i=1mlog⁡u^(ti) }),\mu^{\otimes m}\Big(\Big\{\, t \in \mathbb{R}^m : q \le -2 \sum_{i=1}^m \log \hat u(t_i) \,\Big\}\Big),μ⊗m({t∈Rm:q≤−2i=1∑m​logu^(ti​)}),

converted to a real number, and 000 if this measure is infinite. Edge cases:

  • α≥1\alpha \ge 1α≥1. Then 1−α≤01 - \alpha \le 01−α≤0, so q=0q = 0q=0 and the event is all of Rm\mathbb{R}^mRm, because the statistic is always ≥0\ge 0≥0.
  • α≤0\alpha \le 0α≤0. Then 1−α≥11 - \alpha \ge 11−α≥1. For m≥1m \ge 1m≥1 the chi-square distribution function never reaches 111, so again q=0q = 0q=0 and the event is all of Rm\mathbb{R}^mRm.
  • m=0m = 0m=0. The chi-square law is the zero measure and the statistic is 000, so the value is 111 if q≤0q \le 0q≤0 and 000 otherwise.

corr (correlation). Let (Ω,P)(\Omega, P)(Ω,P) be a measurable space with an arbitrary measure PPP, and let X,Y:Ω→RX, Y : \Omega \to \mathbb{R}X,Y:Ω→R. The value is

CovP[X,Y]VarP[X] VarP[Y].\frac{\mathrm{Cov}_P[X, Y]}{\sqrt{\mathrm{Var}_P[X]\,\mathrm{Var}_P[Y]}}.VarP​[X]VarP​[Y]​CovP​[X,Y]​.
  • Covariance and variance are the library's integral-based notions, centred at ∫X dP\int X\,dP∫XdP and ∫Y dP\int Y\,dP∫YdP.
  • Any integral of a non-integrable function is taken to be 000, and an infinite variance is converted to 000.
  • If either variance is 000 (including these junk cases), the denominator is 000 and the value is defined to be 000.
  • PPP is not required to be a probability measure.
Human review
  • Endorsed by Shuze Chen · Nov 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me