# [Eeglablist] Rank before ICA

Makoto Miyakoshi mmiyakoshi at ucsd.edu
Tue Aug 24 11:10:35 PDT 2021

```Dear Eric and John,

Thanks John for pointing Eric to my Wiki pages.
Currently, Shannon and I are working on this issue specifically. Please see
https://sccn.ucsd.edu/wiki/Shannon%27s_ICA_rank_project

To include the initial reference in calculating average reference, you can
do it in the following way as well.

EEG.data = bsxfun(@minus, EEG.data, sum(EEG.data,1)/(size(EEG.data,1)+1))

I think this works regardless of 2-D or 3-D data, but haven't checked it.
Anyway, the above process simply means that you use EEG.nbchan+1 for the
denominator when calculating the average potential.

Makoto

On Tue, Aug 24, 2021 at 10:30 AM Iversen, John <jiversen at ucsd.edu> wrote:

> Eric,
>
> See
> https://sccn.ucsd.edu/wiki/Makoto's_preprocessing_pipeline#Re-reference_the_data_to_average_.2808.2F02.2F2020_Updated.29
>
>
> and
>
>
> His preprocessing page has a wealth of information.
>
> Your implementation matches Makoto's fullRankAveRef.m :
>
> % Apply average reference after adding initial reference
> EEG.nbchan = EEG.nbchan+1;
> EEG.data(end+1,:) = zeros(1, EEG.pnts);
> EEG.chanlocs(1,EEG.nbchan).labels = 'initialReference';
> EEG = pop_reref(EEG, []);
> EEG = pop_select( EEG,'nochannel',{'initialReference'});
>
>
> The only difference is you are using epoched data, while his was designed
> for continuous data. I see no functional difference between referencing
> before or after epoching, since it's done on a point-by-point basis.
>
> FYI, comments on whether to epoch before of after ICA are here:
> https://sccn.ucsd.edu/wiki/Makoto's_preprocessing_pipeline#Epoch_data_to_-1_to_2_sec_.2809.2F11.2F2019_updated.29
>
> Best,
>
> John
>
> On Aug 24, 2021, at 4:21 AM, Eric HG via eeglablist <
> eeglablist at sccn.ucsd.edu> wrote:
>
> Dear Eeglablist,
>
> I have had some troubles with the rank of the data after re-referencing to
> average.
>
> I have therefore used the following code before ICA:
>
> rank_one = rank(EEG.data(:,:));
>    EEG.nbchan = EEG.nbchan+1;
>    EEG.data(EEG.nbchan,:,:) = zeros(1, EEG.pnts, EEG.trials);
>    EEG.chanlocs(EEG.nbchan).labels = 'Ref';
>    EEG = pop_reref(EEG, []);
>    EEG = pop_select( EEG,'nochannel',{'Ref'});
>    rank_two = rank(EEG.data(:,:));
>
> Is this a feasible way to overcome this?
>
> It gives good results with ICA decomposition.
>
> Best regards,
>
> Eric
> _______________________________________________
> Eeglablist page: http://sccn.ucsd.edu/eeglab/eeglabmail.html
> To unsubscribe, send an empty email to
> eeglablist-unsubscribe at sccn.ucsd.edu
> For digest mode, send an email with the subject "set digest mime" to
> eeglablist-request at sccn.ucsd.edu
>
>
>
```