Principal-component correction for stratification
Residualization on a span of axes
DefinitionResidualized vector after adjustment for a subspace#✓fully proved
The adjusted (residualized) y: the residual of the least-squares regression of y on the
subspace V (y minus its orthogonal projection onto V).
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
Used by 15
TheoremResiduals lie in the orthogonal complement#✓fully proved
Residuals are orthogonal to the adjustment subspace.
theorem adjusted_mem_orthogonal (V : Submodule ℝ E) (y : E) : adjusted V y ∈ Vᗮ
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 1 · Used by 1
TheoremResiduals are orthogonal to every axis#✓fully proved
Residuals are orthogonal to every vector of the subspace, in particular to every axis.
theorem inner_adjusted_eq_zero (V : Submodule ℝ E) {v : E} (hv : v ∈ V) (y : E) :
⟪v, adjusted V y⟫_ℝ = 0
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 2
TheoremResidual as projection onto the orthogonal complement#✓fully proved
The residual is the orthogonal projection onto Vᗮ.
theorem adjusted_eq_starProjection_orthogonal (V : Submodule ℝ E) (y : E) :
adjusted V y = Vᗮ.starProjection y
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 1 · Used by 3
TheoremAdditivity of residualization#✓fully proved
Residualization is additive.
theorem adjusted_add (V : Submodule ℝ E) (y z : E) :
adjusted V (y + z) = adjusted V y + adjusted V z
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 2 · Used by 1
TheoremHomogeneity of residualization#✓fully proved
Residualization is homogeneous.
theorem adjusted_smul (V : Submodule ℝ E) (c : ℝ) (y : E) :
adjusted V (c • y) = c • adjusted V y
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 2
TheoremResidual vanishes exactly on the subspace#✓fully proved
The residual vanishes exactly on the subspace.
theorem adjusted_eq_zero_iff (V : Submodule ℝ E) (y : E) : adjusted V y = 0 ↔ y ∈ V
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 1 · Used by 2
TheoremStratification within the axis span does not change the residual#✓fully proved
Adding a vector of the subspace (stratification lying in the axis span) does not change the residual.
theorem adjusted_add_of_mem (V : Submodule ℝ E) {s : E} (hs : s ∈ V) (z : E) :
adjusted V (s + z) = adjusted V z
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 3 · Used by 1
TheoremVectors orthogonal to the subspace are their own residuals#✓fully proved
Vectors orthogonal to the subspace are their own residuals: stratification outside the axis span is not removed.
theorem adjusted_of_mem_orthogonal (V : Submodule ℝ E) {y : E} (hy : y ∈ Vᗮ) :
adjusted V y = y
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 2
TheoremResidual with respect to an orthonormal family of axes#✓fully proved
Regressing on an orthonormal family of axes one axis at a time gives the joint residual:
y - ∑ₖ ⟪aₖ, y⟫ aₖ.
theorem adjusted_span_orthonormal {K : ℕ} (a : Fin K → E) (ha : Orthonormal ℝ a) (y : E) :
adjusted (Submodule.span ℝ (Set.range a)) y = y - ∑ k, ⟪a k, y⟫_ℝ • a k
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 1
TheoremFrisch–Waugh–Lovell theorem, uniqueness#✓fully proved
Frisch–Waugh–Lovell, uniqueness: in any least-squares decomposition
y = c + β g + e with c ∈ V and e ⊥ V ⊔ span {g}, the coefficient β is the
coefficient of the regression of the residualized y on the residualized g, and the
residual e is the residual of that regression.
theorem frischWaughLovell (V : Submodule ℝ E) (y g : E) (hg : adjusted V g ≠ 0) {c : E}
(hc : c ∈ V) (β : ℝ) (he : y - c - β • g ∈ (V ⊔ Submodule.span ℝ {g})ᗮ) :
β = ⟪adjusted V g, adjusted V y⟫_ℝ / ‖adjusted V g‖ ^ 2 ∧
y - c - β • g = adjusted V y - β • adjusted V g
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 1
TheoremFrisch–Waugh–Lovell theorem, existence#✓fully proved
Frisch–Waugh–Lovell, existence: the coefficient of the residual-on-residual regression
gives a least-squares decomposition of y on V ⊔ span {g}.
theorem exists_frischWaughLovell (V : Submodule ℝ E) (y g : E) :
∃ c ∈ V, y - c - (⟪adjusted V g, adjusted V y⟫_ℝ / ‖adjusted V g‖ ^ 2) • g ∈
(V ⊔ Submodule.span ℝ {g})ᗮ
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
Uses 1
DefinitionEIGENSTRAT association statistic#✓fully proved
The EIGENSTRAT association statistic (N - K - 1) ⟪r_g, r_y⟫² / (‖r_g‖² ‖r_y‖²) of the
adjusted genotype r_g and adjusted phenotype r_y: (N - K - 1) times their squared cosine,
which is their squared sample correlation when both are centered (Price et al. 2006). When either
adjusted vector is zero the ratio is the junk value 0.
noncomputable def chiSq (V : Submodule ℝ E) (K : ℕ) (y g : E) : ℝ :=
((N : ℝ) - K - 1) * (⟪adjusted V g, adjusted V y⟫_ℝ ^ 2 /
(‖adjusted V g‖ ^ 2 * ‖adjusted V y‖ ^ 2))
noncomputable def adjusted (V : Submodule ℝ E) (y : E) : E :=
y - V.starProjection y
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:89
TheoremStratification in the axis span is removed#✓fully proved
Adding vectors of V to the phenotype and
the genotype does not change the EIGENSTRAT statistic.
theorem chiSq_add_of_mem (V : Submodule ℝ E) (K : ℕ) {s t : E} (hs : s ∈ V) (ht : t ∈ V)
(y g : E) : chiSq V K (s + y) (t + g) = chiSq V K y g
noncomputable def chiSq (V : Submodule ℝ E) (K : ℕ) (y g : E) : ℝ :=
((N : ℝ) - K - 1) * (⟪adjusted V g, adjusted V y⟫_ℝ ^ 2 /
(‖adjusted V g‖ ^ 2 * ‖adjusted V y‖ ^ 2))
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:226
TheoremNonnegativity of the EIGENSTRAT statistic#✓fully proved
The EIGENSTRAT statistic is nonnegative when K + 1 ≤ N.
theorem chiSq_nonneg (V : Submodule ℝ E) {K : ℕ} (hK : K + 1 ≤ N) (y g : E) :
0 ≤ chiSq V K y g
noncomputable def chiSq (V : Submodule ℝ E) (K : ℕ) (y g : E) : ℝ :=
((N : ℝ) - K - 1) * (⟪adjusted V g, adjusted V y⟫_ℝ ^ 2 /
(‖adjusted V g‖ ^ 2 * ‖adjusted V y‖ ^ 2))
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:226
Uses 2
TheoremGenotypes in the axis span carry no signal after adjustment#✓fully proved
A genotype lying in the axis span carries no signal after adjustment (its residual is zero,
and the statistic is the junk value 0 of the zero denominator).
theorem chiSq_of_mem (V : Submodule ℝ E) (K : ℕ) (y : E) {g : E} (hg : g ∈ V) :
chiSq V K y g = 0
noncomputable def chiSq (V : Submodule ℝ E) (K : ℕ) (y g : E) : ℝ :=
((N : ℝ) - K - 1) * (⟪adjusted V g, adjusted V y⟫_ℝ ^ 2 /
(‖adjusted V g‖ ^ 2 * ‖adjusted V y‖ ^ 2))
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:226
Uses 3
Patterson normalization and the axes of variation
DefinitionAllele-frequency estimate of a marker#✓fully proved
The allele-frequency estimate p̂ⱼ = μⱼ / 2 of marker j, where μⱼ is the mean
variant-allele count of column j (autosomal diploid data, counts in {0, 1, 2}).
noncomputable def alleleFreq (C : Matrix (Fin N) (Fin M) ℝ) (j : Fin M) : ℝ :=
colMean C j / 2
noncomputable def colMean (X : Matrix (Fin n) (Fin p) ℝ) (j : Fin p) : ℝ :=
(∑ i, X i j) / n
MathlibExt/Probability/Statistics/PCA.lean:79
Uses 1 · Used by 2
DefinitionPatterson's normalized genotype matrix#✓fully proved
Patterson's normalized genotype matrix (C i j - μⱼ) / √(p̂ⱼ (1 - p̂ⱼ)). For a
monomorphic marker (p̂ⱼ ∈ {0, 1}) the denominator is 0 and the column is the junk value 0;
Patterson et al. use polymorphic markers only.
noncomputable def normalizedGenotype (C : Matrix (Fin N) (Fin M) ℝ) : Matrix (Fin N) (Fin M) ℝ :=
Matrix.of fun i j => center C i j / √(alleleFreq C j * (1 - alleleFreq C j))
noncomputable def center (X : Matrix (Fin n) (Fin p) ℝ) : Matrix (Fin n) (Fin p) ℝ :=
Matrix.of fun i j => X i j - colMean X j
MathlibExt/Probability/Statistics/PCA.lean:83
noncomputable def alleleFreq (C : Matrix (Fin N) (Fin M) ℝ) (j : Fin M) : ℝ :=
colMean C j / 2
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:275
DefinitionPatterson's relatedness matrix#✓fully proved
Patterson's N × N matrix Ψ = M Mᵀ / (number of markers) of the normalized genotypes,
whose top eigenvectors are the axes of variation.
noncomputable def relatednessMatrix (C : Matrix (Fin N) (Fin M) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
(M : ℝ)⁻¹ • (normalizedGenotype C * (normalizedGenotype C)ᵀ)
noncomputable def normalizedGenotype (C : Matrix (Fin N) (Fin M) ℝ) : Matrix (Fin N) (Fin M) ℝ :=
Matrix.of fun i j => center C i j / √(alleleFreq C j * (1 - alleleFreq C j))
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:281
TheoremPatterson's relatedness matrix is positive semidefinite#✓fully proved
Patterson's matrix Ψ is positive semidefinite.
theorem relatednessMatrix_posSemidef (C : Matrix (Fin N) (Fin M) ℝ) :
(relatednessMatrix C).PosSemidef
noncomputable def relatednessMatrix (C : Matrix (Fin N) (Fin M) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
(M : ℝ)⁻¹ • (normalizedGenotype C * (normalizedGenotype C)ᵀ)
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:286
Uses 2 · Used by 2
TheoremAll-ones vector lies in the kernel of the relatedness matrix#✓fully proved
The all-ones vector is in the kernel of Ψ (columns of the normalized matrix are centered),
so at most N - 1 eigenvalues are nonzero.
theorem relatednessMatrix_mulVec_one (C : Matrix (Fin N) (Fin M) ℝ) (hN : 0 < N) :
relatednessMatrix C *ᵥ 1 = 0
noncomputable def relatednessMatrix (C : Matrix (Fin N) (Fin M) ℝ) : Matrix (Fin N) (Fin N) ℝ :=
(M : ℝ)⁻¹ • (normalizedGenotype C * (normalizedGenotype C)ᵀ)
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:286
Uses 5
DefinitionAxes of variation#✓fully proved
The axes of variation: an orthonormal eigenbasis of Ψ, in decreasing eigenvalue order.
noncomputable def axes (C : Matrix (Fin N) (Fin M) ℝ) :
OrthonormalBasis (Fin N) ℝ (EuclideanSpace ℝ (Fin N)) :=
orderedEigenbasis (relatednessMatrix_posSemidef C).isHermitian
noncomputable def orderedEigenbasis (hS : S.IsHermitian) :
OrthonormalBasis (Fin p) ℝ (EuclideanSpace ℝ (Fin p)) :=
(isSymmetric_toEuclideanLin_iff.mpr hS).eigenvectorBasis finrank_euclideanSpace_fin
MathlibExt/Probability/Statistics/PCA.lean:171
theorem relatednessMatrix_posSemidef (C : Matrix (Fin N) (Fin M) ℝ) :
(relatednessMatrix C).PosSemidef
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:290
Uses 3 · Used by 3
DefinitionEigenvalues of the axes of variation#✓fully proved
The eigenvalues of Ψ in decreasing order, matching axes.
noncomputable def axisEigenvalues (C : Matrix (Fin N) (Fin M) ℝ) : Fin N → ℝ :=
orderedEigenvalues (relatednessMatrix_posSemidef C).isHermitian
noncomputable def orderedEigenvalues (hS : S.IsHermitian) : Fin p → ℝ :=
(isSymmetric_toEuclideanLin_iff.mpr hS).eigenvalues finrank_euclideanSpace_fin
MathlibExt/Probability/Statistics/PCA.lean:166
theorem relatednessMatrix_posSemidef (C : Matrix (Fin N) (Fin M) ℝ) :
(relatednessMatrix C).PosSemidef
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:290
DefinitionSpan of the top axes of variation#✓fully proved
The span of the top K axes of variation, the subspace EIGENSTRAT adjusts for.
noncomputable def topAxesSpan (C : Matrix (Fin N) (Fin M) ℝ) (K : ℕ) :
Submodule ℝ (EuclideanSpace ℝ (Fin N)) :=
Submodule.span ℝ (axes C '' {i | i.val < K})
noncomputable def axes (C : Matrix (Fin N) (Fin M) ℝ) :
OrthonormalBasis (Fin N) ℝ (EuclideanSpace ℝ (Fin N)) :=
orderedEigenbasis (relatednessMatrix_posSemidef C).isHermitian
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:308
Uses 1 · Used by 2
TheoremEach top axis lies in the span of the top axes#✓fully proved
Each of the top K axes lies in their span.
theorem axes_mem_topAxesSpan (C : Matrix (Fin N) (Fin M) ℝ) {K : ℕ} {i : Fin N} (hi : i.val < K) :
axes C i ∈ topAxesSpan C K
noncomputable def axes (C : Matrix (Fin N) (Fin M) ℝ) :
OrthonormalBasis (Fin N) ℝ (EuclideanSpace ℝ (Fin N)) :=
orderedEigenbasis (relatednessMatrix_posSemidef C).isHermitian
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:308
noncomputable def topAxesSpan (C : Matrix (Fin N) (Fin M) ℝ) (K : ℕ) :
Submodule ℝ (EuclideanSpace ℝ (Fin N)) :=
Submodule.span ℝ (axes C '' {i | i.val < K})
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:317
Uses 2
TheoremDimension of the span of the top axes#✓fully proved
The top K axes span a K-dimensional subspace.
theorem finrank_topAxesSpan (C : Matrix (Fin N) (Fin M) ℝ) {K : ℕ} (hK : K ≤ N) :
Module.finrank ℝ (topAxesSpan C K) = K
noncomputable def topAxesSpan (C : Matrix (Fin N) (Fin M) ℝ) (K : ℕ) :
Submodule ℝ (EuclideanSpace ℝ (Fin N)) :=
Submodule.span ℝ (axes C '' {i | i.val < K})
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:317
Uses 2
Number of significant axes
DefinitionSequential count of significant axes#✓fully proved
Patterson's sequential count of significant axes: among the first K statistics, the
length of the leading run of statistics exceeding the threshold t (testing stops at the first
non-significant one).
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
Used by 7
TheoremAt most K axes are declared significant#✓fully proved
At most K axes are declared significant.
theorem numSignificant_le (stat : ℕ → ℝ) (t : ℝ) (K : ℕ) : numSignificant stat t K ≤ K
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:359
Uses 1 · Used by 1
TheoremCharacterization of the axes counted as significant#✓fully proved
The first numSignificant stat t K indices are exactly those k < K whose statistics and
all earlier ones exceed the threshold.
theorem lt_numSignificant_iff {stat : ℕ → ℝ} {t : ℝ} {K k : ℕ} :
k < numSignificant stat t K ↔ k < K ∧ ∀ i ≤ k, t < stat i
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:359
Uses 2 · Used by 4
TheoremSignificant axes have statistics above the threshold#✓fully proved
Every axis counted as significant has a statistic above the threshold.
theorem lt_stat_of_lt_numSignificant {stat : ℕ → ℝ} {t : ℝ} {K k : ℕ}
(h : k < numSignificant stat t K) : t < stat k
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:359
Uses 2 · Used by 1
TheoremCriterion for at least one significant axis#✓fully proved
At least one axis is significant iff the leading statistic exceeds the threshold.
theorem numSignificant_pos_iff {stat : ℕ → ℝ} {t : ℝ} {K : ℕ} :
0 < numSignificant stat t K ↔ 0 < K ∧ t < stat 0
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:359
Uses 2
TheoremCount of significant axes decreases with the threshold#✓fully proved
A higher threshold declares no more axes significant.
theorem numSignificant_antitone {stat : ℕ → ℝ} {t t' : ℝ} (htt : t ≤ t') (K : ℕ) :
numSignificant stat t' K ≤ numSignificant stat t K
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:359
Uses 2
TheoremSignificant-axis count for decreasing statistics#✓fully proved
For decreasing statistics (such as ordered eigenvalues compared with a fixed threshold) the sequential count is the number of statistics above the threshold.
theorem numSignificant_eq_card_of_antitone {stat : ℕ → ℝ} (h : Antitone stat) (t : ℝ) (K : ℕ) :
numSignificant stat t K = ((Finset.range K).filter fun k => t < stat k).card
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:359
Uses 2
TheoremConditional error bound#✓fully proved
If, under the null hypothesis, the k-th statistic exceeds t
with probability at most 1 - F t (the Tracy–Widom approximation with F the TW₁ distribution
function, taken here as a hypothesis), then the rule declares more than k significant axes with
probability at most 1 - F t.
theorem measure_lt_numSignificant_le {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)
(stat : Ω → ℕ → ℝ) (F : ℝ → ℝ) (t : ℝ) (K k : ℕ)
(hnull : P {ω | t < stat ω k} ≤ ENNReal.ofReal (1 - F t)) :
P {ω | k < numSignificant (stat ω) t K} ≤ ENNReal.ofReal (1 - F t)
noncomputable def numSignificant (stat : ℕ → ℝ) (t : ℝ) : ℕ → ℕ
| 0 => 0
| K + 1 => open Classical in
if numSignificant stat t K = K ∧ t < stat K then K + 1 else numSignificant stat t K
MathlibExt/Biology/StatisticalGenetics/Eigenstrat.lean:359
Uses 2
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.