06 - first level GLM
After preprocessing your data, probably with fmriprep, it´s time to do your first level GLM (= general linear model).
In this step, you will compute mean contrast-estimates for predefined contrasts for each subject individually. These estimations will be used later in the second level Analysis, where you extract relevant (for your research question/hypothesis) values.
For all cases described below, there are generally three things you have to change before running the cells in the jupyter notebook (or the python script):
Change the directories
Indicate the task, the number of sessions and the subject
Implement your contrasts
1 Surface-based Analysis
To compute a first-level GLM you can adapt the following jupyter notebook: /shared/nilearn_ffx.ipynb
You can either run each cell separately (“Play”-Button at the top) after implementing the changes (if changes are needed), or first implement all changes and then run all cells automaticall (“Double-Play”-Button at the top)
- In the second cell (indicated with
[2]:
at the left), change:
data_dir
fmriprep_dir
task_label
(this refers to how your files are named! \(\to\) in your BIDS-valid naming of your file, what´s behind “task-” \(\to\) Forsub-12002_ses-1_task-loc_run-1_space-T1w_desc-preproc_bold.nii.gz
the correspondingtask_label
would beloc
\(\to\)task_label = "loc"
)sub_labels
After the comment
# Loop over sessions
: indicate the number of sessions, by “counting” from 1 to the number of sessions you did (if you did 4 sessions, the line should readfor ses in [1, 2, 3, 4]
)
In the third cell (indicated with
[3]:
at the left), change the number of sessions similar to step 1e)In the sixth cell (indicated with
[6]:
at the left):
Define your
constrasts
-dictionairy, by defining a name for each contrast (= key) and indicating how it is computed (= value)for indicating how a contrast is computed, you can access the columns of the design matrix (that should be printed above this cell). Keep in mind, that for
basic_contrasts[]
you indicate the actual name of the column, not the index!you can print the resulting contrasts matrices, but you don´t have to
- In the seventh cell (indicated with
[7]:
at the left):
define empty lists for each of your contrasts
change the respective names of the lists before the
.append
statementindicate the correct contrast names in the parameters of the
.compute_contrast
function
In the eighth cell (indicated with
[8]:
at the left): changecontrasts_dict
to match with your listsIn the second part of the eighth cell (somehow the enumeration is messed up there): comment out (using
#
) the line starting withdata_dir =
(since you should have writing access in your own directories and you already defineddata_dir
in the beginning of the script)
2 Volume-based Analysis
There is also a script for Volume-based Analysis