code: def check_residual_function(
      residual_function,
      predict_function,
      model,
      data,
      y,
      model_info,
      precalculate,
      verbose,
  ):
      if residual_function is None:
          # residual_function not specified
          # try the default
          def residual_function(_model, _data, _y):
              return _y - predict_function(_model, _data)
  
          verbose_cat(
              "  -> residual function : difference between y and yhat (default)",
              verbose=verbose,
          )
          model_info["residual_function_default"] = True
      else:
          verbose_cat(
              "  -> residual function : " + str(residual_function),
              verbose=verbose,
          )
          model_info["residual_function_default"] = False
  
      # if data is specified then we may test residual_function
      residuals = None
      if (
          data is not None
          and y is not None
          and (verbose or precalculate)
      ):
          try:
              residuals = residual_function(model, data, y)
              verbose_cat(
                  str.format(
                      "  -> residuals         : min = {0:.3}, mean = {1:.3}, max = {2:.3}",
                      np.min(residuals).astype(float),
                      np.mean(residuals).astype(float),
                      np.max(residuals).astype(float),
                  ),
                  verbose=verbose,
              )
          except (Exception, ValueError, TypeError) as error:
              verbose_cat(
                  "  -> residuals         :  'residual_function' returns an Error when executed:",
                  verbose=verbose,
              )
              print(error)
  
      return residual_function, residuals, model_info
  
imports: import numpy
  import pandas
  from copy import deepcopy
  from warnings import warn
  from .helper import verbose_cat, is_y_in_data, get_model_info
  from .yhat import get_predict_function_and_model_type
label_desc: Use image node_id 10 for calling a global function with example usage: check_residual_function(residual_function, predict_function, model, data, y, model_info, precalculate, verbose) and returns: residual_function,  residuals,  model_info, unknown