code: def fit(
      self,
      Y,
      X,
      formula=None,
      axis=0,
      model="spherical",
      method=None,
      niter=2,
  ):
      if Y.shape[axis] != X.shape[0]:
          raise ValueError("Response and predictors are inconsistent")
  
      # Find model type
      self._axis = axis
      if isinstance(formula, str):
          model = "mfx"
      if model in models:
          self.model = model
          if method is None:
              self.method = models[model][0]
          elif models[model].count(method):
              self.method = method
          else:
              raise ValueError("Unknown method")
      else:
          raise ValueError("Unknown model")
  
      # Initialize fields
      constants = []
      a = 0
  
      # Switch on models / methods
      if self.model == "spherical":
          constants = ["nvbeta", "a"]
          if self.method == "ols":
              out = ols(Y, X, axis=axis)
          elif self.method == "kalman":
              out = kalman.ols(Y, X, axis=axis)
      elif self.model == "ar1":
          constants = ["a"]
          out = kalman.ar1(Y, X, axis=axis, niter=niter)
          a = out[4]
          out = out[0:4]
  
      # Finalize
      self.beta, self.nvbeta, self.s2, self.dof = out
      self.s2 = self.s2.squeeze()
      self.a = a
      self._constants = constants
  
imports: import numpy
  import scipy.stats
  from nipy.algorithms.statistics.utils import z_score
  from ..utils import mahalanobis
  from .None import kalman
label_desc: Use image node_id 2 for calling the glm obj's underlying member method code with example usage: obj.fit(Y, X, formula, axis, model, method, niter) without return types