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: Transform RegressionResults instances within a dictionary         (whose keys represent the autoregressive coefficient under the 'ar1'         noise model or only 0.0 under 'ols' noise_model and values are the         RegressionResults instances) into input nifti space.
  
  Parameters
  ----------
  attribute : str
      an attribute of a RegressionResults instance.
      possible values include: 'residuals', 'normalized_residuals',
      'predicted', SSE, r_square, MSE.
  
  result_as_time_series : bool
      whether the RegressionResult attribute has a value
      per timepoint of the input nifti image.
  
  Returns
  -------
  output : list
      A list of Nifti1Image(s).
docstr_tok: ["Transform","RegressionResults","instances","within","a","dictionary","(","whose","keys","represent","the","autoregressive","coefficient","under","the","'ar1","'","noise","model","or","only","0.0","under","'ols","'","noise_model","and","values","are","the","RegressionResults","instances",")","into","input","nifti","space",".","Parameters","--","--","--","--","--","attribute",":","str","an","attribute","of","a","RegressionResults","instance",".","possible","values","include",":","'residuals","'",",","'normalized_residuals","'",",","'predicted","'",",","SSE",",","r_square",",","MSE",".","result_as_time_series",":","bool","whether","the","RegressionResult","attribute","has","a","value","per","timepoint","of","the","input","nifti","image",".","Returns","--","--","--","-","output",":","list","A","list","of","Nifti1Image","(","s",")","."]
code: def _get_voxelwise_model_attribute(
      self, attribute, result_as_time_series
  ):
      """Transform RegressionResults instances within a dictionary \
          (whose keys represent the autoregressive coefficient under the 'ar1' \
          noise model or only 0.0 under 'ols' noise_model and values are the \
          RegressionResults instances) into input nifti space.
  
          Parameters
          ----------
          attribute : str
              an attribute of a RegressionResults instance.
              possible values include: 'residuals', 'normalized_residuals',
              'predicted', SSE, r_square, MSE.
  
          result_as_time_series : bool
              whether the RegressionResult attribute has a value
              per timepoint of the input nifti image.
  
          Returns
          -------
          output : list
              A list of Nifti1Image(s).
  
          """
      # check if valid attribute is being accessed.
      all_attributes = dict(vars(RegressionResults)).keys()
      possible_attributes = [
          prop for prop in all_attributes if "__" not in prop
      ]
      if attribute not in possible_attributes:
          msg = f"attribute must be one of: {possible_attributes}"
          raise ValueError(msg)
  
      if self.minimize_memory:
          raise ValueError(
              "To access voxelwise attributes like "
              "R-squared, residuals, and predictions, "
              "the `SecondLevelModel`-object needs to store "
              "there attributes. "
              "To do so, set `minimize_memory` to `False` "
              "when initializing the `SecondLevelModel`-object."
          )
  
      if self.labels_ is None or self.results_ is None:
          raise ValueError(
              "The model has no results. This could be "
              "because the model has not been fitted yet "
              "or because no contrast has been computed "
              "already."
          )
  
      if result_as_time_series:
          voxelwise_attribute = np.zeros(
              (self.design_matrix_.shape[0], len(self.labels_))
          )
      else:
          voxelwise_attribute = np.zeros((1, len(self.labels_)))
  
      for label_ in self.results_:
          label_mask = self.labels_ == label_
          voxelwise_attribute[:, label_mask] = getattr(
              self.results_[label_], attribute
          )
      return self.masker_.inverse_transform(voxelwise_attribute)
  
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 4 for calling the SecondLevelModel obj's underlying member method code with example usage: obj._get_voxelwise_model_attribute(attribute, result_as_time_series) and returns: self