question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Working with rank-deficient EEGLAB data

See original GitHub issue

So a colleague of mine was handed a set of files that had been pre-processed in EEGLAB. The data was read via mne.read_epochs_eeglab(). When computing the noise covariance via mne.compute_covariance() and visualizing the results via Covariance.plot(), we noticed that the data looked a bit odd. Turns out that during preprocessing, artifact rejection via ICA had been carried out, and some ICs had been removed. So the data was now rank-deficient. However, MNE didn’t “pick this up” – in fact, mne.compute_rank() assumed the rank was full even with rank=None to force an actual estimation. And according to raw.info, obviously, the rank was full as well.

So I’m wondering how to best deal with this now. We could certainly pass rank=dict(eeg=true_rank) to all functions that require a rank input. But this seems cumbersome and error-prone, and I’m not sure if there are other places where this situation could lead to errors? I would prefer just being able to do something like, raw.rank = true_rank; or, even better, the EEGLAB import should do something of that sort. A way to detect rank deficiency after ICA is simply by checking if the number of sensors is equal to the number of ICs in the EEG structure:

data = scipy.io.loadmat('myfile.set')
n_comps, n_sensors = data['EEG']['icaweights'][0, 0].shape
if n_comps == n_sensors:
    print('Data has full rank')
else:
    print(f'Data has rank {n_comps}')

(Of course this only works if no (avg) reference has been set)

Any opinions on that?

cc @cbrnr

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:43 (43 by maintainers)

github_iconTop GitHub Comments

2reactions
agramfortcommented, May 5, 2020

what do you mean such data? EEGLAB data which contain an ICA solution?

I would suggest to people to look at their covariance

1reaction
larsonercommented, May 6, 2020

I didn’t understand how that PR could fix it until I looked back at…

EEGLAB data noise cov estimated with rank=None

… I realized that I probably misunderstood this plot. Did you have some form of regularization on (e.g., shrunk) during estimation? If so it would explain why the first shelf is only 1e-2 or so below the real data (regularization inflated the eigenvalues). Can you do the same plot of the noise covariance estimated with empirical? You will probably see a much larger shelf at 48 (at least 1e-6 below the largest eigenvalue), and hence using a rtol vs atol like in #7736 could indeed help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Eeglablist] Rank deficient data
an ICA decomposition performed on or ICA solution applied to rank deficient data can be the source of many (sometimes BIG) problems down...
Read more >
d. Indep. Comp. Analysis - EEGLAB Wiki
Issues with data rank deficiencies​​ ICA does not behave well in this (rank-deficient) case. If the rank of the data is lower than...
Read more >
How to deal with bad channels before ICA for EEG data
Hi, Wenwen. Another possibility is run PREP-pipeline which is a plug-in of EEGLAB to robust-reference your data. You can specify the rank of...
Read more >
Data pre-processing - CIMeC Wiki
It is worth remembering that in EEG data each time-point represents a ... are common operations that could make the data rank deficient....
Read more >
What is rank deficiency, and how to deal with it?
The deficiency may stem from simply too little data. In general, you cannot uniquely estimate n parameters with less than n data points....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found