Skip to content

Commit

Permalink
[FIX] Refactor design matrix and contrast formula for the two-sample …
Browse files Browse the repository at this point in the history
…T-test example (nilearn#4407)

* Refactor design matrix and update contrast formula for the two-sample t-test example

* [FIX] Refactor design matrix and contrast formula for two-sample t-test example

* Solve rank-deficien design matrix for paired-design

* Modify the comment in plot_second_level_two_sample_test.py

* Modified the comment paragraph in plot_second_level_two_sample_test.py

* formatting fix through tox

* Add author information and change logs

* add author information (Sort alphabetically.)

* add newline at end of file

* fix label for example

* add `.py` in the example reference

---------

Co-authored-by: Remi Gau <[email protected]>
Co-authored-by: Himanshu Aggarwal <[email protected]>
  • Loading branch information
3 people authored May 27, 2024
1 parent 8295ffa commit 1745198
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ authors:
website: https://github.com/ymzayek
affiliation: Inria, Saclay, France
orcid: https://orcid.org/0000-0003-2904-2530
- given-names: Yichun
family-names: Huang
website: https://github.com/YCHuang0610
affiliation: Peking University, Beijing, China
- given-names: Zvi
family-names: Baratz
website: https://github.com/ZviBaratz
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ Changes
- :bdg-dark:`Code` Remove the unused arguments ``upper_cutoff`` and ``exclude_zeros`` for :func:`nilearn.masking.compute_multi_background_mask` (:gh:`4273` by `Rémi Gau`_).

- :bdg-dark:`Code` Throw error in :func:`nilearn.glm.first_level.first_level_from_bids` if unknown ``kwargs`` are passed (:gh:`4414` by `Michelle Wang`_).

- :bdg-primary:`Doc` Refactor design matrix and contrast formula for the two-sample T-test example in :ref:`sphx_glr_auto_examples_05_glm_second_level_plot_second_level_two_sample_test.py` (:gh:`4407` by `Yichun Huang`_).
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,21 @@
# Next, we model the effect of conditions (sample 1 vs sample 2).
import numpy as np

condition_effect = np.hstack(([1] * n_subjects, [-1] * n_subjects))
condition_effect = np.hstack(([1] * n_subjects, [0] * n_subjects))

# %%
# The design matrix for the unpaired test doesn't need any more columns
# The design matrix for the unpaired test needs to add an intercept,
# For the paired test, we include an intercept for each subject.
subject_effect = np.vstack((np.eye(n_subjects), np.eye(n_subjects)))
subjects = [f"S{i:02d}" for i in range(1, n_subjects + 1)]

# %%
# We then assemble those into design matrices
unpaired_design_matrix = pd.DataFrame(
condition_effect[:, np.newaxis], columns=["vertical vs horizontal"]
{
"vertical vs horizontal": condition_effect,
"intercept": 1,
}
)

paired_design_matrix = pd.DataFrame(
Expand Down

0 comments on commit 1745198

Please sign in to comment.