Model time series separately for first and second half

I’m following this nilearn tutorial and was wondering if would be possible to model the first half of resting state data separately from the second half?
The seed_time_series array([[-0.1719],[-0.2145],[-0.3262],...,[1.2215],[0.8738],[0.2069]]) has 176 values (88 in first half and 88 in second half).

My initial thought was to create two separate regressors like this:
vols – pcc1st – pcc_2nd
001 – -0.1719 – 0
002 – -0.2145 – 0
003 – -0.3262 – 0

174 – 0 – 1.2215
175 – 0 – 0.8738
176 – 0 – 0.2069

pcc_1st has zeros for vols>088 and pcc_2nd has zeros for vols<088, but this won’t work because the data are centered. Is there another way?


What you propose seems rather reasonable, but I fail to understand what your goal is in this analysis.

Another possibility would be to formally divide the 4D image into 2 4D images with half of the samples, and handle them as 2 different runs.

Thanks @bthirion. I would like to analyze connectivity for different segments of the time series (for example, first 20 min vs last 20 min).

But isn’t it a problem that the data are centered? So a 0 doesn’t really represent absence but rather the mean of the time series.

Yes, I suppose that would work provided that I have the exact number of samples for each regressor. However, if I intend to analyse the first third against the last 2/3 of rest for example, this method will not work…

No, this is not a problem, since correlation measures are sensitive to variations around the mean. The mean-0 part will have no impact on correlation measure.

1 Like

But then you can do a 1/3 - 2/3 split. This should amount to the same as the approach you propose.

1 Like

thanks @bthirion that was really very helpful. Just one more question, in centering, would you center the whole time series before or after dividing it into two halves?
For example, for the pcc_1st regressor in my example, would you (1) center the values from 001 to 176 and subsequently zero out the values ranging from 088 to 176, or (2) only center the values from 001 to 088 and zero out the rest?

I think the second solution is better, but I expect little difference between the two alternatives.

@bthirion, suppose I have 150 volumes and I wish to model the first 50 and last 50 volumes in one run, and the middle 50 volumes in another run.
I divided my volumes in the 4D image into two separate runs:

run_first_last = [vol1, vol2, ..., vol50, vol101, vol102, ..., vol150]
run_middle = [vol51, ..., vol100]

Then I simply included the time-courses within my ROI for the first/last volumes (run_first_last) in one design matrix, and the time-courses for the middle volumes (run_middle) in another design matrix.

fmri_glm =[run_first_last,run_middle], design_matrices=design_matrices)

Is that a reasonable approach?

Also what hrf_model should I select? For resting state data does it make sense to have an hrf model at all?

I think that what you propose to do is sound. You should not use an hrf because what you have in the design matrix is already a bold signal.

1 Like

That’s great @bthirion, thanks! Regarding contrasts, with one session I can simply do first_level.compute_contrast([1, -1]). How can I do the same contrast with two sessions?

My design matrices look like these (reg1,reg2 and reg3 are confound regressors):

    firstlast  reg1 reg2 reg3

    middle   reg1 reg2 reg3

I tried this

funcs = [images_first_last, images_middle]
design_matrices = [design_matrix_first_last, design_matrix_middle]

fmri_glm = FirstLevel()
fmri_glm =, design_matrices=design_matrices)
fmri_glm.compute_contrast([[1,0,0,0], [-1,0,0,0]])

This is comparing the time courses of firstlast with the time courses of middle, is that correct?

What this does is to estimate the two contrasts on the two runs sepaarately, and then to do a fixed effects on the contrasts. the computed parameters will indeed be the difference between the two parameters.

1 Like