Dear NeuroStars Community,
I’m seeking some help in figuring out why, when I compute contrasts through nilearn, I often get a “RuntimeWarning: divide by zero encountered in true_divide” arising from the function “positive_reciprocal(X)” in _utils.py.
I have attempted to debug. Digging around it seems to stem from the function compute T contrast of the RegressionResults object, but after that I couldn’t track what is happening under the hood… is there somewhere where I can actually see the problematic values?
For context, I run a first-level LSA GLM estimated with motion confounds and the contrasts are between single trials (1) of the various conditions (bunch of 0s for the rest) against baseline (-1), to be used later in MVPA classification.
I’d appreciate any contribution that may improve my insight on the whole process!
Hi @Stempio and welcome to neurostars!
It would help if you share some relevant code with us about how you set up your models.
Please format the code for readability using the <> button in the text editor or surrounding it with tickmarks
so it looks like this
Hi @Steven, thanks for your reply!!
So, the GLM is set up like this:
mod = glm.first_level.FirstLevelModel(
and the contrasts are set-up in this way, following the model fit, in a loop for each trial condition (‘con’):
for con in mod.design_matrices_.columns:
contrast_matrix = np.zeros(len(mod.design_matrices_.columns)) # reset contrast matrix
# baseline minus condition
contrast_matrix[baseline_index] = -1
contrast_matrix[np.where(mod.design_matrices_.columns == con)] = 1
The functional images and brain masks are in native T1w space, as outputted by fmri-prep.