Two-sample t-test¶
In this tutorial we will look at comparing two groups of participants. To do this we will use a two-sample t-test, using the dataset previously introduced.
We will focus on testing for a difference in overall task activation (contrast con_0009.nii
) depending on whether participants responded with their left or right hand.
Specifying the model¶
- Navigate to
derivatives/second_level
and make an empty directory where you will save your results. Name it something meaningful to you, e.g.two_sample_ttest_task
. - Switch to this new directory in Matlab, using the file navigator (typically on the left hand side of the Matlab window).
- We will now define our groups based on the information in
participants.mat
. - In your Matlab command window, load the file:
load('participants.mat')
. - You can view the contents of the file in the Matlab window. You will see that there is a variable called
response hand
which codes for which hand the participant used to make task responses.0
corresponds to left,1
to right. -
We will define a variable selecting all participants who responses with their left hand. Copy and paste the following code into the Matlab command window and press enter:
% identify which rows in the spreadsheet correspond to left-hand responders group1_id = find(participants.response_hand ~= true) % for each left-hand responder, create a full path to the contrast exploring task effects (con_0009.nii) for i = 1:numel(group1_id) sub = participants.id_string{group1_id(i)} img_group1{i} = char(fullfile(pwd, "derivatives/first_level", sub, "con_0009.nii")) end
img_group1
holds all the directories pointing to left-handed responder’scon_0009.nii
. -
Now we’ll do the same for the right-hand responders:
% identify which rows in the spreadsheet correspond to right-hand responders group2_id = find(participants.response_hand == true) % for each right-hand responder, create a full path to the contrast exploring task effects (con_0009.nii) for i = 1:numel(group2_id) sub = participants.id_string{group2_id(i)} img_group2{i} = char(fullfile(pwd, "derivatives/first_level", sub, "con_0009.nii")) end
img_group2
holds all directories pointing to right-hand responder’scon_0009.nii
. -
Return to the main SPM menu window and select
Specify 2nd level
. - In the pop-up batch editor window, select your newly created output directory by clicking
Directory
and navigating toderivatives/second_level/two_sample_ttest_task
in the selection box. - Define your statistical model by selecting
Design
Two-sample t-test
- Select
Group 1 scans
Specify...
. Bring up the edit window by clickingEd
in the file selection window. - From the edit window, you can now insert the variables you have saved in Matlab. Type in
img_group1
and pressEval
. This should fill the window with full paths to each left-hand responder’scon_0009.nii
file. ClickAccept
Done
. - Let’s do the same thing for right-hand responders.
Group 2 scans
Specify...
Ed
img_group2
Eval
Accept
Done
. - From the drop-down menu, select
SPM
Stats
Model estimation
. - Navigate to
Model estimation
in the left-hand panel of the batch window. - Press
Select SPM.mat
Dependency
Factorial design specification: SPM.mat file
OK
. - From the drop-down menu panel, select
SPM
Stats
Contrast manager
. - Within the
Contrast manager
, click onSelect SPM.mat
Dependency
Model estimation: SPM.mat file
OK
. - You can now start specifying your contrasts of interest in
Contrast sessions
comparing left to right hand responders and vice versa. - Select
Contrast sessions
New: T-contrast
. - Name your contrast,
Name
Specify...
left > right
. - Specify your contrast weight,
Weights vector
Specify...
1 -1
. - Now, do the same for the reverse contrast -
Contrast sessions
New: T-contrast
.Name
Specify...
right > left
.Weights vector
Specify...
-1 1
. - When you’re ready, save your batch and press to run your analysis.
Your design matrix should have two columns specifying left-hand and right-hand responders:
Viewing the results¶
To view the results of your analysis, select Results
from the SPM menu and select the SPM.mat
file corresponding to your analysis. In our case, this will be in derivatives/second_level/two_sample_ttest_task
. Choose a contrast to view, e.g. left > right
.
SPM will now let you select masking and multiple comparisons correction. Select the following in the SPM window:
Apply masking
none
P-value adjustment to control
FWE
P-value
0.05
Extent threshold (voxels)
0
After going through these steps, SPM will display the results as an activation map and summary table:
We can see that participants who used their left-hand to make responses had stronger (more positive) activation in the contralateral (right) motor cortex.
Exercise
Can you follow the steps above to view the second contrast we specified? What do you expect the results will be? Can you display them as a heatmap on a standard template?
If you need a reminder of what any of the options in the SPM results window are, visit the one-sample t-test tutorial.