code: def test_cusum():
      mod = RecursiveLS(endog, exog)
      res = mod.fit()
  
      # Test the cusum statistics against those from R (strucchange)
      # These values are not even close to ours, to Statas, or to the alternate
      # statsmodels values
      # assert_allclose(res.cusum, results_R['cusum'])
  
      # Test the cusum statistics against Stata (cusum6)
      # Note: cusum6 excludes the first 3 elements due to OLS initialization
      # whereas we exclude only the first 2. Also there are initialization
      # differences (as seen above in the recursive residuals).
      # Here we explicitly reverse engineer our cusum to match their to show the
      # equivalence
      d = res.nobs_diffuse
      cusum = res.cusum * np.std(res.resid_recursive[d:], ddof=1)
      cusum -= res.resid_recursive[d]
      cusum /= np.std(res.resid_recursive[d + 1 :], ddof=1)
      cusum = cusum[1:]
      assert_allclose(
          cusum, results_stata.iloc[3:]["cusum"], atol=1e-6, rtol=1e-5
      )
  
      # Test the cusum statistics against statsmodels estimates
      mod_ols = OLS(endog, exog)
      res_ols = mod_ols.fit()
      desired_cusum = recursive_olsresiduals(res_ols)[-2][1:]
      assert_allclose(res.cusum, desired_cusum, rtol=1e-6)
  
      # Test the cusum bounds against Stata (cusum6)
      # Again note that cusum6 excludes the first 3 elements, so we need to
      # change the ddof and points.
      actual_bounds = res._cusum_significance_bounds(
          alpha=0.05, ddof=1, points=np.arange(d + 1, res.nobs)
      )
      desired_bounds = results_stata.iloc[3:][["lw", "uw"]].T
      assert_allclose(actual_bounds, desired_bounds, rtol=1e-6)
  
      # Test the cusum bounds against statsmodels
      actual_bounds = res._cusum_significance_bounds(
          alpha=0.05, ddof=0, points=np.arange(d, res.nobs)
      )
      desired_bounds = recursive_olsresiduals(res_ols)[-1]
      assert_allclose(actual_bounds, desired_bounds)
  
      # Test for invalid calls
      assert_raises(
          ValueError,
          res._cusum_squares_significance_bounds,
          alpha=0.123,
      )
  
imports: import os
  import numpy
  from numpy.testing import assert_allclose, assert_equal, assert_raises
  import pandas
  import pytest
  from scipy.stats import norm
  from statsmodels.datasets import macrodata
  from statsmodels.genmod.api import GLM
  from statsmodels.regression.linear_model import OLS
  from statsmodels.regression.recursive_ls import RecursiveLS
  from statsmodels.stats.diagnostic import recursive_olsresiduals
  from statsmodels.tools import add_constant
  from statsmodels.tools.eval_measures import aic, bic
  from statsmodels.tools.sm_exceptions import ValueWarning
label_desc: Use image node_id 11 for calling a global function with example usage: test_cusum() without return types