Comparing contrasts (zmaps) between runs of a single subject

Hello,
I am wondering wether I should use a Second Level Model to compare zmaps between runs of a single subject and what alpha I should use.
For instance I would like to compare a constrast between run 4 with run 1.

Thanks for you help

Hi @Laura24 and welcome to neurostars!

Yes

That’s a pretty loaded question (see Type I and Type II error concerns in fMRI research: re-balancing the scale | Social Cognitive and Affective Neuroscience | Oxford Academic and https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6314595/), but a safe bet would be 0.05 FDR-corrected.

Also, you’ll want to use the effect size (betas) as inputs to your second level model, not z-maps as the post title implies.

Best,
Steven

Thanks! Is this code correct?

contrast_val_sub2_run1_regneu = [np.array([[-1, 1]])]  # Regulation vs. Neutre for Run 1
contrast_val_sub2_run10_regneu = [np.array([[-1, 1]])]  # Regulation vs. Neutre for Run 10

eff_map_run1 = first_level_model_sub2_ses1_run1.compute_contrast(contrast_val_sub2_run1_regneu, output_type='effect_size')
eff_map_run10 = first_level_model_sub2_ses3_run4.compute_contrast(contrast_val_sub2_run10_regneu, output_type='effect_size')

# Create a list of effect maps from the first-level models
eff_maps = [eff_map_run1, eff_map_run10]

# Create a design matrix for the second-level model
n_runs = len(eff_maps)
design_matrix = pd.DataFrame([-1, 1], columns=['intercept'])  # Run 10 - Run 1

# Specify the second-level model and fit it
second_level_model = SecondLevelModel(n_jobs=1)
second_level_model = second_level_model.fit(eff_maps, design_matrix=design_matrix)

# Estimate the contrast between the runs
beta_run10_vs_run1_regneu = second_level_model.compute_contrast('intercept', output_type='effect_size')

# Apply the FPR correction with a cluster threshold
thresholded_img_run10_vs_run1_regneu, threshold = threshold_stats_img(
    beta_run10_vs_run1_regneu,
    alpha=0.05,
    cluster_threshold=10,
    two_sided=False
)

I don’t seem to achieve putting fdr correction, the output is TypeError: bad operand type for unary -: ‘Nifti1Image’

Hi @Laura24,

In future posts, please format code for readability using tickmarks (`) or by using the </> button in the text editor, so it looks nice like this or

like this

. You can see I did it for you this time.

You can see this tutorial for how to implement FDR correction (Statistical testing of a second-level analysis - Nilearn).

I can only speak to your code on a superficial level since I don’t have access to any data and do not see how your first level models were created, but it looks fine. I will note that I would not use two_sided in the thresholding unless you have a good reason to, and sometimes people will add mean FD to the second level design matrix.

Best,
Steven