# Understanding rank deficiencies in covariance estimation

**URL:** <https://mne.discourse.group/t/understanding-rank-deficiencies-in-covariance-estimation/3190>\
**Category:** Support & Discussions\
**Tags:** ﻿source-localization, preprocessing\
**Created:** [May 31, 2021, 3:55pm UTC](https://mne.discourse.group/t/understanding-rank-deficiencies-in-covariance-estimation/3190 "2021-05-31T15:55:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grahamflick](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/grahamflick/32/393_2.png) [@grahamflick](https://mne.discourse.group/u/grahamflick)\
**Post date:** [May 31, 2021, 3:55pm UTC](https://mne.discourse.group/t/understanding-rank-deficiencies-in-covariance-estimation/3190/1 "2021-05-31T15:55:55Z")

</div>

Hi all,

Following up on a discussion from office hours last week… I’m hoping someone can confirm/clarify my understanding of how MNE-python handles rank deficiencies in (MEG) covariance estimation for minimum-norm estimates, when using the default `rank = None` in `mne.compute_covariance`. This is what I understand from looking at `_compute_covariance_auto` and `_smart_eigh` in `mne.cov`:

If the data matrix (X) used to estimate `cov` is rank deficient, then `_smart_eigh` will eigendecompose the matrix XTX and get projections to a subspace defined by the eigenvectors with non-zero eigenvalues (this is done in `_get_ch_whitener`). The data that are to be used for estimation are then projected into this space, effectively eliminating the redundant rows in the matrix and concerns about rank deficiency. The covariance matrix which is ultimately returned is estimated in this subspace, regardless of whether or how regularization is applied, and then projected back to the original space at the end of `_compute_covariance_auto`.

Does this sound correct or have I missed something here? Thanks!

FWIW:

- MNE-Python version: 0.23.0
- operating system: macOS

The relevant part of the code: [mne-python/cov.py at maint/0.23 · mne-tools/mne-python · GitHub](https://github.com/mne-tools/mne-python/blob/maint/0.23/mne/cov.py#L1028)

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [June 16, 2021, 7:56pm UTC](https://mne.discourse.group/t/understanding-rank-deficiencies-in-covariance-estimation/3190/2 "2021-06-16T19:56:47Z")

</div>

hi

sorry for the late reply. Yes this seems about right from the top of my mind.  
To double check this put a break point in the code after the whitener is computed  
and check its shape and eigenvalues.

Alex
