Małgorzata Wierzba, PhD (m.wierzba@nencki.edu.pl)
Laboratory of Emotions Neurobiology
Center of Excellence for Neural Plasticity and Brain Disorders BRAINCITY
Nencki Institute of Experimental Biology, Polish Academy of Sciences
- Copy the
demo-ds005460-with-derivativesdirectory from the shared materials to your local machine.- It is a subset of the original dataset, containing data from three subjects:
sub-0312f,sub-1512e, andsub-2811d. - However, besides (some of) raw data, it now also contains preprocessed data in the
derivatives/fmriprepsubdirectory.
- It is a subset of the original dataset, containing data from three subjects:
.
├── dataset_description.json
├── derivatives
│ └── fmriprep
│ ├── sub-0312f
│ │ └── func
│ │ ├── sub-0312f_task-cet_desc-confounds_timeseries.json
│ │ ├── sub-0312f_task-cet_desc-confounds_timeseries.tsv
│ │ ├── sub-0312f_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.json
│ │ └── sub-0312f_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
│ ├── sub-1512e
│ │ └── func
│ │ ├── sub-1512e_task-cet_desc-confounds_timeseries.json
│ │ ├── sub-1512e_task-cet_desc-confounds_timeseries.tsv
│ │ ├── sub-1512e_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.json
│ │ └── sub-1512e_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
│ └── sub-2811d
│ └── func
│ ├── sub-2811d_task-cet_desc-confounds_timeseries.json
│ ├── sub-2811d_task-cet_desc-confounds_timeseries.tsv
│ ├── sub-2811d_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.json
│ └── sub-2811d_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
├── participants.json
├── participants.tsv
├── sub-0312f
│ └── func
│ └── sub-0312f_task-cet_events.tsv
├── sub-1512e
│ └── func
│ └── sub-1512e_task-cet_events.tsv
├── sub-2811d
│ └── func
│ └── sub-2811d_task-cet_events.tsv
└── task-cet_events.json
-
Open MATLAB and navigate to the
demo-ds005460-with-derivativesdirectory (the one you just created on your machine). -
Start SPM by typing:
spm fmri
In the CLIMATE BRAIN dataset, data preprocessing was performed using fMRIPrep rather than SPM. While the general logic is similar, there are some differences between these software packages.
- One important difference is that they use different naming conventions for the output files. In particular, fMRIPrep follows the so called Brain Imaging Data Structure (BIDS) format.
- BIDS is a common standard for naming files and directories. For instance:
- Raw data are located in the root directory of the dataset, while derived data are stored in the
derivativessubdirectory. In particular,derivatives/fmriprepcontains fMRIPrep output derived from the raw data. - Data for each subject are placed in subdirectories named
sub-<label>, where string<label>is substituted with the unique identifier of each subject, e.g.sub-0312f,sub-1512e,sub-2811d. anatcontains anatomical data, whilefunccontains functional data.- ... and so on! (for the full BIDS specification, go here)
- Raw data are located in the root directory of the dataset, while derived data are stored in the
- Such consistent way to organize neuroimaging datasets makes it easy to understand and share data across research groups and institutions.
- This is why BIDS is now widely adopted by the scientific community, and making your data BIDS-compliant is sometimes even a requirement. For instance, OpenNeuro allows users to host neuroimaging data for free, as long as it is BIDS-formatted.
- Navigate to the
demo-ds005460-with-derivativesdirectory. The files that you see in thederivatives/fmriprepare selected fMRIPrep outputs.- These files are both sufficient and necessary to proceed with the statistical analysis of fMRI data.
- All intermediate and auxiliary files have been removed.
- All files are organized according to BIDS.
- Look at the name of this file:
sub-1512e_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz. - Try to guess what it is just by looking at its name and its location in the directory structure.
- Look at the name of this file:
We will start by performing the subject-level analysis (i.e., first-level analysis) separately for each subject. We will start with sub-1512e and then follow by processing the remaining subjects' data. If we have time, we will proceed to the group-level analysis (i.e., second-level analysis).
Some important things to keep in mind about fMRIPrep:
- All NIfTI images produced by fMRIPrep are compressed (i.e.,
.nii.gzformat). - By default, fMRIPrep does not perform smoothing because some analyses require unsmoothed data.
- fMRIPrep stores head-motion parameters (translations and rotations) in a large TSV file together with other confounds.
Therefore, there is still some preprocessing left to do before we can move on to the statistical analysis. This will be covered in the following sections, so be patient!
IMPORTANT: All NIfTI images produced by fMRIPrep are compressed (i.e., .nii.gz format).
Since SPM can only work with uncompressed NIFTI, we need to unzip them first.
- Use the
Batchbutton, then selectBasicIO > File Operations > Gunzip Files - Click on the
File Set, thenSpecify. - Navigate to
derivatives/fmriprep/sub-1512e. Fromfuncselect the preprocessed functional imagesub-1512e_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz. When you're ready, clickDone. - Click the green "play" button to run this step!
- Navigate to your files to check whether the
.nii.gzfile was successfully uncompressed into a.niifile. - Save your batch (if needed) and close it.
IMPORTANT: By default, fMRIPrep does not perform smoothing because some analyses require unsmoothed data.
The type of analysis we are planning to perform requires that the data be smoothed.
- Use the
Smoothbutton. - Click on the
Images to smooth, then navigate to thederivatives/fmriprep/sub-1512e/funcsubdirectory. - Important: Make sure to select all the preprocessed funtional images! Click on the
Framesfield, replace1withInf, the press theEnterkey. - Now, right-click on the right pane and from the context menu select
Select All. You should see 385 files added. If you're ready, clickDone. - Change the
FWHMfield to6 6 6. - Click the green "play" button to run this step!
- Navigate to your files to check if the smoothing was sucessful. You will recognize the resulting output file by the
sprefix. - Save your batch (if needed) and close it.
IMPORTANT: fMRIPrep stores head-motion parameters (translations and rotations) in a large TSV file together with other confounds.
For our analysis, we will only need six motion parameters, formatted in a way that SPM can use (i.e., a .txt file without a header).
- fMRIPrep stores head-motion parameters in the
sub-1512e_task-cet_desc-confounds_timeseries.tsvfile. Open this file in any text editor and try to locate the six motion parameters. Can you recognize them by name? - Close SPM for now.
- In MATLAB, navigate to the root directory of your dataset, e.g.
demo-ds005460-with-derivatives. - In MATLAB, click
New Script, then copy and paste the following code snippet:
subjects = {'sub-0312f', 'sub-1512e', 'sub-2811d'};
for s = 1:3
sub = subjects{s};
input = fullfile('./derivatives/fmriprep', sub, 'func', [sub, '_task-cet_desc-confounds_timeseries.tsv']);
output = fullfile('./derivatives/fmriprep', sub, "func", [sub, '_motion_parameters.txt']);
T = readtable(input, "FileType", "text", "Delimiter", "\t");
cols = ["trans_x", "trans_y", "trans_z", "rot_x", "rot_y", "rot_z"];
writematrix(T{:,cols}, output, "Delimiter", "tab");
end
- Give it a name (e.g.,
extract_motion_parameters.m) and save it in your user-specificMATLABdirectory. You should be able to find this directory in your home directory, it will look like this:~/Documents/MATLAB. - Run the script!
- Navigate to your files to see if the
sub-1512e_motion_parameters.txtfile was indeed created. It will be in thederivatives/fmriprep/sub-1512e/funcsubdirectory. - In fact, the script extracted motion parameters for all three subjects. You can verify that the motion parameter files were created in the other subjects’ directories as well.
- Clear MATLAB workspace, before going back to SPM. To do that, type this in the MATLAB console:
clear all
- Go back to SPM:
spm fmri
We are almost ready to start the first-level analysis.
Before we can start fMRI data analysis, we need to know the experimental task that was performed in the scanner. In particular:
- What conditions (experimental, control) was the subject exposed to while performing the task?
- For each condition, we need to know exactly:
- When it occurred (onsets)?
- How long it lasted (durations)?
Here, we will analyse data from the Carbon Emission Task (CET), which involves participants making a series of decisions between receiving a monetary bonus (a self-interest choice) and retiring carbon emission certificates (a climate-friendly choice).
- Go to the CLIMATE BRAIN publication and read the description of the CET task. Make sure to take a look at
Figure 3. This will help you understand the difference between "CET" (experimental condition) and "dummy" (control condition). - Navigate to your files and in the raw data look for the
sub-1512e_task-cet_events.tsvfile.- The file will be located in the
demo-ds005460-with-derivatives/sub-1512e/funcsubdirectory. - Open this file in any text editor.
- The file will be located in the
- As you can see from the contents of this file, all trials can generally be divided into
CETanddummy. - Note that the
onsetanddurationcolumns provide information about the onset and duration of each trial, respectively (in seconds).- Onsets for the
CETtrials are:
5.7918 20.8334 51.1668 66.9674 83.2502 99.5425 130.6259 147.4176 162.9592 193.0510 208.3343 224.8760 256.7088 273.0094 306.5838 322.8761 338.1678 354.7095 387.7924 403.3346 418.8763 451.9591 467.2514 498.3342 514.8764 530.6765 546.4682 578.3099 593.3432 609.8848 640.7183 657.5100 689.8428 705.1434 736.9851 753.7768- Onsets for the
dummytrials are:
36.1257 114.5836 178.0009 240.9177 290.0422 371.7596 435.1674 483.2931 561.5098 625.6761 674.3011 721.4434- Both
CETanddummytrials have a duration of10seconds.
- Onsets for the
Now, we can finally start the first-level analysis!
- Use the
Specify 1st-levelbutton. - Click on
Directory.- Here, we need to provide the directory where we want SPM to save the first-level results.
- Navigate to your files. Inside the
derivativesdirectory, create a newresultssubdirectory, and within this directory, create a subject-specific folder namedsub-1512e. - The same can be achived by running this command in the MATLAB console:
mkdir derivatives/results/sub-1512e- At the end, your directory structure should look like this:
demo-ds005460-with-derivatives/derivatives/results/sub-1512e. - Go back to SPM and select this newly created directory.
- Specify
Units for designasSeconds. - Specify
Interscan intervalas2.- This refers to the repetition time (TR), which is the time required to acquire a single functional volume.
- In our case, the TR is 2 seconds. You can verify this information in the
sub-1512e_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.jsonfile, by opening it in any text editor.
- Click on
Data & Design, thenNew: Subject/Session. - Click on
Scans, thenSpecify, then navigate to thederivatives/fmriprep/sub-1512e/funcsubdirectory. - Important: Make sure to select all the smoothed funtional images! Click on the
Filterfield and change it toss.*. Then click on theFramesfield, replace1withInf, then press theEnterkey. - Now, right-click on the right pane and from the context menu select
Select All. You should see 385 files added. If you're ready, clickDone. - Click on
Conditions:- Here we need to specify any conditions (experimental, control) that the subject was exposed to while performing the task.
- As discussed above, we have two conditions (
CETanddummy). Therefore we clickNew: Conditiontwice. - For each condition, specify
Name,Onsets, andDurations. If in doubt, refer to the "But before we start..." section above.
- Click on
Multiple regressors, thenSpecify. Navigate toderivatives/fmriprep/sub-1512e/funcsubdirectory and select thesub-1512e_motion_parameters.txtfile, containing motion parameters. - Click the green "play" button to run this step!
- Take a look at the output and review your experimental design! Do you know what different columns correspond to? Is this a block design or an event-related design?
- Save your batch, but don't close it this time!
- While in the batch editor, select
SPM > Stats > Model estimation. - Click on
Model estimation, thenSelect SPM.matand this timeDependencyinstead ofSpecify. - Choose the only available option on the list,
fMRI model specification. - Click the green "play" button to run both steps!
- SPM will issue a warning and ask if you want to overwrite the existing model. Confirm by clicking
Continue(we do this only for educational purposes).
- SPM will issue a warning and ask if you want to overwrite the existing model. Confirm by clicking
- Save changes to your batch, but don't close it this time!
- While in the batch editor, select
SPM > Stats > Contrast Manager. - Click on
Contrast Manager, thenSelect SPM.matand this timeDependencyinstead ofSpecify. - From the list of available dependencies, choose
Model estimation. - Click on
Contrast Sessionsand thenNew: T-contrast.- Specify
NameasCET vs dummy. - Specify
Weights vectoras[1 -1].
- Specify
- Click on
Contrast Sessionsagain and thenNew: T-contrast- Specify
Nameasdummy vs CET. - Specify
Weights vectoras[-1 1].
- Specify
- Change
Delete existing contraststoYes. - Click the green "play" button to run all steps!
- SPM will issue a warning again, proceed by clicking
Continue(we do this only for educational purposes).
- SPM will issue a warning again, proceed by clicking
- Save changes to your batch and close it. :)
- In the main SPM menu, use the
Resultsbutton and navigate to the SPM model you have just created, i.e.derivatives/results/sub-1512e/SPM.mat. - Select the contrast you'd like to view, e.g.
CET vs dummy, then clickDone. - Don't apply any masking.
- For your p value adjustment choose
FWE, then confirm that you want to use the threshold of0.05. - Repeat steps 1-3, but this time choose
noneinstead ofFWE. Also, use the threshold of0.001and extent threshold of0. - What do you see?
- Are the results the same or different from what you see in the CLIMATE BRAIN publication?
- Try to navigate to coordinates
x = -6,y = 26andz = 37, just to make sure. - Discuss your ideas with the tutor.
The results table provides cluster-level and peak-level statistics.
- Take a closer look at the results table.
- For each cluster, it provides the cluster size (
kE) and p-values, adjusted using different methods. - For each cluster, it shows 3 local peaks, that are more than 8 mm apart.
- For each peak, it provides the T statistics and p-values, adjusted using different methods.
- Also, for each peak it gives you the
[x, y, z]coordinates, i.e. its location in the MNI space.
- For each cluster, it provides the cluster size (
You can also view the results in a graphical form, overlaid on a brain template.
- While in SPM's
Resultswindow, use theOverlaysselector. - Select
Sections, then use thePrevpath selector to navigate tospm25/canonicalsubdirectory. - Choose
single_subj_T1.niias a template. - Move the coursor around to view different clusters.
- Right-click on the image and from the context menu select:
Display > Labels > Neuromorphometrics. - What brain regions do the visible clusters represent?
We will now learn how to export the results to a NIfTI file. This file can then be opened in any NIfTI viewer (e.g. MRIcron).
- While in SPM's
Resultswindow, use theSaveselector. - Choose
Thresholded SPMand provide a meaningful name for your output file, e.g.CET-vs-dummyordummy-vs-CET. - Navigate to your files, find the file that you just created and try opening it in MRIcron.
Before we can proceed to the second level analysis, all the above steps need to be repeated for the remaining subjects.
Any survivors left...?
In the shared materials, you will find two files: tutorial_batch_glm_job.m, which defines the batch, and tutorial_batch_glm.m, which runs it.
- Open the
tutorial_batch_glm_job.mfile in SPM using theBatchbutton. - Notice that the batch contains all the steps we performed today!
- Notice that the subject-specific information has been removed and replaced with
Xcharacters. When we run the script,Xcharacters will be replaced with the following:- a preprocessed functional image, i.e.
sub-<label>_task-cet_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz - a directory name for the subject-specific results, i.e.
./derivatives/results/sub-<label> - a file containing motion parameters, i.e.
sub-<label>_motion_parameters.txt
- a preprocessed functional image, i.e.
- Now close SPM and open the
tutorial_batch_glm.mdirectly in MATLAB. This script is has been prepared to run over all the three subjects. Since we have already processed the first subject, we only need to run the script for the remaining two subejcts, i.e.sub-0312fandsub-2811d. - Edit the code by changing the list of subjects.
- Save the
tutorial_batch_glm.mscript and then run it, by pressing the greenRunbutton in the MATLAB menu! - Relax and enjoy the show! 🍿📺
- When it's done, clear MATLAB workspace, and then go back to SPM.
clear all
spm fmri
- Don't forget to look at the results for
sub-0312fandsub-2811d! Are they similar or completely different?
Now, we are ready to start the second-level analysis!
- Use the
Specify 2nd-levelbutton. - Click on
Directory.- Here, we need to provide the directory where we want SPM to save the second-level results.
- Navigate to your files, in the
derivatives/resultsdirectory create a newgroupsubdirectory. - At the end, your directory structure should look like this
demo-ds005460-with-derivatives/derivatives/results/group. - Go back to SPM and select this newly created directory.
- Click on
Designand notice that at this point we can choose from many different types of analysis, such as one-sample t-test, paired t-test or ANOVA. In this case, we select the defaut option, i.e. one-sample t-test. - Click on
Scans, navigate toderivatives/results, then to each subject's results subdirectory and selectcon_0001.niiimage for each subject. In total, you should have three files selected. These images represent theCET vs dummycontrasts we've seen earlier! - Save your batch, but don’t close it!
- While in the batch editor, select
SPM > Stats > Model estimation. - Click on
Model estimation, thenSelect SPM.matand this timeDependencyinstead ofSpecify. - Choose the only available option on the list,
Factorial design specification. - Save changes to your batch, but don’t close it this time!
- While in the batch editor, select
SPM > Stats > Contrast Manager. - Click on
Contrast Manager, thenSelect SPM.matand this timeDependencyinstead ofSpecify. - From the list of available dependencies, choose
Model estimation. - Click on
Contrast Sessionsand thenNew: T-contrast.- Specify
NameasGroup: CET vs dummy. - Specify
Weights vectoras1.
- Specify
- Click the green “play” button to run all steps!
- Save changes to your batch and close it.
- Use the
Resultsbutton to view the group results, you already know all the steps! :)
The group results are somewhat disappointing, as they look nothing like those presented in the CLIMATE BRAIN publication.
- Was this something you expected?
- Discuss your ideas with the tutor.
Congratulations, you have just completed your first fMRI data analysis!