Marijn van Vliet
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # PracticalMEEG-2025 MNE-Python In this document you can write and answer questions. Use the buttons above to switch between editing or read-only modes: ![image](https://hackmd.io/_uploads/rJ0mP0nAxg.png) This document uses the markdown formatting syntax, meaning you are editing a plain text file that gets automatically converted into HTML for nicer viewing. See the toolbar (while in editing mode) for shotcuts for common formatting options: ![image](https://hackmd.io/_uploads/BkBnqChCeg.png) ### How to ask and answer a question You can ask questions by starting a bullet list. Anyone can then respond by adding a new item to the list and increasing the indentation. We respond to a response to increasing the indentation even more: - What is the best Python module for analyzing EEG and MEG data? - I believe it is MNE-Python! See here: https://mne.tools - What about FieldTrip, Brainstorm and EEGLAB? - They are great too, but they are MATLAB toolboxes, while the question was about Python. Always ask new questions at the very bottom of this document. --- **Reminder:** Most information can be found here: [https://github.com/wmvanvliet/mne_practical_meeg_2025](GitHub.com/wmvanvliet) If HackMD goes down, this will be our backup document: https://notes.coderefinery.org/HA-NqCW8T0aUTvddKzIIpA?both ## Day 1, parts 1 and 2 Moved to: https://hackmd.io/@wmvanvliet/r16gxEAReg ## Day 2, parts 1 and 2 Moved to: https://hackmd.io/@wmvanvliet/SJB3dYgybl and a tiny rest here https://hackmd.io/KUnLk4lTSrianDniCBoDVg ## Day 3: Group analysis - **Ice breaker:** How many hours of sleep did you get last night? - <4: - 4–6::red_circle: :red_circle: - 6: :red_circle: :red_circle: - 7: :red_circle: :red_circle: :red_circle: :red_circle::red_circle::red_circle: :red_circle: :red_circle: - 8: :red_circle::red_circle::red_circle::red_circle::red_circle::red_circle: - more than 8: - interpretation so far: participants are conserving energy for the social event today ## We've added some more exercises to the notebook for today. Please download the notebooks again from github: https://github.com/wmvanvliet/mne_practical_meeg_2025/archive/refs/heads/main.zip --- Session-related questions: - :white_check_mark: **Is there no outlier check?** - I think here we also assume that we did something sensible regarding outliers on the single-subject level before. - You should definitively do an outlier check! However, there's no fixed recipe to when something is an outlier, as it also heavily depends on your data. In this case we just removed subjects by eye-balling the data. As long as you report why you removed which participants in the paper and make reasonable decisions (i.e. NOT to increase an effect, i.e. p-hacking), you should be relatively fine. Best case: Define thresholds before running the analysis and preregister! - **:white_check_mark: with magnotometers subjecct 12 just seemed fine.** - yes, individual recording modalities often have specific noise, even when recorded at the same time. - **:white_check_mark: How much are we entitled to reject data "at a glance", without using any predefinded parameters for that?** - not recommended to do without any predefined criteria. But in papers you often find things like '2 participants were rejected because of excessive motion artefacts' or something similar. The criteria for this are definitely fuzzy sometimes. - Having pre-defined parameters (i.e., >X standard deviations from the mean value across all participants) is certainly good idea, especially when you pre-register your analysis pipeline. - **:white_check_mark: So the contrast suggests that the response was always greater to the famous faces than scrambled? Surely this is unlikely particularly for the early activity. Am I misunderstanding? Even for the pre stimulus.** - It's a non-zero-centered difference, in this case even strictly positive (as we squared the numbers), therefore the difference will be positive by definition - The peaks in the global field power curve suggest that stronger contrast is present around certain time points, which one might want to inspect in detail - :white_check_mark: **About outliers, is it okay to just remove a subject because his signal is above the signal of others ? He is still part of the population / representing a part of the population.** - The underlying question is: Is the signal due to natural variation of your population (or are they from a different population and just ended up by accident in yours! e.g. your participant is color blind? aphantastic? face blind? but you want to measure "healthy face perception") or is it due to artefacts or noise? This decision needs to be made informed based on these factors. Based on the research question the decision could be made differently. Usually if it's just a couple of subjects that deviate significantly and strongly, it is better to assume that they are outliers - If you will correlate the amplitude of an ERP with a behavioral variable, then such "outliers" might also strongly influence the direction and the size of the effect you observe. In this context, it is always good to keep track of the presence of such outliers in the data and double-check correlation analyses with scatter plots to see if there could be one / several points that stand out and effectively control your correlation. A transparent way to report this could be to include both versions of the same plot in your paper - with and without outliers. Then, the reader also has more information to drive their own conclusion or at least see a bigger picture. - :white_check_mark: **what are the contents of the X matrix precisely, I couldnt follow that?** - `X = np.array([contrast.data for contrast in contrast_list])` - that means, they are the concatenated data of the contrasts for all participants - X.shape = (15, 376, 241) - (n_subject, n_chs, n_time) - :white_check_mark: **Are the times of the shown topographies random? What can these specific three time point tell us?** ![image](https://hackmd.io/_uploads/rkPNOnx1be.png) - Yes you can customize them. Parameters: timesfloat | array of float | “auto” | “peaks” The time point(s) to plot. If "auto", 5 evenly spaced topographies between the first and last time instant will be shown. If "peaks", finds time points automatically by checking for 3 local maxima in Global Field Power. Defaults to "peaks". see https://mne.tools/stable/generated/mne.Evoked.html#mne.Evoked.plot_joint - :white_check_mark: **When we computed the differences between conditions (eg. famous vs unfamiliar) we plotted the data and there were 2 different lines. Since I understand we are computing ERPs, it looks like we selected a pool of electrodes or just one electrode. When did we select the electrodes?** - It was all electrodes, the global field power in the example. You can of course do this for single electrodes. - :white_check_mark: Surely the fact we've interpolated channels creates an issue with cluster based tests? - interesting question! In the best case this should not matter too much if they are in the same cluster. However, intuitively I would also assume that this could cause problems (e.g. ad absurdum: all channels are interpolated from a significant electrode, you'll find a large cluster!) - don't exactly know what is exactly the right answer, @others can we think about this a bit? - It would boost the summed t value for that cluster given you've essentially duplicated a channel, although, this would apply to both conditions. - And to all permutations, so the null distribution should also change accordingly, I think. And the resulting test should make sense - I guess the issue arises when your cluster does not include interpolated channels, but we are comparing against the maximum permuted cluster that does, although it would have the effect of making the test more conservative! - Interesting thought, it likely makes sense to double-check whether interpolation affects the result. But as far as I understand, the main goal of interpolation is to have the same channels for each subject since different channels could be dropped during preprocessing. So it could be a reasonable assumption that the number of interpolated channels is rather low, and hopefully the effect of interpolation is minimal. But better to double-check, of course! - :white_check_mark: So, we've been comparing the contrast using a one-sample t-test vs 0 (no difference) - mathematically, is this the same as just doing a two-sampled test between conditions? If not, what is the difference between the two approaches and why would you do one and not the other? - You're right, these approaches should lead to the same result. ## :bangbang: More "stupid" questions please! No fear to ask things that are unclear to you! Feel free to use the mics as well - :white_check_mark: **Why is the threshold t-value and not p-value?** - in principle your results should be same, there's a direct equivalence/transform between p and t values. p values are constrained between 0-1, which makes t-values a bit nicer to plot in some cases - :white_check_mark: Is the threshold an absolute value or not? - It depends on the hypothesis - it can be either one-sided (X is greater than Y) or two-sided (X is different from Y). The behavior is controlled using the `tail` argument. By default, it is set to 0 and corresponds to a two-sided hypothesis. - :white_check_mark: If the t-value is positive, this means that famous > scrambled, or the other way around? Thanks! - Sorry, misunderstood it to be around significance. Yes this is correct! Old answer about significance: Larger t-values = smaller p values. (it also depends on how you calculate it) The conversion of your threshold is depending on your degrees of freedom, and the threshold changes accordingly: https://www.sjsu.edu/faculty/gerstman/StatPrimer/t-table.pdf - If we subtracted scrambled from famous (famous-scrambled), then a positive t-value means famous > scrambled - It wasn't about significance, it was just about sign, thank you!! -> clarified the answer, sorry, misunderstood :) you are correct in this case - :white_check_mark: Is there a good way of picking a threshold without 'eyeballing'? - There are alternative approaches like threshold-free cluster enhancement, here's a blog post that explains the procedure: [link](https://benediktehinger.de/blog/science/threshold-free-cluster-enhancement-explained/) - This tutorial shows how to use it with MNE: [link](https://mne.tools/stable/auto_tutorials/stats-sensor-space/10_background_stats.html#threshold-free-cluster-enhancement-tfce) - :white_check_mark: In mne they say that "Randomized data are generated with random sign flips", is there another way to randomize data to create null hypothesis ? What do we shuffle ? - doing a signflip-test has the advantage to make little assumption about the distribution. You could also do different kind of shuffles (depending on the data), but signflip test is also less suscepitble on outliers - Generally, doing a different shuffle (e.g. group assignment shuffle) would be possible, but in this case as we are comparing a difference and dont have group assignments, we are testing against the 0 and cant shuffle group labels. - :white_check_mark: When will we need to use single sensor analysis? I usually go straight to the level of all the sensors and all the time points. - For illustrative purposes - Sometimes you have a research question related to a specific location/a specifc correlate. - :bangbang: sadly, none of us is fNIRS expert. Let's ask maybe Robert later for fNIRS-specific questions. :slightly_smiling_face: - yes please :) - :white_check_mark: why does looking athe t-value plots feel like cherry pikcing the thresholds??? 🍒 - I understand the feeling but the final decision on whether the cluster is significant is purely based on comparing the t-value for actual data of this cluster against the t-value for the same cluster in permuted data. So we double-check whether a high t-value that we picked based on the threshold is actually significant. And cluster-based test was validated to show that the alpha (false positive rate, typically 5%) is preserved. - :white_check_mark: Is there a standard n_permutations number that is used, or is this data-specific? - Generally, with permutations you get a more stable result. To the best of my knowledge, there is no mathematically motivated standard number, but 1000 seems to be a common choice. It might make sense to try several values with your own data and see how much (hopefully, not much at some point) the number of permutations affects the result you get. - The p-value resolution depends on the number of permutations, i.e. if you o 10 permutations, the p-value can only be 0.1, 0.2, 0.3 etc., this limits the lower value of permutations that you should do. 1000 permutations gives you a resolutions of 0.001, which might be more informative - :white_check_mark: follow-up: could we do some sort of "convergence-test" to determine the ideal number of permutations we need? - so the p-values will have the number of permutations in the denominator, aka p = number of occurences / nr_permutations. so it depends on how exact you want your p-values to be. With the law of large numbers there should be some convergence indeed. Ususally you just select whatever is computationally feasibly, there's not disadvantage of selecting more afaik, except longer computation - :white_check_mark: If I run n_permutations = 5000 n_jobs= 2 the kernel crashes, (LookupError: <ContextVar name='shell_parent' at 0x000001F5573E53F0>). If I run it with fewer permutations (less than 100) it works.? - solved: problem was multithreading and verbose=True (this variable should be verbose='ERROR') if you experience the same error - :white_check_mark: can you discuss when this approach would be superior/inferior to doing mean/peak amplitude (within pre determined time window of interest)?? - Both approaches certainly make sense but might slightly differ in the application area - cluster-based test might serve well for exploratory purposes while having pre-defined region/time window of interest is very good for a clear pre-registration of a confirmatory analysis. So the superior/inferior part is most about how many assumptions you need to make. - :white_check_mark: what do I do if inter-subject variability is too high? how do I report my results? - Ideally, in a transparent way. You can add some plots that illustrate the variability you observe. Otherwise, inter-subject variability will also make the t-values lower, so in some way this will be accounted for by the test you perform. - :white_check_mark: If you want to visualise more than one channel, will it take hours to run? - in my experience it does not scale linearly, but you would need to try that out. Due to efficiency of matrix multiplication the slow part is the permutation, but less so the size of the matrix that you do the multiplication on (it's a bit more complex than that though) - :white_check_mark: Should we not normalise (e.g., L2) the data given we know there are overall differences in magnitude? - I would assume no as long as we want check that the differences are present. But if there are reasons to believe the differences in magnitude are not caused by the effect you want to investigate, then normalization could be a potential approach to solve this problem. - :white_check_mark: Just here to say that you are AWESOME!!! - :heart: ! - :white_check_mark: Can I compare connectivity values rs EEG data belong to patient and healthy with using this ? Generally my study do this - Generally yes, but you might need to adapt the implementation a bit. Maybe, the `mne-connectivity` package has some hints on how to do such type of comparison. - :white_check_mark: Is there any possibility to make simmilar comparisons as presented today but in a Bayesian manner in MNE? Or I'll have to figure it out by myself ;) - From a quick glance at the documentation, it seems that Bayesian stats are currently not supported so you'll probably have to use alternative means (e.g., export the values and load them in R). - :white_check_mark: If we want to use more than two condition simultaneously, cloud we use permutation_cluster_1samp_test or should we do u else? - Most likely, you need to use other functions (e.g., [link](https://mne.tools/stable/generated/mne.stats.f_mway_rm.html)) or even other packages. - :white_check_mark: for adjcency matrix , there is this in documentation for eeg that means adjcency is not relaible: - "Therefore, it is recommended to check (and, if necessary, manually modify) the result by inspecting it via mne.viz.plot_ch_adjacency()." - I think it general works, but you have to check it. :question: could you explain about that? How should we manage that? - It *can* be unstable, but it is not generally unstable. Therefore you need to check if the adjacency matrix is valid! you should define your adjacency matrix in a way that it meaninfully tells you which values in your data might be correlated, e.g. adjacent in time or adjacent in space, or adjacent in any other meaningful way. Does that answer your question? There are default adjacency matrices available for many M/EEG layouts, can also be imported from FieldTrip afaik. - :white_check_mark: Just to make sure if I'm well understood, the cluster on all the channel contrast, we cluster different channel? and the ERP constrast plot show the mean value of the cluster group? What the yellow zone mean? - Yes, we look for clusters of significance difference among all channels that we have in the data. The plots show the average time course (over subjects and sensors) for each cluster. Yellow areas correspond to the time points that belong to the significant channel in at least one sensor. - :question: is there a rule of thumb for the cluster threshold? e.g. same range as alpha? - :question: is there anyone have the same problem as ``` File "d:\Tools\anaconda3\envs\mne\Lib\site-packages\ipykernel\kernelbase.py", line 797, in get_parent return self._shell_parent.get() ^^^^^^^^^^^^^^^^^^^^^^^^LookupError: <ContextVar name='shell_parent' at 0x000001ECD1023790> ``` when I doing the `spatio_temporal_cluster_1samp_test` - Come to the helpers, we can look at the error in more deatil :) - sorry, we did not manage to see you in person. I have never seen this error before, will check! - :bangbang: Useful (and important) fieldtrip page on cluster-based permutation report: [How NOT to interpret results from a cluster-based permutation test](https://www.fieldtriptoolbox.org/faq/stats/clusterstats_interpretation/) ## Your own research: what methodological problems do you have, do you have general questions? Everybody can chime in! - X ## PracticalMEEG2025 playlist: https://open.spotify.com/playlist/1EVtKZrp3r9fn7ALUbpxp7?si=HH06rGyaQy60M5W7zEdZ2Q --- **:arrow_up: Add new questions just above this line :arrow_up:**

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully