Z-maps manipulation for different contrasts in NiLearn

Hello, I am new to fMRI data analysis and following standard tutorials for data processing. But since the

I have two fmriprep preprocessed fMRI in two separate files: fmri1 and fmri2. fmri1 is for condition 1, fmri2 is for condition 2. Using nilearn, I can compute z-map contrasts where condition 1 is active and condition 2 is active, i.e. “condition 1 is 1, and others are 0”, and “condition 2 is 1, and others are 0”

If I want to compute contrasts where “condition 1 is 1, condition 2 is -1, and others are 0”, does it make sense to subtract the z-map where condition 2 is active from the z-map where condition 1 is active?

Hi @slavaheroes and welcome to neurostars!

You typically do not want this, where you two condition of interests come from different runs, since there may be differences in scanner signal between acquisitions due to low-frequency drift and scanner heat. Usually, all conditions you want to compare against each other are in a run (in some block-related or event-related design).

Due to the limitations stated before, if you do want to make a comparison like this, you would want to do everything in a single model while controlling for scanner differences (and not due this subtraction post-hoc as you propose). So, one option is to concatenate your timeseries and design matrices, and include a column in the design matrices for acqusition_1 and acquisition_2, that contain 1s in rows that belong to their respective acquisitions, and 0 otherwise.


Thank you for your response!
I’ve also referenced your solution on this topic.

I have concatenated fMRI using Nilearn’s concat images:

concated_clean_fmri = nimg.concat_imgs([clean_rest_fmri, clean_session_fmri], auto_resample=True)

And concatenated design matrices as below:

And I computed contrast with the following contrast vector: (I wanted to do ‘session - rest’ contrast)

Is my approach correct? I am a bit worried about the fMRI concatenation step

Hi @slavaheroes,

Some issues:

  1. You have cosine and drift terms. Both should act as a high pass filter - so you do not need both. Since you are using a_comp_cor terms, you should use cosine terms.
  2. It looks like your task runs the entire session, which is not good for running GLMs. You usually want some kind of block of event-related design.
  3. You have two constant terms (it should just be one column with all 1s)


Thank you for your feedback!