Repository navigation
New cluster test API - #12663
New cluster test API#12663
Conversation
drammock
left a comment
There was a problem hiding this comment.
just a few comments to get you rolling. Maybe ping us when the formulaic bit is added? (or sooner if you have any questions in the meantime, of course!)
|
This might be related: |
|
I think it is a great idea to revamp the current cluster permutation test API 🚀! Could you please share the reasoning behind choosing a pandas DataFrame as the container for evokeds and related meta info? If possible, I'd try to avoid using pandas (an optional dependency) when something similar could be achieved using, for example, a simple dictionary. |
But this doesn't need to be user-facing, then, no? Just trying to understand. If a user passes in a list of TypedDicts or Dataclasses, you can internally create the DataFrames that need to be passed to formulaic. The user would then also get tab-completion assistance in their editor. But it's just a thought. Great work so far in any case! |
This would still require pandas to be available though. |
Sure |
For context, this is step 1 of a GSoC project. A later step involves (probably) creating helper functions that will create the necessary DataFrame for the user. That's not done here because:
|
|
@CarinaFo I pushed a commit to add the dataset and add If you look at the CI runs, you can see that CircleCI, which builds modified examples/tutorials in PRs, hit an error up on 9c8ec90: Then I pushed a little commit to fix that in 47363b5, and now it hits a different error (which replicates what I saw locally when I tried to run the example): It would be good to keep CircleCI green at least so we can see renderings of the tutorial with each push. If you make sure |
|
I rewrote the tutorial and I think I found another improvement/feature we should probably implement. In the tutorial, the reference used by the cluster test by default was non-target, so the t-values were negative. In the example plot, we visualised the evoked difference by setting target - non-target contrast. I think for the user the cluster t-values might be confusing/misinterpreted. I need to verify, but I guess cluster_test sorts the contrast alphabetically by default. The cluster_test function does return the reference (which is great), but we should allow the user to change the reference or at least document the default behaviour? I also noticed that cluster_result.n_permutations gives the wrong number of permutations (1024) even though the test runs an exact test here (15 permutations). But I think this should be a separate PR. Let me know what you think @scott-huberty (again, great work, the API is already so much better). Update: The merge conflict is from a recent PR that fixes TFCE (#14286), maybe good to keep that PR in mind before finalising the new cluster test API |
…aired tests/clean up list to array conversion
|
Sounds like all that might now be needed to merge is to address the docstring issue, fix a merge conflict, and maybe the n_permutations bug, leaving the condition order/sign to another PR. (Though one easy change would be to keep the original order first seen, so if A comes before B then the contrast is A-B, if B before A then B-A. I might try this to see how easy it is.) Okay for me to do these last fix ups and merge @scott-huberty @wmvanvliet @CarinaFo ? |
* upstream/main: (91 commits) Fix static doc viewing in IDEs (mne-tools#14195) Fix COLA for odd sizes (mne-tools#14312) add type hints to mne/_fiff/ module (mne-tools#14278) ENH: wire the JupyterLite build into the docs (JupyterLite split 5/5) (mne-tools#14157) MAINT: Update pre-commit hook versions (mne-tools#14306) Small documentation fix for "Frequency and time-frequency sensor analysis" tutorial (mne-tools#14304) FIX: don't mutate cached ICA sources in plot_sources properties (mne-tools#14303) Fix bug with lite backend closing (mne-tools#14302) Fix for NumPy eig change [circle deploy] (mne-tools#14300) No PyQt5 [circle deploy] [skip azp] [skip actions] ENH: add the JupyterLite notebook setup cell (JupyterLite split 4/5) (mne-tools#14150) FIX: Ver [circle deploy] [skip azp] [skip actions] Hotfix fix EDF round-trip (mne-tools#14296) Brain GUI modernization (Phase 7) (mne-tools#14270) Fix bug with SciPy 1.18.0 EEGLAB reading (mne-tools#14293) remove plotting abs as the defauls for plotting volumetric (mne-tools#13989) Coregistration GUI modernisation (phase 4) (mne-tools#14285) Dipole GUI interactivity and visual enhancements (phase 2) (mne-tools#14291) Width [circle deploy] [skip azp] [skip actions] ...
Checked and all comments have been addressed!
drammock
left a comment
There was a problem hiding this comment.
just a small suggestion to interleave the code + text a bit more in the tutorial.
| # The smallest cluster p-value is about 0.06, so no cluster is significant at | ||
| # alpha = 0.05 -- and with five subjects none ever could be. Here is why. | ||
| # | ||
| # The null distribution is built by sign-flipping the five per-subject | ||
| # difference scores. There are ``2 ** 5 = 32`` ways to assign signs, but | ||
| # flipping every sign only mirrors the partition, so just ``2 ** (5 - 1) = 16`` | ||
| # are distinct. Because the test is exact, all 16 are evaluated rather than | ||
| # sampled at random -- which is why ``cluster_result.n_permutations`` below | ||
| # reports 16 rather than the 1024 requested by default. Fifteen of those are | ||
| # surrogates (you will see ``15/15`` in the progress log); the sixteenth is the | ||
| # arrangement actually observed. | ||
| # | ||
| # The finest p-value this can resolve is therefore ``1 / 16 = 0.0625``, so even the | ||
| # most extreme possible cluster lands just above 0.05. The near-0.0625 result | ||
| # means the observed cluster *was* the most extreme one -- there is simply not | ||
| # enough data to reach significance. Detecting an effect here would need more | ||
| # subjects; that, not the specific p-value, is the takeaway. |
| vlim = np.abs(stat_obs).max() | ||
|
|
||
| fig, ax = plt.subplots(layout="constrained") | ||
| im = ax.imshow( |
There was a problem hiding this comment.
I think this is fine for now, but a better visualization might be to create an EvokedArray from the stat_obs and plot t-value as a function of time for each sensor, visualized as a joint plot (so you see topomaps at times where the t-vals are high across channels). With a heatmap, the neighbor relationships across channels get obscured/lost.
Co-authored-by: Daniel McCloy <[email protected]>
|
congrats! This is amazing! 🎉 |
set up new cluster_test api that sets up design matrix based on Wilkinson formula (using formulaic package)