[Eeglablist] ICA component variance explained

Bruzadin Nunes, Ugo ugob at siu.edu
Tue Sep 17 20:35:13 PDT 2019


I was looking for the answer to your question on EEGLAB listserv from March 2019 and found out that the answer was a little more complicated that find "just a variable". I don't know how to respond to an old list-serv email, so I'm sorry if this is the wrong way.

In any case, I wrote/modified the code from pop_prop_extended() from viewprop. You can copy and paste this snip within a code of your own in a pipeline or in a separate script  and run it once the data is loaded via EEGLAB. This code basically calculates the percentage of explained variable as it is done in IClabel and makes into a variable called finalList in order of component number. You can call that variable from a separate code then, instead of having to modify the original script (which was the thing was going to do).

I also don't know the proper etiquette for modifying people's codes, so this is my best attempt. Hope it helps!!!

%%% This code was adapted from pop_prop_extended() originally from Luca
%%% Pion-Tonachini (2017) from the EEGLAB plugin ViewProps
%%% It was snipped and modified by Ugo Bruzadin Nunes, M.A., with collaboration with Matthew Gunn at
%%% the INL lab at SIU - C to fit our pipeline purposes
% This is a GNU copyrighted content for free distribution only

temporaryList = {}
finalList = []
EEG.icaact = (EEG.icaweights*EEG.icasphere)*EEG.data(EEG.icachansind,:);

    chanorcomp = size(EEG.icaweights,1);
    for i=1:chanorcomp

        icaacttmp = EEG.icaact(i, :, :);
        maxsamp = 1e6;
        n_samp = min(maxsamp, EEG.pnts*EEG.trials);
            samp_ind = randperm(EEG.pnts*EEG.trials, n_samp);
            samp_ind = randperm(EEG.pnts*EEG.trials);
            samp_ind = samp_ind(1:n_samp);
        if ~isempty(EEG.icachansind)
            icachansind = EEG.icachansind;
            icachansind = 1:EEG.nbchan;
        datavar = mean(var(EEG.data(icachansind, samp_ind), [], 2));
        projvar = mean(var(EEG.data(icachansind, samp_ind) - ...
        EEG.icawinv(:, i) * icaacttmp(1, samp_ind), [], 2))
        pvafval = 100 *(1 - projvar/ datavar);
        pvaf = num2str(pvafval, '%3.1f')
        temporaryList = {pvaf};
        finalList = cat(1, finalList, temporaryList);
Best wishes,

Ugo Bruzadin Nunes, M.A. & Doctoral Candidate
PSYC 222 Instructor - Effects of Recreational Drugs
Brain and Cognitive Sciences Ph.D Program ||
School of Psychological and Behavioral Sciences
Southern Illinois University - Carbondale

More information about the eeglablist mailing list