Dear Bthirion,
Thanks for your reply!
I got the idea of inserting a column of 0s from Steven‘s answer in this post (I also saw your post beneath saying you did not use this approach though
)
I also tried running without padding a column of 0s. In one of my subjects, I have 21 regressors in one run, and 20 regressors in another 3 runs, which leads to an inconsistent number of columns in design matrices across 4 runs. This is how I generated a design matrix of each run:
def make_contrasts(design_matrix):
contrast_matrix = np.eye(design_matrix.shape[1])
contrasts = {
column: contrast_matrix[i]
for i, column in enumerate(design_matrix.columns)
}
contrasts["decision_short - decision_long"] = (
contrasts["decision_short"] - contrasts["decision_long"]
)
contrasts["decision_long - decision_short"] = (
contrasts["decision_long"] - contrasts["decision_short"]
)
contrasts["confirmation_short - confirmation_long"] = (
contrasts["confirmation_short"] - contrasts["confirmation_long"]
)
contrasts["confirmation_long - confirmation_short"] = (
contrasts["confirmation_long"] - contrasts["confirmation_short"]
)
return contrasts
Then when I fitted the model, I got this warning message:
/Users/shengjie/Library/CloudStorage/OneDrive-UGent/Collabration/DelayDiscounting_Jenya/code/GLM.py:122: UserWarning: One contrast given, assuming it for all 4 runs
summary_statisticsNew = fmri_glm.compute_contrast(
/Users/shengjie/anaconda3/lib/python3.11/site-packages/nilearn/glm/contrasts.py:108: UserWarning: t contrasts should be of length P=22, but it has length 21. The rest of the contrast was padded with zeros.
reg = regression_result[label_].Tcontrast(con_val)
I got the final results without crashing. Also I am thinking if I define contrasts symbolically, I might have the same message because of the inconsistence of design matrices’ column numbers. Can I ignore this warning and assume everything is correct here?
Thanks again for your help!
Best,
Shengjie