ucdavis / erplab

ERPLAB Toolbox is a free, open-source Matlab package for analyzing ERP data. It is tightly integrated with EEGLAB Toolbox, extending EEGLAB’s capabilities to provide robust, industrial-strength tools for ERP processing, visualization, and analysis. A graphical user interface makes it easy for beginners to learn, and Matlab scripting provides enormous power for intermediate and advanced users.
http://erpinfo.org/erplab
261 stars 74 forks source link

'Weighted' average is not working without setting the `ExcludeNullBin' argument #151

Open filippogambarota opened 2 years ago

filippogambarota commented 2 years ago

Description

Hi! I've noticed a discrepancy between the pop_gaverager() function and the respective function with the GUI. My guess is that the Weighted argument is not working when used within a script. Given that the GUI is involved is difficult to write a complete reproducible example, my approach is the following: I've created 3 .erp files from GUI using:

Then I've created the same set but using the pop_gaverager()

Then I've compared the ERP.bindata within GUI/script and between GUI/script

This is my approach:

%% From Script

ERP_weighted = pop_gaverager(fullfile('eeg_data', 'GA', 'ga_list.txt'), 'Weighted', 'on');
ERP_unweighted_remove = pop_gaverager(fullfile('eeg_data', 'GA', 'ga_list.txt'), 'Weighted', 'off', 'ExcludeNullBin', 'on');
ERP_unweighted_noremove = pop_gaverager(fullfile('eeg_data', 'GA', 'ga_list.txt'), 'Weighted', 'off', 'ExcludeNullBin', 'off');

isequal(ERP_weighted.bindata, ERP_unweighted_remove.bindata) % equal
isequal(ERP_unweighted_remove.bindata, ERP_unweighted_noremove.bindata) % different

%% From GUI

ERP_weighted_gui = load('ga_weighted.erp', '-mat');
ERP_weighted_gui = ERP_weighted_gui.('ERP');

ERP_unweighted_remove_gui = load('ga_unweighted_remove.erp', '-mat');
ERP_unweighted_remove_gui = ERP_unweighted_remove_gui.('ERP');

ERP_unweighted_noremove_gui = load('ga_unweighted_noremove.erp', '-mat');
ERP_unweighted_noremove_gui = ERP_unweighted_noremove_gui.('ERP');

isequal(ERP_weighted_gui.bindata, ERP_unweighted_remove_gui.bindata) % different
isequal(ERP_unweighted_remove_gui.bindata, ERP_unweighted_noremove_gui.bindata) % different

%% Compare script and GUI

isequal(ERP_weighted.bindata, ERP_weighted_gui.bindata) % different
isequal(ERP_unweighted_remove.bindata, ERP_unweighted_remove_gui.bindata) % equal
isequal(ERP_unweighted_noremove.bindata, ERP_unweighted_noremove_gui.bindata) % equal

I've commented with the isequal() function result. Basically the weighted, on e off is not effective because data are the same. I've also noticed that regardless the GUI checked options, the history command is the same across examples.

Versions

OS version [Pop!_OS 21.04]
Matlab version [R2021a]
EEGLAB version [2021.1]
ERPLAB version [8.20]
filippogambarota commented 2 years ago

Thanks to @sbrigadoi now the issue is more clear. The Weighted argument from the script is effective only when ExcludeNullBin is turned off (as automatically performed in the GUI). The weighted average from GUI and ERP = pop_gaverager(ALLERP, 'Weighted', 'on', 'ExcludeNullBin', 'off') now are the same. The problem is that omitting the ExcludeNullBin while keeping the Weighted argument as on, force the classic average mode but the output message still reports a weighted average.