First-level modeling in NiLearn, Conditions come from Different Runs

Hi,

I have three .niis from the same session, two of these contain condition A, and the third contains condition B. I want to produce subject level t/z maps for A > B and B > A. Following the tutorial here, I was able to make design matrices individually for the three runs and can fit the GLM. However, I am now running into troubles defining the contrasts for a few reasons: 1) the design matrices are different sizes between the condition A and B runs since they are different lengths, 2) I don’t see how I can define a contrast vector, since the conditions I am interested in may be the first conditions of the given runs. That is, I can’t think of a way to make one-hot encoded vectors unique to my contrasts, unless I make them 2D which I’m not sure Nilearn would accept.

Does anyone have any advice about how to proceed in this case?
Thanks,
Steven

2 Likes

Not sure I understand properly. Do you means that A and B are observed in different runs and that you want to combine them a posteriori to get a contrast ?
IIUC this is something unusual, and that should be avoided, because it conflates a run effect with a condition effect. I don’t see a good solution to your case, sorry.
Bertrand

1 Like

Hi Bertrand,

Thanks for the response.

Yes, runs 1-2 contained condition A (and other conditions not of interest) and run 3 contained condition B (and other conditions not of interest).

Would it not make sense to include all runs in a single design matrix and include some kind of regressor to normalize between runs?

Thanks,
Steven

Just to get more specific, in the picture below, I want to contrast the conditions “arith_Large” in runs 1 and 2 with “Word_Rhyme” in run 3. Is this design matrix invalid? The GLM was fit on the three runs concatenated with a concatenated design matrix as seen below. The individual runs were zero padded in times when they were not active. Would a contrast matrix for arith_Large vs Word_Rhyme have 0.5 where arith_Large is active (since it happens in two columns) and -1 when word_rhyme is active (and 0s everywhere else)?

@bthirion

It seems like in this thread you note the possibility of making a diagonal design matrix, or alternatively a fixed effect model, as in the tutorial here.

  1. If I do the diagonal design matrix, did I set it up correctly in the picture above? Since the first two blocks are the same size and have the same regressor names can I just vertically stack them?
  2. If I do the fixed effect model, should the effect I use for a given session be for A > Baseline or B > Baseline, or can I use just the effect of A/B?

Thanks,
Steven

I think that technically, your solution with a block design matrix solves your problem (I can only acknowledge your creativity :grinning:). In a perfect world, where scanners are reliable and brain signals are well-behaved, there is no big problem with this approach.
You should simply be aware that there may be some drifts across runs (due to tiredness or any type of instability), so that part of the difference you see between contrasts may be attributable to a run effect. It’s your responsbility to interpret these values with caution.
I would not stack vertically the first two blocks, to better fit signals variations, whether wanted (task effects) or not (drifts, motion).
Best,
Bertrand

2 Likes

Got it, thanks! Initial testing looks okay. This is reading > face match contrast and looks to be about what I expect (more reading on the left. more faces on the right).

Similarly for math > reading, looks to be more left sided and occipital activation in reading, and more prefrontal and occipital activation in math.

Will definitely keep in mind the limitations of this approach, and thanks again for the insight!

Best,
Steven

@Steven Hi Steven, I’m very new to Nilearn and python in general but I am trying to create a block design matrix just like yours, do you mind sharing with me how you did it?

Until now I concatenated my design matrices (2 sessions, 3 runs each) and I was trying to follow the tutorial for creating a block design matrix here: Nilearn: Statistical Analysis for NeuroImaging in Python — Machine learning for NeuroImaging

But I couldn’t implement it in my code. I wanted to create a design matrix for each session showing 3 runs just like yours.

Thank you

Hi @Merve,

I actually now do most of my first-level modeling in Fitlins, since it is developed against fMRIPrep derivatives (and I mainly use fMRIPrep for preprocessing). If you would want help on this, feel free to reach out or start a new thread!

Best,
Steven

1 Like