LIMO-EEG-Toolbox / limo_tools

Hierarchical Linear Modelling for MEEG data
https://limo-eeg-toolbox.github.io/limo_meeg/
Other
58 stars 28 forks source link

Cluster correction for one-sample t-test throws error when provided with toolbox-default number of bootstraps (1) #189

Closed Bysmuth closed 2 months ago

Bysmuth commented 5 months ago

Describe the bug When using the GUI to perform cluster correction for a one-sample t-test, the parfor loop over boot from 1:nboot throws an error when boot > 1. I believe this is because LIMO.design.bootstrap was set to 1 (by toolbox defaults, not by me), leading to unexpected behavior.

I am using v4.0 of the LIMO toolbox, recently downloaded through EEGLAB v2023.1 via "Manage EEGLAB extensions". I have made a few customizations to my copy of the toolbox, described briefly in the "Experimental/study context" section, though I don't believe they are relevant here. All line numbers below reference the code in original v4.0 files (without my modifications).


To Reproduce Steps to reproduce the behavior:

Using the GUI:

limo_eeg Button: Random effects Button: One Sample t-test     Default options:         Compute param. stat. (mandatory) -- Checked         Precompute bootstrap -- Unchecked     Chanlocs found, parameter number 1

limo_eeg Button: View results Button: Image all     Default options:         P value: 0.05         MC Correction: None         Compute Bootstraps: Unchecked         Compute TFCE: Unchecked     Button: Level 2     .mat file selected: one_sample_ttest_parameter_1.mat --> Opens Figure window

Within Figure window:     Drop-down menu: Cluster correction

After displaying the text in the command window "Getting clusters under H0 boot, please wait...", this throws an error via a dialog box called "cluster correction failure" which says "error log: Index in position 3 exceeds array bounds (must not exceed 1)."


Cause of the error After some investigation, I believe this error is due to the following:

During the above steps, limo_display_results.m line 117 is executed:

LIMO.design.bootstrap = 1;

This appears to be a binary variable at this point. Depending on the analysis that is run, this may later be set to a larger value -- but not always.

When it remains 1, then at the time the H0 table is created with dimensions [chans x time x bootstraps], in practice it has dims [chans x time x 1]. MATLAB treats this as a 2-dimensional array with dims [chans x time]. As a result, line 51 of limo_clustering.m behaves in an unexpected way:

nboot = size(bootM,length(size(bootM)));

Because MATLAB thinks bootM only has 2 dimensions (not 3), nboot gets set not to 1, but to the length of the time dimension. Then, in the parfor loop iterating over boot from 1:nboot, the code fails because bootP(:,:,boot) does not resolve when boot > 1.


Potential solution In my own version of the toolbox, I have modified limo_display_results.m by setting LIMO.design.bootstrap to 1000 (and then saving the LIMO file) in the conditional that checks whether the filename contains "one_sample" or "two_samples" or "paired_samples"/etc. This seems to behave as expected. It appears that some solution like this may also be necessary for other tests, but I haven't yet tested those.


Experimental/study context When I performed Batch Import (which was done using code and not the GUI), I had LIMO.design.bootstrap set to 0. I think that only affects Level 1 behavior, but I'm mentioning it here in case that's important.

I have made a number of other customizations to the LIMO toolbox files on my computer to accommodate my workflow – making it easier to use LIMO functions without using EEGLAB's STUDY functionality, permitting modification of default GLM subfolder names, etc. Prior to encountering this error, however, none of my modifications involved the bootstrapping or clustering functions.

CPernet commented 5 months ago

do not use v4 from EEGLAB, as you can see in the repo stable/main is 3.4 ; if you want v4, take it from here and let me know how this goes

Bysmuth commented 5 months ago

Thanks; unfortunately, I didn't notice that until I came to GitHub to file this. :) There's no particular need for me to use v4; that's just what it downloaded when I decided that enough time had passed that I should probably update the toolbox. But I'll do as you suggest and report back.

Bysmuth commented 5 months ago

I just confirmed that the same workflow and data with v3.4 (downloaded from GitHub) work fine.

I also downloaded v4 from GitHub, but when I click the Image All button, I encounter the following error:

Execution of script limo_display_image as a function is not supported: /Library/MathWorks/MATLAB/eeglab2023.1_LIMOv4.0_master/plugins/LIMO4.0/limo_display_image.m

It looks to me like the file limo_display_image.m has been replaced by something else entirely. I'd be happy to re-test once that is fixed.

CPernet commented 5 months ago

yeh I am going to revert it -- arnaud tried something entry new but this breaks everyting