Script demonstrating differences in GLM modelling approaches between SPM and FSL:
import numpy as np
from nipy.modalities.fmri.glm import GeneralLinearModel
# Simulated data (20 'rest' volumes followed by 20 'task' volumes)
Y = np.hstack((np.random.normal(4200, 50, size=20),
np.random.normal(4300, 50, size=20)))
# SPM-style GLM
X = np.array([[0] * 20 + [1] * 20, # model 'task'
[1] * 40]).T # + constant
model = GeneralLinearModel(X)
model.fit(Y) # fit model to data
con = model.contrast(np.array([1, 0])) # test for task effect
print(f"SPM: {con.effect[0,0]:.2f} (z = {con.z_score()[0]:.2f})")
# FSL-style GLM
Y -= np.mean(Y) # demean signal
X = np.array([[0.0] * 20 + [1.0] * 20]).T # model 'task' only (no constant)
X -= np.mean(X, axis=0) # demean model
model = GeneralLinearModel(X)
model.fit(Y) # fit demeaned model to demeaned data
con = model.contrast(np.array([1])) # test for task effect
print(f"FSL: {con.effect[0,0]:.2f} (z = {con.z_score()[0]:.2f})")
Output:
SPM: 121.71 (z = 6.51)
FSL: 121.71 (z = 6.60)