code: def output_resid(outfile, fmri_image, clobber=False):
      """
      Create an output file of the residuals parameter from the OLS pass of
      fmristat.
  
      Uses affine part of the first image to output resids unless
      fmri_image is an Image.
  
      Parameters
      ----------
      outfile :
      fmri_image : ``FmriImageList`` or 4D image
         If ``FmriImageList``, needs attributes ``volume_start_times``,
         supports len(), and object[0] has attributes ``affine``,
         ``coordmap`` and ``shape``, from which we create a new 4D
         coordmap and shape
         If 4D image, use the images coordmap and shape
      clobber : bool
         if True, overwrite previous output
  
      Returns
      -------
      regression_output :
      """
      if isinstance(fmri_image, FmriImageList):
          n = len(fmri_image.list)
          T = np.zeros((5, 5))
          g = fmri_image[0].coordmap
          T[1:, 1:] = fmri_image[0].affine
          T[0, 0] = (
              fmri_image.volume_start_times[1:]
              - fmri_image.volume_start_times[:-1]
          ).mean()
          # FIXME: NIFTI specific naming here
          innames = ["t"] + list(g.function_domain.coord_names)
          outnames = ["t"] + list(g.function_range.coord_names)
          cmap = AffineTransform.from_params(innames, outnames, T)
          shape = (n,) + fmri_image[0].shape
      elif isinstance(fmri_image, Image):
          cmap = fmri_image.coordmap
          shape = fmri_image.shape
      else:
          raise ValueError("expecting FmriImageList or 4d Image")
  
      outim = ModelOutputImage(outfile, cmap, shape, clobber=clobber)
      return outputters.RegressionOutput(outim, outputters.output_resid)
  
imports: import copy
  from os import path
  import numpy
  import numpy.linalg
  from nipy.algorithms.statistics.formula import make_recarray
  from nipy.algorithms.statistics.models.regression import ARModel, OLSModel, ar_bias_correct, ar_bias_corrector
  from nipy.core.api import AffineTransform, Image, matrix_generator, parcels
  from nipy.io.api import save_image
  from ..api import FmriImageList, axis0_generator
  from .None import outputters
label_desc: Use image node_id 7 for calling a global function with example usage: output_resid(outfile, fmri_image, clobber) and returns: outputters