@@ -901,7 +901,7 @@ def regress(self, noise_model="ols", **kwargs):
901901 ResultsContainer: with keys for each convolved column of `.X` and values as `Brain_Data` objects of the GLM statistics
902902 """
903903 # Avoid circular import
904- from .results import ResultsContainer
904+ from .results import Brain_Collection
905905
906906 if not isinstance (self .X , pd .DataFrame ):
907907 raise ValueError ("Make sure self.X is a pandas DataFrame." )
@@ -927,19 +927,45 @@ def regress(self, noise_model="ols", **kwargs):
927927 drift_model = drift_model ,
928928 signal_scaling = signal_scaling ,
929929 noise_model = noise_model ,
930+ minimize_memory = False ,
930931 )
931932 glm .fit (self .to_nifti (), design_matrices = self .X )
932933 self .glm = glm
933934
934935 # Assemble results
935936 regressors_of_interest = self .X .convolved
936- results = {
937- r : ResultsContainer (
938- glm .compute_contrast (r , stat_type = stat_type , output_type = output_type )
939- )
940- for r in regressors_of_interest
937+ nltools2nilearn = {
938+ "t" : "stat" ,
939+ "p" : "p_value" ,
940+ "beta" : "effect_size" ,
941+ "se" : "effect_variance" ,
942+ "z_score" : "z_score" ,
941943 }
942- return results
944+ all_results = dict (
945+ z_score = Brain_Data (),
946+ t = Brain_Data (),
947+ p = Brain_Data (),
948+ beta = Brain_Data (),
949+ se = Brain_Data (),
950+ )
951+ for r in regressors_of_interest :
952+ # This a dictionary of niftis of different statistics
953+ result = glm .compute_contrast (
954+ r , stat_type = stat_type , output_type = output_type
955+ )
956+ # Which we convert to our naming format for backwards compatibility
957+ for k in all_results .keys ():
958+ all_results [k ] = all_results [k ].append (
959+ Brain_Data (result [nltools2nilearn [k ]])
960+ )
961+
962+ # These are single-item lists
963+ all_results ["rsquared" ] = Brain_Data (glm .r_square [0 ])
964+ all_results ["predicted" ] = Brain_Data (glm .predicted [0 ])
965+ all_results ["residual" ] = Brain_Data (glm .residuals [0 ])
966+ all_results ["regressors" ] = regressors_of_interest
967+
968+ return Brain_Collection (all_results )
943969
944970 def randomise (
945971 self , n_permute = 5000 , threshold_dict = None , return_mask = False , ** kwargs
@@ -2053,6 +2079,7 @@ def aggregate(self, mask, func):
20532079 values = dat .apply (func )
20542080 return dat .combine (values )
20552081
2082+ # TODO: replace with nilearn.glm.threshold_stats_img
20562083 def threshold (self , upper = None , lower = None , binarize = False , coerce_nan = True ):
20572084 """Threshold Brain_Data instance. Provide upper and lower values or
20582085 percentages to perform two-sided thresholding. Binarize will return
0 commit comments