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

[FIX] Refactor design matrix and contrast formula for the two-sample T-test example #4407

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

YCHuang0610
Copy link

@YCHuang0610 YCHuang0610 commented Apr 29, 2024

Closes #4400

Changes proposed in this pull request:

  • Simplify the design matrix for paired and unpaired design from [1 -1] to [1 0].
  • Fix the uncorrect design matrix for paired design by adding a interception column.

Copy link
Contributor

👋 @YCHuang0610 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 (see our documentation on PR structure)
  • Code is PEP8-compliant (see our documentation on coding style)
  • Changelog or what's new entry in doc/changes/latest.rst (see our documentation on PR structure)

For new features:

  • There is at least one unit test per new function / class (see our documentation on testing)
  • The new feature is demoed in at least one relevant example.

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

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

Copy link

codecov bot commented Apr 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.02%. Comparing base (abb80ff) to head (e33eab1).
Report is 68 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4407      +/-   ##
==========================================
+ Coverage   91.85%   92.02%   +0.17%     
==========================================
  Files         144      143       -1     
  Lines       16419    16635     +216     
  Branches     3434     3528      +94     
==========================================
+ Hits        15082    15309     +227     
+ Misses        792      758      -34     
- Partials      545      568      +23     
Flag Coverage Δ
macos-13_3.11_test_plotting 91.81% <ø> (?)
macos-13_3.12_test_plotting 91.81% <ø> (?)
macos-13_3.8_test_plotting 91.77% <ø> (?)
macos-13_3.9_test_plotting 91.77% <ø> (?)
macos-latest_3.11_test_plotting ?
ubuntu-latest_3.10_test_plotting ?
ubuntu-latest_3.8_test_min 68.71% <ø> (?)
ubuntu-latest_3.8_test_plot_min 91.47% <ø> (?)
windows-latest_3.11_test_plotting 91.78% <ø> (?)
windows-latest_3.12_test_plotting 91.78% <ø> (?)
windows-latest_3.8_test_plotting 91.74% <ø> (?)
windows-latest_3.9_test_plotting 91.75% <ø> (?)

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.

import numpy as np

condition_effect = np.hstack(([1] * n_subjects, [-1] * n_subjects))
vertical_subjects = np.hstack(([1] * n_subjects, [0] * n_subjects))
horizontal_subjects = np.hstack(([0] * n_subjects, [1] * n_subjects))
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I should have been clearer, but when you do this you make the design matrix rank deficient: the sum of these two regressors, is equal to the some of all the subject regressors.
This means that the design matrix is no longer invertible, and some contrasts are not estimable. Normally, you should get a warning when you run that code.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for that mistake for the paired design matrix.
Now I have modified the paired design matrix as follows:

$$\begin{bmatrix} 1 & 1 & 0 & \cdots & 0\\\ 1 & 0 & 1 & \cdots & 0\\ \vdots & \vdots & \vdots & \ddots & \vdots\\\ 1 & 0 & 0 & \cdots & 1\\\ 0 & 1 & 0 & \cdots & 0\\\ 0 & 0 & 1 & \cdots & 0\\\ \vdots & \vdots & \vdots & \ddots & \vdots\\\ 0 & 0 & 0 & \cdots & 1 \end{bmatrix}$$

which rank is 17.

The unpaired design matrix is now added a intercept column as follows:

$$\begin{bmatrix} 1 & 1 \\\ 1 & 1 \\\ 1 & 1 \\\ \vdots & \vdots \\\ 0 & 1 \\\ 0 & 1 \\\ 0 & 1 \end{bmatrix}$$

Its rank is 2 which is a full column rank matrix.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there an error in the design matrix from the second level two sample test example?
3 participants