How to save beta maps from the first level GLM?

I am trying to use beta maps for second-level GLM analysis.
However, I cannot find a way to save the beta maps from the first-level GLM function. Does anyone know how to save the beta map as nii file?

I also found that nilearn default setting of the 2nd level ‘effect_size’ map. Is ‘effect size’ map beta map?

1 Like

Yes - see this code snippet in second-level analysis:

1 Like

Just to +1 @HaoTing_Wang 's answer, you can find this idea in the narrative documentation here :slightly_smiling_face:

https://nilearn.github.io/auto_examples/plot_single_subject_single_run.html#detecting-voxels-with-significant-effects

1 Like

I am also trying to understand this.

In the link there is:

1. Does this mean that in order to get a beta map (as the beta_xxxx.nii from SPM), we need to use effect_size as input argument?

2. And the z_score argument will produce the z-scored version of the t-map produced from the beta map?

  1. Pure beta maps will come from individual conditions (that is, those that go into a contrast). The effect size here would be analogous to the “con_XXX” maps from SPM.
  2. Yes. You have beta maps for your individual conditions, contrast maps for the difference between the beta maps, t-maps for the statistical significance of the contrasts, and z-maps for a normalized version of the t-maps. Outputting the z-score will get you directly to the last step, which will likely be useful for the next step in your analyses.

Hope this helps,
Steven

2 Likes

Clear. Thanks for clarifying this!

I’m sorry I have the same problem. I need a second-level GLM analysis between groups. Do I understand correctly that I need to save contrast maps between selected events at the first GLM level in order to calculate the contrast between groups at the second GLM level?

Excuse me, if you managed to perform a second-level analysis for fNIRS data, can you tell the sequence? Please , I 'm desperate , I can 't do anything

Hi Steven,

Something I don’t quite understand is how can nilearn output stat maps when only given a single regressor?

e.g.:

model.compute_contrast(condition_a,
                                            output_type='stat')

or

model.compute_contrast(condition_a,
                                            output_type='z_score')

how a statistics be computed when there is no contrast?

Hi @foldes.andrei,

Assuming this is still a first level model, the output will still be the beta coefficients for how well the signal corresponds to the event regressor convolved with the HRF. You may also see these referred to as “dummy regressors”.

Best,
Steven

Hi Steven,

Yes, first level model!

So…

model.compute_contrast(condition_a,
output_type=‘stat’) AND model.compute_contrast(condition_a,
output_type=‘z_score’) should be the same as model.compute_contrast(condition_a,
output_type=‘effect_size’)?

Given that they are beta coeffs and model.compute_contrast(condition_a,
output_type=‘effect_size’) should be the way to extract beta coeffs…

Not quite. The effect size are the beta coefficients. stat is the t-values, which is are betas scaled by the variance of the betas, and z_score are normalized t-values. Does that make sense, or did I misunderstand the question at all?

Best,
Steven

1 Like

I see! I think what was confusing is that in task fMRI studies usually t-values are reported when contrasting two conditions and betas are reported when… wanting to further illustrate said comparison or wanting to better understand interaction between >2 conditions.

So what’s really happening when running

model.compute_contrast(condition_a,
output_type=‘stat’)

is just …

SE_map = np.sqrt(effect_variance_map)
t_map = effect_size_map / SE_map

Relatedly, when wanting to better understand my group level 2 (condition with 2 levels) x 2 (condition with 2 levels) interaction I can just as well opt to plot the the t-statistics of the individual conditions, instead of the unscaled beta coefficients, right?