[Eeglablist] WG: ICA components distorted after rereferencing, saving and reloading
Tomko Settgast
tomko.settgast at uni-wuerzburg.de
Mon Aug 4 06:30:23 PDT 2025
Hi Anna,
Thanks for the comment! 😊
And sorry for the late reply. I am currently on vacation.
I started this thread because I wanted to do exactly what you’re suggesting.
The problem arose when I used MARA to reject artifact components after ICA and before applying common average reference (CAR). In cases where MARA did NOT reject any components, I encountered a disrupted ICA after saving and reloading the dataset.
If I understood Cedric correctly, he therefore recommended changing the order: applying CAR before ICA (which apparently doesn't cause problems), and adjusting the ICA to the effective rank to avoid ghost components.
As for the initial reference channel: I don’t have one. The data was recorded using an online reference at the earlobe, and gTec does not provide access to the corresponding signal. That’s why I was asking whether I should add a zero-filled channel before applying CAR.
What I’m still unsure about is whether adjusting to the effective rank using the method proposed in the paper you mentioned already accounts for the lack of a reference channel, or if I should still manually add an empty reference channel — and if so, when exactly this should be done.
Maybe you have an idea — or maybe Cedric can weigh in on this again?
Best,
Tomko 😊
Von: Anna Bánki <anna.banki at univie.ac.at>
Gesendet: Freitag, 1. August 2025 11:49
An: Tomko Settgast <tomko.settgast at uni-wuerzburg.de>
Betreff: [EXT] Re: [Eeglablist] ICA components distorted after rereferencing, saving and reloading
Hi Tomko,
Regarding your rank definiency question, I adjusted pop_runica according to Makoto's recommendation:
https://sccn.ucsd.edu/wiki/Makoto's_preprocessing_pipeline#Adjust_data_rank_for_ICA_.2805.2F17.2F2019_updated.29
See section "adjust data rank" here, and there is also a paper from him about ghost ICAs. I work with infant and child data so I usually rereference to average after ICA to avoid introducing additional noise to the channels before ICA due to rereferencing. But I do interpolate channels before the ICA and my understanding is that adjusting this pop_runica value would then account for interpolated channels and consequent rank deficiency in the data.
Then I do rereferencing and add back the initial reference after the ICA.
So my understanding is that if you use this fix you refer to then you do not need to add a 0 channel for the original reference before the ICA but I am also interested in what Cedric says.
All the best,
Anna Banki
Best,
Anna
________________________________
From: eeglablist <eeglablist-bounces at sccn.ucsd.edu<mailto:eeglablist-bounces at sccn.ucsd.edu>> on behalf of Tomko Settgast via eeglablist <eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>>
Sent: 31 July 2025 16:07:37
To: Cedric Cannard; EEGLAB List
Subject: Re: [Eeglablist] ICA components distorted after rereferencing, saving and reloading
Dear Cedric,
I am sorry for having caused some confusion!
What I meant with "threshold" was the right part of the function you have referred to in your paper: sum(eig(cov(double(EEG.data'))) > 1e-7).
So, my question was: if I use this method to estimate and account for rank deficiencies when doing ICA, do I still need to introduce the zero-filled reference channel first, or does this approach already account for the rank-deficiencies introduced by not having a reference channel and applying CAR before ICA?
Regarding clean_rawdata: you mentioned removing channels using a lax threshold before running the cleaning step. I assumed this meant running clean_rawdata twice — once with a lax threshold to remove obviously bad channels, and then again with stricter/default settings. Is that correct? And if so, do you apply both passes of clean_rawdata in direct sequence, or do you insert ICA in between (i.e., clean_rawdata (lax), ICA, clean_rawdata ("normal"))?
Or do you use another method to detect very noisy channels prior to cleaning?
I hope this clarifies my questions a bit better.
Best,
Tomko
-----Original Message-----
From: eeglablist <eeglablist-bounces at sccn.ucsd.edu<mailto:eeglablist-bounces at sccn.ucsd.edu>> On Behalf Of Cedric Cannard via eeglablist
Sent: Thursday, July 31, 2025 8:28 AM
To: EEGLAB List <eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>>
Subject: [EXT] Re: [Eeglablist] ICA components distorted after rereferencing, saving and reloading
Hi Tomko,
> using your threshold and applying PCA reduction during ICA alone cannot account for existing rank deficiencies, correct?
So in any case, I would still need to re-introduce this zero-filled reference channel?
"threshold" referring to ASR/clean_rawdata() here? That is just to remove large artifacts before ICA.
Feeding the effective data rank to ICA ensures that it accounts for rank deficiencies in the data. For instance, if your dataset has 64 electrodes but only 60 effective dimensions (e.g., due to applying a common average reference, which reduces rank by 1, and interpolating 3 bad channels), then ICA will only attempt to extract 60 independent components instead of 64, which prevents overfitting and instability.
Using the modified CAR approach (where a simulated channel filled with zeros is appended before re-referencing) allows you to maintain full rank during average referencing. This way, you preserve the original data rank and don’t need to reintroduce the reference channel later.
Hope this helps,
Cedric Cannard
On Wednesday, July 30th, 2025 at 4:44 AM, Tomko Settgast <tomko.settgast at uni-wuerzburg.de<mailto:tomko.settgast at uni-wuerzburg.de>> wrote:
> Dear
>
> Cedric
>
>
> ,
>
> Thanks again for the super quick and helpful reply!
> And yes, of course, it makes sense to bring this back to the community.
>
> I will try to follow your recommendations.
> Just to be sure: using your threshold and applying PCA reduction during ICA alone cannot account for existing rank deficiencies, correct?
> So in any case, I would still need to re-introduce this zero-filled reference channel?
>
> Regarding your second recommendation - to clarify: Do you apply the clean_rawdata twice directly in sequence (first with a lax threshold, then with a stricter one), or do you run ICA in between, i.e., clean_rawdata (lax), ICA, clean_rawdata ("normal")?
>
> Thanks again!
>
> Best,
> Tomko 😊
>
> -----Ursprüngliche Nachricht-----
> Von: eeglablist eeglablist-bounces at sccn.ucsd.edu<mailto:eeglablist-bounces at sccn.ucsd.edu> Im Auftrag von Cedric
> Cannard via eeglablist
>
> Gesendet: Dienstag, 29. Juli 2025 23:01
> An: EEGLAB List eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>
>
> Betreff: [EXT] Re: [Eeglablist] ICA components distorted after
> rereferencing, saving and reloading
>
> Dear Tomko,
>
> Getting this thread back in the eeglablist loop in case it is helpful to more people later.
>
> Yes, apply the modified CAR method (zero-filled channel) to preserve effective data rank before ICA:
>
> % 1) Add a zero-filled surrogate for the initial reference refLabel =
> 'initialReference'; EEG.data(end+1, :) = 0; EEG.nbchan = EEG.nbchan +
> 1; EEG.chanlocs(end+1).labels = refLabel; % minimal fields are fine
> for pop_reref
>
> % 2) Re-reference to average including the zero-filled reference % use 'refloc' input to explicitly tell EEGLAB that you are referencing to a virtual reference with the label 'initialReference'. EEGLAB stores this information in EEG.ref and internally handles bookkeeping better for projection matrices, reversing the reference or re-referencing later.
> EEG = pop_reref(EEG, [], 'refloc', struct('labels', refLabel));
>
> % 3) Remove the zero-filled channel to return to the original channel
> count EEG = pop_select(EEG, 'nochannel', {refLabel});
>
>
> Note: when I can, I generally run clean_rawdata/ASR right after removing bad channels with a very lax threshold (e.g. 60-100 depending on data) to remove large artifacts before ICA to improve performance. More aggressive thresholds can remove eye blinks or alpha waves depending on your data quality, which would then reduce ICA performance at extracting ocular components (you want to preserve the eye activity to separate it more successfully).
>
>
> Cedric
>
>
>
> On Saturday, July 26th, 2025 at 4:07 AM, Tomko Settgast tomko.settgast at uni-wuerzburg.de<mailto:tomko.settgast at uni-wuerzburg.de> wrote:
>
> > Dear Dr. Cannard,
> >
> > Thank you very much for the quick and helpful response!
> >
> > As far as I recall your paper, I also do not remember you recommending re-referencing after ICA.
> > I was trying to follow both the guidelines you provided in your paper, and the recommendation from the EEGLab tutorial.
> > That is what me lead to this hybrid approach.
> > But knowing that the recommendation in EEGLab might be incorrect actually simplifies things for me because I did not observe any problems when applying CAR before ICA.
> > What may have added to my confusion - making the recommendation in the tutorial plausible - was that some pipelines may indeed appear to apply CAR after ICA (e.g., EPOS: https://urldefense.com/v3/__https://www.frontiersin.org/journals/neuroscience/articles/10.3389/fnins.2021.660449/full*h4__;Iw!!Mih3wA!GU-3iC3bMIbuyzXxfHhwMjWvX_aw0Qc2OYibKegEIojxdaSycLRawNNpcStKWPGQT6A1y0gonLnCTlzxbuFdoHs42g$<https://urldefense.com/v3/__https:/www.frontiersin.org/journals/neuroscience/articles/10.3389/fnins.2021.660449/full*h4__;Iw!!Mih3wA!GU-3iC3bMIbuyzXxfHhwMjWvX_aw0Qc2OYibKegEIojxdaSycLRawNNpcStKWPGQT6A1y0gonLnCTlzxbuFdoHs42g$> , or HAPPE: https://urldefense.com/v3/__https://www.frontiersin.org/journals/neuroscience/articles/10.3389/fnins.2018.00097/full*h5__;Iw!!Mih3wA!GU-3iC3bMIbuyzXxfHhwMjWvX_aw0Qc2OYibKegEIojxdaSycLRawNNpcStKWPGQT6A1y0gonLnCTlzxbuGqsNTIrA$<https://urldefense.com/v3/__https:/www.frontiersin.org/journals/neuroscience/articles/10.3389/fnins.2018.00097/full*h5__;Iw!!Mih3wA!GU-3iC3bMIbuyzXxfHhwMjWvX_aw0Qc2OYibKegEIojxdaSycLRawNNpcStKWPGQT6A1y0gonLnCTlzxbuGqsNTIrA$> ).
> > However, I don't know their implementations in detail, and they might have already accounted for occurring issues.
> >
> > I especially want to thank you for the detailed explanation regarding why saving and reloading seemingly corrupts the ICA.
> > That was the thing that puzzled me the most and they way you have explained it made immediate sense.
> >
> > Just to confirm: If I understood you correctly, you would recommend the following order: Delete heavily noisy or flat channels (I am using clean_artifcacts), interpolate these channels, apply CAR, run ICA, correct?
> >
> > One additional question regarding the rank-deficiency issues in ICA:
> > My datasets do not include a reference channel and were recorded with a unipolar reference (ear lobe/CZ).
> > In Makoto's pipeline, if I understood it correctly, it is suggested to add zero-filled channel to account for the effective rank-deficiency when no reference channel is present.
> > Now, if I follow your recommendations, i.e., computing the approximate true rank with the formula you provided - do you think this is already sufficient, or would you still recommend adding a zero-only channel to my data?
> >
> > Thank you again for you time and the guidance!
> >
> > Best,
> > Tomko
> >
> > -----Ursprüngliche Nachricht-----
> > Von: eeglablist eeglablist-bounces at sccn.ucsd.edu<mailto:eeglablist-bounces at sccn.ucsd.edu> Im Auftrag von
> >
> > Cedric
> >
> > Cannard via eeglablist
> >
> > Gesendet: Freitag, 25. Juli 2025 19:59
> > An: EEGLAB List eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>
> >
> > Betreff: [EXT] Re: [Eeglablist] ICA components distorted after
> > rereferencing, saving and reloading
> >
> > Hi Tomko,
> >
> > There may be an error in the tutorial web page. Makoto, Scott, or Arno, please correct me if I'm wrong here.
> >
> > If I recall correctly, we do not recommend in the paper to re-reference after ICA. Instead, we emphasize correcting the average referencing before ICA and taking the data rank into account while computing ICA, so that ICA operates on a properly rank-full dataset and avoids generating "ghost ICs".
> >
> > see these quotes:
> > "To avoid this issue, we propose two solutions: 1) apply the correct average referencing, and 2) calculate the effective data rank that is used for PCA dimension reduction in applying ICA."
> > "The correct method, i.e., including the initial reference when re-referencing and then discarding the initial reference channel, resulted in a successful rank-full decomposition."
> >
> > Now to address your questions more directly:
> >
> > EEGLAB stores the ICA decomposition using:
> > - EEG.icaweights and EEG.icasphere: together they define the
> > unmixing matrix,
> > - EEG.icawinv: the mixing matrix (inverse of the unmixing matrix),
> > - EEG.data: the referenced data ICA was trained on.
> > When you apply pop_reref(EEG, []) after ICA, it modifies EEG.data, but does not update the ICA weights or sphere, nor does it recompute EEG.icaact if it exists. So now the ICA decomposition no longer corresponds to the modified data (that is if operations were done between your last referencing and post-ICA referencing). If you save the set like this, ICA reconstruction is no longer valid when reloading.
> > --> This is why the ICs appear corrupted after reloading — the weights are applied to differently referenced data than they were trained on.
> >
> > Why does the issue only happen when MARA doesn’t reject any components? I haven't used MARA before, but my guess is that when MARA rejects components, EEGLAB calls pop_subcomp() which updates EEG.data to reflect the projection of the ICA decomposition with removed components. This may result in reinitializing the ICA fields in a way that masks the corruption caused by re-referencing.
> >
> > But when no components are rejected (gcompreject = 0), EEG.data is left unchanged from ICA, and then your subsequent call to pop_reref corrupts the ICA-to-data correspondence.
> >
> > > Can you confirm whether re-referencing after MARA might break the ICA structure?
> >
> > Yes.
> >
> > > Would you recommend re-referencing before ICA, especially if PCA is already used to adjust for rank deficiency?
> >
> > Yes (see above correction about the paper and recommendations). You should also interpolate bad channels before ICA (before calculating the data rank).
> >
> > > Do you have any suggestions on how to safely apply re-referencing post-ICA?
> >
> > If for some reason you must re-reference after ICA (e.g., for visualization), do one of the following:
> >
> > % Backup ICA weights before re-referencing icaweights =
> > EEG.icaweights; icasphere = EEG.icasphere;
> >
> > % Apply re-referencing (this alters EEG.data!) EEG = pop_reref(EEG,
> > []);
> >
> > % Re-apply ICA on new data manually
> > EEG.icaact = icaweights * icasphere * EEG.data;
> >
> > Cedric Cannard
> >
> > On Thursday, July 24th, 2025 at 12:47 PM, Tomko Settgast via eeglablist eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu> wrote:
> >
> > > Dear EEGLAB team,
> > >
> > > I encountered a puzzling issue while applying common average referencing (CAR) after ICA, as currently recommended in the EEGlab tutorial (https://urldefense.com/v3/__https://eeglab.org/tutorials/06_RejectArtifacts/RunICA.html*issues-with-data-rank-deficiencies__;Iw!!Mih3wA!Hy4Uj5ky7Dr8niY5yJBllkYbV8sC-8D2mnYBuaJiqvb2aYgEkuwDK9M_9PyFCOjmtEKMU505X4gXGbOKz39zcB4VawTXegSozL76zYdG$<https://urldefense.com/v3/__https:/eeglab.org/tutorials/06_RejectArtifacts/RunICA.html*issues-with-data-rank-deficiencies__;Iw!!Mih3wA!Hy4Uj5ky7Dr8niY5yJBllkYbV8sC-8D2mnYBuaJiqvb2aYgEkuwDK9M_9PyFCOjmtEKMU505X4gXGbOKz39zcB4VawTXegSozL76zYdG$> ) to address rank deficiencies.
> > >
> > > In one specific dataset, ICA components appear strongly corrupted after saving and reloading the dataset, although they looked perfectly normal before saving. This issue does not occur in other datasets processed by the same automated pipeline.
> > >
> > > Steps to reproduce:
> > >
> > > 1. Run runica and perform MARA artifact rejection.
> > > 2. Apply CAR using pop_reref(EEG, []) after ICA (as recommended).
> > > * The components looked completely normal at this point (see
> > > attached
> > > ICsBeforeSaving.gif) 3. Save the dataset using pop_saveset.
> > > 4. Close EEGLAB, reload the dataset, and inspect ICA components with pop_eegplot .
> > > * After reloading, the ICA time series look heavily distorted (see
> > > attached ICsAfterReload.gif)
> > >
> > > To investigate further, I saved the EEG structure as .mat immediately before saving with pop_saveset and compared it with the EEG structure after reloading the saved dataset.
> > > There are mismatches between the ICA matrices in these two structures - which aligns with the visual differences in the component time series.
> > >
> > > For a better understanding:
> > >
> > > * MARA did not reject components for this dataset (0 entries in gcompreject).
> > > * The ICA was computed with proper PCA reduction to the data rank (rank = 10), following the recommendations in Kim et al. (2023) (https://urldefense.com/v3/__https://doi.org/10.3389/frsip.2023.1064138__;!!Mih3wA!Hy4Uj5ky7Dr8niY5yJBllkYbV8sC-8D2mnYBuaJiqvb2aYgEkuwDK9M_9PyFCOjmtEKMU505X4gXGbOKz39zcB4VawTXegSozNk76r1m$<https://urldefense.com/v3/__https:/doi.org/10.3389/frsip.2023.1064138__;!!Mih3wA!Hy4Uj5ky7Dr8niY5yJBllkYbV8sC-8D2mnYBuaJiqvb2aYgEkuwDK9M_9PyFCOjmtEKMU505X4gXGbOKz39zcB4VawTXegSozNk76r1m$> ), so ghost components are unlikely.
> > > * I am aware that common average re-referencing is commonly not
> > > recommended for datasets with a low number of channels but we were
> > > trying to follow the guidelines expressed by Hu et al. (2018;
> > > 10.1088/1741-2552/aaa13f)
> > > * The issue seems to occur only in this particular dataset - as far as I can trust my visual comparison.
> > > In other datasets where MARA rejected components, I did not encounter this behavior (again, only checked visually) - even though the same pipeline and re-referencing strategy was applied.
> > >
> > > After discussing the issue with ChatGPT, the suggestion came up that applying re-referencing after ICA might silently disrupt the ICA-to-data mapping, and this mismatch only becomes apparent after saving and reloading the dataset.
> > >
> > > However, what I find particularly confusing is that this issue only occurs when MARA does not reject any components - which would normally indicate better signal quality.
> > >
> > > My questions:
> > >
> > > * Can you confirm whether re-referencing after MARA-based component rejection might break the ICA structure in this way?
> > > * Is this a known issue with pop_reref in combination with ICA, and MARA?
> > > * Would you recommend re-referencing before ICA, especially if PCA is already used to adjust for rank deficiency?
> > > * Do you have any suggestions on how to safely apply re-referencing post-ICA without compromising the ICA decomposition?
> > >
> > > I'd be happy to share the script or provide further information if helpful.
> > >
> > > Thank you very much in advance for your time and support!
> > >
> > > Best regards,
> > > Tomko
> > >
> > > Tomko Settgast, MSc
> > > Section Intervention Psychology
> > > University of Würzburg
> > >
> > > _______________________________________________
> > > To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu<mailto:eeglablist-unsubscribe at sccn.ucsd.edu> or visit https://sccn.ucsd.edu/mailman/listinfo/eeglablist .
> >
> > _______________________________________________
> > To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu<mailto:eeglablist-unsubscribe at sccn.ucsd.edu> or visit https://sccn.ucsd.edu/mailman/listinfo/eeglablist .
>
> _______________________________________________
> To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu<mailto:eeglablist-unsubscribe at sccn.ucsd.edu> or visit https://sccn.ucsd.edu/mailman/listinfo/eeglablist .
_______________________________________________
To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu<mailto:eeglablist-unsubscribe at sccn.ucsd.edu> or visit https://sccn.ucsd.edu/mailman/listinfo/eeglablist .
_______________________________________________
To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu<mailto:eeglablist-unsubscribe at sccn.ucsd.edu> or visit https://sccn.ucsd.edu/mailman/listinfo/eeglablist .
More information about the eeglablist
mailing list