code: def durbin_watson(resids, axis=0):
      r"""
      Calculates the Durbin-Watson statistic.
  
      Parameters
      ----------
      resids : array_like
          Data for which to compute the Durbin-Watson statistic. Usually
          regression model residuals.
      axis : int, optional
          Axis to use if data has more than 1 dimension. Default is 0.
  
      Returns
      -------
      dw : float, array_like
          The Durbin-Watson statistic.
  
      Notes
      -----
      The null hypothesis of the test is that there is no serial correlation
      in the residuals.
      The Durbin-Watson test statistic is defined as:
  
      .. math::
  
         \sum_{t=2}^T((e_t - e_{t-1})^2)/\sum_{t=1}^Te_t^2
  
      The test statistic is approximately equal to 2*(1-r) where ``r`` is the
      sample autocorrelation of the residuals. Thus, for r == 0, indicating no
      serial correlation, the test statistic equals 2. This statistic will
      always be between 0 and 4. The closer to 0 the statistic, the more
      evidence for positive serial correlation. The closer to 4, the more
      evidence for negative serial correlation.
      """
      resids = np.asarray(resids)
      diff_resids = np.diff(resids, 1, axis=axis)
      dw = np.sum(diff_resids**2, axis=axis) / np.sum(
          resids**2, axis=axis
      )
      return dw
  
file_path: statsmodels/statsmodels/stats/stattools.py
imports: from scipy import stats
  import numpy
  from statsmodels.tools.sm_exceptions import ValueWarning
label_desc: Use image node_id 1 for calling a global function with example usage: durbin_watson(resids, axis) and returns: dw