Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] Combine similar two-runs GLM examples #3191

Merged
merged 26 commits into from Jan 17, 2024

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Mar 24, 2022

Closes #2771
Closes #4211

Changes proposed in this pull request:

  • Combine plot_fiac_analysis.py and plot_fixed_effects.py into plot_two_session_model.py.
  • Update a link in first_level_model.rst that originally went to plot_fiac_analysis.py.
  • Example now relies on the fact that Nilearn will zero pad contrast matrices (uncovered a bug that got fixed)
  • Update some of the code to use run instead of session
  • Fix plotting of unpadded contrast matrices and add test for it

@tsalo tsalo added the Documentation for documentation related questions or requests label Mar 24, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2022

👋 @tsalo Thanks for creating a PR!

Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft.

Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.

  • PR has an interpretable title.
  • PR links to Github issue with mention "Closes #XXXX"
  • Code is PEP8-compliant.
  • (Bug fixes) There is at least one test that would fail under the original bug conditions.
  • (New features) There is at least one unit test per new function / class.
  • (New features) The new feature is demoed in at least one relevant example.

We will review it as quick as possible, feel free to ping us with questions if needed.

@codecov
Copy link

codecov bot commented Mar 24, 2022

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (6764c9e) 92.09% compared to head (256bfff) 92.00%.
Report is 8 commits behind head on main.

Files Patch % Lines
nilearn/datasets/func.py 71.42% 2 Missing ⚠️
nilearn/glm/_utils.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3191      +/-   ##
==========================================
- Coverage   92.09%   92.00%   -0.10%     
==========================================
  Files         144      144              
  Lines       16366    16389      +23     
  Branches     3426     3431       +5     
==========================================
+ Hits        15073    15078       +5     
- Misses        754      767      +13     
- Partials      539      544       +5     
Flag Coverage Δ
macos-latest_3.10_test_plotting 91.87% <89.65%> (-0.02%) ⬇️
macos-latest_3.11_test_plotting 91.87% <89.65%> (-0.02%) ⬇️
macos-latest_3.12_test_plotting 91.87% <89.65%> (-0.02%) ⬇️
macos-latest_3.8_test_plotting 91.83% <89.65%> (-0.02%) ⬇️
macos-latest_3.9_test_plotting 91.83% <89.65%> (-0.02%) ⬇️
ubuntu-latest_3.10_test_plotting 91.87% <89.65%> (-0.02%) ⬇️
ubuntu-latest_3.11_test_plotting 91.87% <89.65%> (-0.02%) ⬇️
ubuntu-latest_3.12_test_plotting 91.87% <89.65%> (-0.02%) ⬇️
ubuntu-latest_3.12_test_pre 91.87% <89.65%> (-0.02%) ⬇️
ubuntu-latest_3.8_test_min 68.91% <27.58%> (-0.08%) ⬇️
ubuntu-latest_3.8_test_plot_min ?
ubuntu-latest_3.8_test_plotting 91.83% <89.65%> (-0.02%) ⬇️
ubuntu-latest_3.9_test_plotting 91.83% <89.65%> (-0.02%) ⬇️
windows-latest_3.10_test_plotting 91.84% <89.65%> (-0.02%) ⬇️
windows-latest_3.11_test_plotting 91.84% <89.65%> (-0.02%) ⬇️
windows-latest_3.12_test_plotting 91.84% <89.65%> (-0.02%) ⬇️
windows-latest_3.8_test_plotting 91.80% <89.65%> (-0.02%) ⬇️
windows-latest_3.9_test_plotting 91.81% <89.65%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx !
I think we can still improve a little bit.

examples/04_glm_first_level/plot_two_session_model.py Outdated Show resolved Hide resolved
examples/04_glm_first_level/plot_two_session_model.py Outdated Show resolved Hide resolved
@Remi-Gau Remi-Gau added the GLM Issues/PRs related to the nilearn.glm module. label Feb 20, 2023
@Remi-Gau
Copy link
Collaborator

@tsalo do you want me to take over or do you prefer to wrap it up?

@tsalo
Copy link
Member Author

tsalo commented Feb 24, 2023

@Remi-Gau, I think this is waiting on #3203, but I could be misremembering.

@Remi-Gau
Copy link
Collaborator

@Remi-Gau, I think this is waiting on #3203, but I could be misremembering.

My bad: I misread a comment in the thread.

@bthirion
Copy link
Member

#3203 needs a bit of love, but I'm willing to finish it. Thx for the remainder !

@Remi-Gau
Copy link
Collaborator

#3203 has been merged so this should unblock this PR.

@tsalo let me know if you have the bandwidth to get back to it.

@Remi-Gau
Copy link
Collaborator

@tsalo am taking over this PR before it drifts too far

@tsalo
Copy link
Member Author

tsalo commented Jan 10, 2024

@Remi-Gau thanks for taking over. Sorry I didn't get around to it back in September.

@Remi-Gau
Copy link
Collaborator

No worries at all.

@Remi-Gau
Copy link
Collaborator

To probably tackle in a separate PR but it seems that the contrast matric plotting function gives weird results when it is given unpadded contrast matrices.

@Remi-Gau Remi-Gau changed the title [DOC] Combine similar two-session GLM examples [DOC] Combine similar two-runs GLM examples Jan 10, 2024
@bthirion
Copy link
Member

LGTM, but the docu build seems broken.

@Remi-Gau
Copy link
Collaborator

Remi-Gau commented Jan 11, 2024

TODO:

  • update changelog

@tsalo
Copy link
Member Author

tsalo commented Jan 11, 2024

@tsalo do you remember what specifically was still needed?

@Remi-Gau I thought the only issue was that compute_fixed_effects wasn't producing correct results for F contrasts, so the two figures being compared didn't match. I don't think there were any actual bugs in the example back when we paused it, so it could be that some things are out of date now.

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise, thx !

examples/04_glm_first_level/plot_two_runs_model.py Outdated Show resolved Hide resolved
examples/04_glm_first_level/plot_two_runs_model.py Outdated Show resolved Hide resolved
@@ -409,6 +403,54 @@ def plot_contrast_matrix(
return ax


def pad_contrast_matrix(contrast_def, design_matrix):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to fix #4211 in this PR to have valid glm reports in this example

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can extract in separate PR if needed.

Comment on lines +341 to +348
contrast_def : :obj:`str` or :class:`numpy.ndarray` of shape[1] <= n_col \
where ``n_col`` is the number of columns of the design matrix.
The string can be a formula compatible
with :meth:`pandas.DataFrame.eval`.
Basically one can use the name of the conditions
as they appear in the design matrix of the fitted model
combined with operators +-
and combined with numbers with operators +-`*`/.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I can tell the code in this function cannot handle list of strings or list of arrays as inputs

@Remi-Gau
Copy link
Collaborator

Adding a report of the outputs before and after: could not spot any difference.

reports.zip

Copy link
Member

@ymzayek ymzayek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Remi-Gau thanks it's looking good! Some minor comments

@@ -180,6 +180,17 @@ @article{Craddock2012
year = {2012}
}

@article{dehaene2006functional,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we alphabetized this list this should move to after Davidson2004

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

thanks!!!

examples/04_glm_first_level/plot_two_runs_model.py Outdated Show resolved Hide resolved
examples/04_glm_first_level/plot_two_runs_model.py Outdated Show resolved Hide resolved
examples/04_glm_first_level/plot_two_runs_model.py Outdated Show resolved Hide resolved
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many improvements in one PR, thx !

@Remi-Gau Remi-Gau merged commit 881816d into nilearn:main Jan 17, 2024
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation for documentation related questions or requests GLM Issues/PRs related to the nilearn.glm module.
Projects
None yet
4 participants