Nilearn: GLM Betas from specific brain area as input for decoding analysis

Hi Everyone,
This is a very simple question (but hard for me, a nilearn beginner)…
If I have already run the whole brain GLM analysis and got a beta-map, then for the subsequent decoding analysis (training a classifier to distinguish multiple categories), how can I extract the betas only from specific brain areas (e.g., visual, frontal or hippocampus) to do this analysis? I have read some tutorials, but am still very confused on how to generate a mask to restrict the betas to specific brain areas.
Can anyone help me figure this out?
Thank you very much!
Sharon

Hi, if your betas are stored in an image (let’s call it beta image), then it should be easy to define a NiftiMasker object with the regions that are interesting for you and then transform the beta image through the NiftiMasker object in order to obtain betas restricted to the regions you are interested in.
But, then it depends on what you want to do with these values ?
Anyway, after NiftiMasker.transform(beta_image), you are left with Numpy arrays, which makes it easy to do whatever you want with these data.
Does that answer your question ?
Best,
Bertrand

Hi Bertrand,
Thanks for your reply! Sorry I lost track of it.
Yes, my betas are saved as a Niimag like object. I used NiftiMasker to create a masker to restrict my betas to interesting regions.
To use the decoder defined in Nilearn, I implemented the following three commands:

beta_images = nib.load(z_maps_filename)
masked_data = masker.fit_transform(beta_images)
inverse_transformed_data = masker.inverse_transform(masked_data)

Does this make sense to you? Or do you suggest using the NiftiMasker.transform(beta_image) directly?
Best,
Sharon

This looks good indeed.
Note that you need to fit the masker at least once in order to use the transform method.
Best,

1 Like