class_docstr: This class handles the so-called on General Linear Model
  
  Most of what it does in the fit() and contrast() methods
  fit() performs the standard two-step ('ols' then 'ar1') GLM fitting
  contrast() returns a contrast instance, yileding statistics and p-values.
  The link between fit() and contrast is done vis the two class members:
  
  glm_results : dictionary of nipy.algorithms.statistics.models.
               regression.RegressionResults instances,
               describing results of a GLM fit
  
  labels : array of shape(n_voxels),
          labels that associate each voxel with a results key
class_docstr_tok: ["This","class","handles","the","so-called","on","General","Linear","Model","Most","of","what","it","does","in","the","fit","(",")","and","contrast","(",")","methods","fit","(",")","performs","the","standard","two-step","(","'ols","'","then","'ar1","'",")","GLM","fitting","contrast","(",")","returns","a","contrast","instance",",","yileding","statistics","and","p-values",".","The","link","between","fit","(",")","and","contrast","is","done","vis","the","two","class","members",":","glm_results",":","dictionary","of","nipy.algorithms.statistics.models",".","regression.RegressionResults","instances",",","describing","results","of","a","GLM","fit","labels",":","array","of","shape","(","n_voxels",")",",","labels","that","associate","each","voxel","with","a","results","key"]
docstr: GLM fitting of a dataset using 'ols' regression or the two-pass
  
  Parameters
  ----------
  Y : array of shape(n_time_points, n_samples)
      the fMRI data
  model : {'ar1', 'ols'}, optional
      the temporal variance model. Defaults to 'ols'
  steps : int, optional
      Maximum number of discrete steps for the AR(1) coef histogram
docstr_tok: ["GLM","fitting","of","a","dataset","using","'ols","'","regression","or","the","two-pass","Parameters","--","--","--","--","--","Y",":","array","of","shape","(","n_time_points",",","n_samples",")","the","fMRI","data","model",":","{","'ar1","'",",","'ols","'","}",",","optional","the","temporal","variance","model",".","Defaults","to","'ols'","steps",":","int",",","optional","Maximum","number","of","discrete","steps","for","the","AR","(","1",")","coef","histogram"]
code: def fit(self, Y, model="ols", steps=100):
      """GLM fitting of a dataset using 'ols' regression or the two-pass
  
      Parameters
      ----------
      Y : array of shape(n_time_points, n_samples)
          the fMRI data
      model : {'ar1', 'ols'}, optional
          the temporal variance model. Defaults to 'ols'
      steps : int, optional
          Maximum number of discrete steps for the AR(1) coef histogram
      """
      if model not in ["ar1", "ols"]:
          raise ValueError("Unknown model")
  
      if Y.ndim == 1:
          Y = Y[:, np.newaxis]
  
      if Y.shape[0] != self.X.shape[0]:
          raise ValueError("Response and predictors are inconsistent")
  
      # fit the OLS model
      ols_result = OLSModel(self.X).fit(Y)
  
      # compute and discretize the AR1 coefs
      ar1 = (ols_result.resid[1:] * ols_result.resid[:-1]).sum(0) / (
          ols_result.resid**2
      ).sum(0)
      ar1 = (ar1 * steps).astype(np.int_) * 1.0 / steps
  
      # Fit the AR model according to current AR(1) estimates
      if model == "ar1":
          self.results_ = {}
          self.labels_ = ar1
          # fit the model
          for val in np.unique(self.labels_):
              m = ARModel(self.X, val)
              self.results_[val] = m.fit(Y[:, self.labels_ == val])
      else:
          self.labels_ = np.zeros(Y.shape[1])
          self.results_ = {0.0: ols_result}
  
imports: from warnings import warn
  import numpy
  import scipy.stats
  from nibabel import Nifti1Image, load
  from nipy.algorithms.statistics.models.regression import ARModel, OLSModel
  from nipy.algorithms.statistics.utils import multiple_mahalanobis, z_score
  from nipy.io.nibcompat import get_affine, get_header
  from nipy.labs.mask import compute_mask_sessions
label_desc: Use image node_id 2 for calling the GeneralLinearModel obj's underlying member method code with example usage: obj.fit(Y, model, steps) without return types