-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] cannot use dataframe as input for second level GLM #3871
Comments
I think this reproduces the bug import pandas as pd
from nilearn.glm.second_level import SecondLevelModel
from nilearn._utils.data_gen import write_fake_fmri_data_and_design
# need a random file fmri_run0.nii
write_fake_fmri_data_and_design(shapes=((7, 8, 7, 15), (7, 8, 7, 16)))
df = pd.DataFrame(data={"effects_map_path" : ["fmri_run0.nii"], "map_name" : ["tmp"], "subject_label" : ["sub1"]})
slm = SecondLevelModel().fit(second_level_input=df)
slm.compute_contrast()
|
Went and looked into our test suite to see how we test this and here is something that works import pandas as pd
from nilearn.glm.second_level import SecondLevelModel
from nilearn._utils.data_gen import write_fake_fmri_data_and_design
shapes = ((7, 8, 9, 10),)
_, FUNCFILE, _ = write_fake_fmri_data_and_design(shapes)
FUNCFILE = FUNCFILE[0]
dfcols = ["subject_label", "map_name", "effects_map_path"]
dfrows = [
["01", "a", FUNCFILE],
["02", "a", FUNCFILE],
["03", "a", FUNCFILE],
]
niidf = pd.DataFrame(dfrows, columns=dfcols)
# dataframes as input
SecondLevelModel().fit(niidf) |
extracted from here:
|
my bad this does not work when you compute a contrast on the model |
Thx for reporting. |
It seems that the bug comes from the call to _check_first_level_contrast, the function tries to check if the first element of second_level_input is an instance of FirstLevelModel since than the first_level_contrast argument is needed to compute the contrast. An easy fix would just to first check if the second_level_input is a list: |
OK. Do you want to contribute it ? |
Is there an existing issue for this?
Operating system
Operating system version
Python version
nilearn version
Expected behavior
Using unlearn.glm.second_level.SecondLevelModel with panda.DataFrame as input I get an error when computing the contrast because the code checks the first element of the second_level_input to see if it is a FirstLevelModel. The problem is when the second_level_input is a DataFrame, a key error is generated. See below:
Current behavior & error messages
This is what I got:
Steps and code to reproduce bug
The text was updated successfully, but these errors were encountered: