Mixed model with nilearn

Hi, I would like to execute a mixed model with nilearn to my fMRI data. In my experiment, participants executed a psychomotor task in 4 conditions (2 levels of force x 2 temperatures), for a total of 48 trials divided in 4 runs. The four conditions are: hand contraction at 5% of force during painful or warm temperature, hand contraction at 30% of force during painful or warm temperature. I computed the 1st level model analysis, so I have the individual activation for each defined contrast. Now I need to execute the group analisys. I would like to understand better the 2nd level model analysis with nilearn, I found this tutorial:

which account for the random effect of the subjects but I would like also to account for the random effect of runs. Do you have any solutions?
Thanks a lot for your help.

If you want to check the effect of the run you will need to have one contrast image per run: this example may help you figure out how to get those: Simple example of two-runs fMRI model fitting - Nilearn

you will then need to construct a second level design matrices with regressors that also encode which run each image corresponds too.

Hi, thanks for the answer. So it means that I will have runs x participants number of columns ? So sub-01_run-01, sub-01_run-02, sub-01_run-03, …, sub-02_run-01, sub-02_run-02, …

Thanks again

not quite

in the example you linked to you have 1 regressor for the “contrast”, and then one per subject n=16

in the analysis you want to do (assuming you have n sujects and m runs per subject), you would have 1 regressor for the contrast, n regressors for the subjects and m regressors for the runs.