def glm(image_ts, regressors): ''' image_ts should be a matrix of the form (t x v) where t is the no. of timepoints and v is the no. of voxels regressors should be a matrix of the form (t x n) where t is the no. of timepoints and n is the number of regressors ------------------ beta output is a serie of beta vector of the form (n x v). ''' Y = image_ts if len(regressors.shape) == 1: X = np.expand_dims(regressors, axis=1) else: X = regressors glm_dist = GeneralLinearModel(X) glm_dist.transform(Y) beta = glm_dist.get_beta() return beta
def global_signal_regression(timeserie, regressor): #Get timeseries data Y = timeserie.data.T X = np.expand_dims(regressor, axis=1) glm_dist = GeneralLinearModel(X) glm_dist.transform(Y) beta_dist = glm_dist.get_beta() r_signal = np.dot(X, beta_dist) regressed_s = Y - r_signal return regressed_s