class_docstr: Implement the :term:`General Linear Model<GLM>` for multiple     subject :term:`fMRI` data.
  
  Parameters
  ----------
  mask_img : Niimg-like, :class:`~nilearn.maskers.NiftiMasker` or             :class:`~nilearn.maskers.MultiNiftiMasker`, optional
      Mask to be used on data. If an instance of masker is passed,
      then its mask will be used. If no mask is given,
      it will be computed automatically by a
      :class:`~nilearn.maskers.MultiNiftiMasker` with default
      parameters. Automatic mask computation assumes first level imgs have
      already been masked.
  %(target_affine)s
  
      .. note::
          This parameter is passed to :func:`nilearn.image.resample_img`.
  
  %(target_shape)s
  
      .. note::
          This parameter is passed to :func:`nilearn.image.resample_img`.
  
  %(smoothing_fwhm)s
  %(memory)s
  %(memory_level1)s
  %(verbose0)s
      If 0 prints nothing. If 1 prints final computation time.
      If 2 prints masker computation details.
  %(n_jobs)s
  minimize_memory : :obj:`bool`, default=True
      Gets rid of some variables on the model fit results that are not
      necessary for contrast computation and would only be useful for
      further inspection of model details. This has an important impact
      on memory consumption.
class_docstr_tok: ["Implement","the",":","term",":","`","General","Linear","Model","<","GLM",">","`","for","multiple","subject",":","term",":","`","fMRI","`","data",".","Parameters","--","--","--","--","--","mask_img",":","Niimg-like",",",":","class",":","`","~nilearn.maskers.NiftiMasker","`","or",":","class",":","`","~nilearn.maskers.MultiNiftiMasker","`",",","optional","Mask","to","be","used","on","data",".","If","an","instance","of","masker","is","passed",",","then","its","mask","will","be","used",".","If","no","mask","is","given",",","it","will","be","computed","automatically","by","a",":","class",":","`","~nilearn.maskers.MultiNiftiMasker","`","with","default","parameters",".","Automatic","mask","computation","assumes","first","level","imgs","have","already","been","masked",".","%","(","target_affine",")","s","..","note",":",":","This","parameter","is","passed","to",":","func",":","`","nilearn.image.resample_img","`",".","%","(","target_shape",")","s","..","note",":",":","This","parameter","is","passed","to",":","func",":","`","nilearn.image.resample_img","`",".","%","(","smoothing_fwhm",")","s","%","(","memory",")","s","%","(","memory_level1",")","s","%","(","verbose0",")","s","If","0","prints","nothing",".","If","1","prints","final","computation","time",".","If","2","prints","masker","computation","details",".","%","(","n_jobs",")","s","minimize_memory",":",":","obj",":","`","bool","`",",","default=True","Gets","rid","of","some","variables","on","the","model","fit","results","that","are","not","necessary","for","contrast","computation","and","would","only","be","useful","for","further","inspection","of","model","details",".","This","has","an","important","impact","on","memory","consumption","."]
docstr: Fit the second-level :term:`GLM`.
  
  1. create design matrix
  2. do a masker job: fMRI_data -> Y
  3. fit regression to (Y, X)
  
  Parameters
  ----------
  %(second_level_input)s
  confounds : :class:`pandas.DataFrame`, optional
      Must contain a ``subject_label`` column. All other columns are
      considered as confounds and included in the model. If
      ``design_matrix`` is provided then this argument is ignored.
      The resulting second level design matrix uses the same column
      names as in the given :class:`~pandas.DataFrame` for confounds.
      At least two columns are expected, ``subject_label`` and at
      least one confound.
  
  design_matrix : :class:`pandas.DataFrame`, optional
      Design matrix to fit the :term:`GLM`. The number of rows
      in the design matrix must agree with the number of maps derived
      from ``second_level_input``.
      Ensure that the order of maps given by a ``second_level_input``
      list of Niimgs matches the order of the rows in the design matrix.
docstr_tok: ["Fit","the","second-level",":","term",":","`","GLM","`",".","1.","create","design","matrix","2.","do","a","masker","job",":","fMRI_data","-",">","Y","3.","fit","regression","to","(","Y",",","X",")","Parameters","--","--","--","--","--","%","(","second_level_input",")","s","confounds",":",":","class",":","`","pandas.DataFrame","`",",","optional","Must","contain","a","``","subject_label","``","column",".","All","other","columns","are","considered","as","confounds","and","included","in","the","model",".","If","``","design_matrix","``","is","provided","then","this","argument","is","ignored",".","The","resulting","second","level","design","matrix","uses","the","same","column","names","as","in","the","given",":","class",":","`","~pandas.DataFrame","`","for","confounds",".","At","least","two","columns","are","expected",",","``","subject_label","``","and","at","least","one","confound",".","design_matrix",":",":","class",":","`","pandas.DataFrame","`",",","optional","Design","matrix","to","fit","the",":","term",":","`","GLM","`",".","The","number","of","rows","in","the","design","matrix","must","agree","with","the","number","of","maps","derived","from","``","second_level_input","``",".","Ensure","that","the","order","of","maps","given","by","a","``","second_level_input","``","list","of","Niimgs","matches","the","order","of","the","rows","in","the","design","matrix","."]
code: def fit(self, second_level_input, confounds=None, design_matrix=None):
      """Fit the second-level :term:`GLM`.
  
      1. create design matrix
      2. do a masker job: fMRI_data -> Y
      3. fit regression to (Y, X)
  
      Parameters
      ----------
      %(second_level_input)s
      confounds : :class:`pandas.DataFrame`, optional
          Must contain a ``subject_label`` column. All other columns are
          considered as confounds and included in the model. If
          ``design_matrix`` is provided then this argument is ignored.
          The resulting second level design matrix uses the same column
          names as in the given :class:`~pandas.DataFrame` for confounds.
          At least two columns are expected, ``subject_label`` and at
          least one confound.
  
      design_matrix : :class:`pandas.DataFrame`, optional
          Design matrix to fit the :term:`GLM`. The number of rows
          in the design matrix must agree with the number of maps derived
          from ``second_level_input``.
          Ensure that the order of maps given by a ``second_level_input``
          list of Niimgs matches the order of the rows in the design matrix.
  
      """
      # check second_level_input
      _check_second_level_input(
          second_level_input, design_matrix, confounds=confounds
      )
  
      # check confounds
      _check_confounds(confounds)
  
      # check design matrix
      _check_design_matrix(design_matrix)
  
      if isinstance(second_level_input, pd.DataFrame):
          second_level_input = _sort_input_dataframe(second_level_input)
      self.second_level_input_ = second_level_input
      self.confounds_ = confounds
      sample_map, subjects_label = _process_second_level_input(
          second_level_input
      )
  
      # Report progress
      t0 = time.time()
      if self.verbose > 0:
          sys.stderr.write(
              "Fitting second level model. Take a deep breath.\r"
          )
  
      # Create and set design matrix, if not given
      if design_matrix is None:
          design_matrix = make_second_level_design_matrix(
              subjects_label, confounds
          )
      self.design_matrix_ = design_matrix
  
      # Learn the mask. Assume the first level imgs have been masked.
      if not isinstance(self.mask_img, NiftiMasker):
          self.masker_ = NiftiMasker(
              mask_img=self.mask_img,
              target_affine=self.target_affine,
              target_shape=self.target_shape,
              smoothing_fwhm=self.smoothing_fwhm,
              memory=self.memory,
              verbose=max(0, self.verbose - 1),
              memory_level=self.memory_level,
          )
      else:
          self.masker_ = clone(self.mask_img)
          for param_name in [
              "smoothing_fwhm",
              "memory",
              "memory_level",
          ]:
              our_param = getattr(self, param_name)
              if our_param is None:
                  continue
              if getattr(self.masker_, param_name) is not None:
                  warn(
                      f"Parameter {param_name} of the masker overridden"
                  )
              setattr(self.masker_, param_name, our_param)
      self.masker_.fit(sample_map)
  
      # Report progress
      if self.verbose > 0:
          sys.stderr.write(
              "\nComputation of second level model done in "
              f"{time.time() - t0} seconds.\n"
          )
  
      return self
  
imports: import sys
  import time
  from warnings import warn
  import numpy
  import pandas
  from joblib import Memory
  from nibabel import Nifti1Image
  from sklearn.base import clone
  from nilearn._utils import fill_doc, stringify_path
  from nilearn._utils.niimg_conversions import check_niimg
  from nilearn.glm._base import BaseGLM
  from nilearn.glm.contrasts import compute_contrast, expression_to_contrast_vector
  from nilearn.glm.first_level import FirstLevelModel, run_glm
  from nilearn.glm.first_level.design_matrix import make_second_level_design_matrix
  from nilearn.glm.regression import RegressionResults, SimpleRegressionResults
  from nilearn.image import mean_img
  from nilearn.maskers import NiftiMasker
  from nilearn.mass_univariate import permuted_ols
label_desc: Use image node_id 2 for calling the SecondLevelModel obj's underlying member method code with example usage: obj.fit(second_level_input, confounds, design_matrix) and returns: self