code: def test_predict():
      # AR(1) without mean, k_regimes=2
      endog = np.ones(10)
      markov_autoregression.MarkovAutoregression(
          endog, k_regimes=2, order=1, trend="n"
      )
      mod = markov_autoregression.MarkovAutoregression(
          endog, k_regimes=2, order=1, trend="n"
      )
      assert_equal(mod.nobs, 9)
      assert_equal(mod.endog, np.ones(9))
  
      params = np.r_[0.5, 0.5, 1.0, 0.1, 0.5]
      mod_resid = mod._resid(params)
      resids = np.zeros((2, 2, mod.nobs))
      # Resids when: S_{t} = 0
      resids[0, :, :] = np.ones(9) - 0.1 * np.ones(9)
      assert_allclose(mod_resid[0, :, :], resids[0, :, :])
      # Resids when: S_{t} = 1
      resids[1, :, :] = np.ones(9) - 0.5 * np.ones(9)
      assert_allclose(mod_resid[1, :, :], resids[1, :, :])
  
      # AR(1) with mean, k_regimes=2
      endog = np.arange(10)
      mod = markov_autoregression.MarkovAutoregression(
          endog, k_regimes=2, order=1
      )
      assert_equal(mod.nobs, 9)
      assert_equal(mod.endog, np.arange(1, 10))
  
      params = np.r_[0.5, 0.5, 2.0, 3.0, 1.0, 0.1, 0.5]
      mod_resid = mod._resid(params)
      resids = np.zeros((2, 2, mod.nobs))
      # Resids when: S_t = 0, S_{t-1} = 0
      resids[0, 0, :] = (np.arange(1, 10) - 2.0) - 0.1 * (
          np.arange(9) - 2.0
      )
      assert_allclose(mod_resid[0, 0, :], resids[0, 0, :])
      # Resids when: S_t = 0, S_{t-1} = 1
      resids[0, 1, :] = (np.arange(1, 10) - 2.0) - 0.1 * (
          np.arange(9) - 3.0
      )
      assert_allclose(mod_resid[0, 1, :], resids[0, 1, :])
      # Resids when: S_t = 1, S_{t-1} = 0
      resids[1, 0, :] = (np.arange(1, 10) - 3.0) - 0.5 * (
          np.arange(9) - 2.0
      )
      assert_allclose(mod_resid[1, 0, :], resids[1, 0, :])
      # Resids when: S_t = 1, S_{t-1} = 1
      resids[1, 1, :] = (np.arange(1, 10) - 3.0) - 0.5 * (
          np.arange(9) - 3.0
      )
      assert_allclose(mod_resid[1, 1, :], resids[1, 1, :])
  
      # AR(2) with mean, k_regimes=3
      endog = np.arange(10)
      mod = markov_autoregression.MarkovAutoregression(
          endog, k_regimes=3, order=2
      )
      assert_equal(mod.nobs, 8)
      assert_equal(mod.endog, np.arange(2, 10))
  
      params = np.r_[
          [0.3] * 6, 2.0, 3.0, 4, 1.0, 0.1, 0.5, 0.8, -0.05, -0.25, -0.4
      ]
      mod_resid = mod._resid(params)
      resids = np.zeros((3, 3, 3, mod.nobs))
      # Resids when: S_t = 0, S_{t-1} = 0, S_{t-2} = 0
      resids[0, 0, 0, :] = (
          (np.arange(2, 10) - 2.0)
          - 0.1 * (np.arange(1, 9) - 2.0)
          - (-0.05) * (np.arange(8) - 2.0)
      )
      assert_allclose(mod_resid[0, 0, 0, :], resids[0, 0, 0, :])
  
      # Resids when: S_t = 1, S_{t-1} = 0, S_{t-2} = 0
      resids[1, 0, 0, :] = (
          (np.arange(2, 10) - 3.0)
          - 0.5 * (np.arange(1, 9) - 2.0)
          - (-0.25) * (np.arange(8) - 2.0)
      )
      assert_allclose(mod_resid[1, 0, 0, :], resids[1, 0, 0, :])
  
      # Resids when: S_t = 0, S_{t-1} = 2, S_{t-2} = 1
      resids[0, 2, 1, :] = (
          (np.arange(2, 10) - 2.0)
          - 0.1 * (np.arange(1, 9) - 4.0)
          - (-0.05) * (np.arange(8) - 3.0)
      )
      assert_allclose(mod_resid[0, 2, 1, :], resids[0, 2, 1, :])
  
      # AR(1) with mean + non-switching exog
      endog = np.arange(10)
      exog = np.r_[0.4, 5, 0.2, 1.2, -0.3, 2.5, 0.2, -0.7, 2.0, -1.1]
      mod = markov_autoregression.MarkovAutoregression(
          endog, k_regimes=2, order=1, exog=exog
      )
      assert_equal(mod.nobs, 9)
      assert_equal(mod.endog, np.arange(1, 10))
  
      params = np.r_[0.5, 0.5, 2.0, 3.0, 1.5, 1.0, 0.1, 0.5]
      mod_resid = mod._resid(params)
      resids = np.zeros((2, 2, mod.nobs))
      # Resids when: S_t = 0, S_{t-1} = 0
      resids[0, 0, :] = (
          np.arange(1, 10) - 2.0 - 1.5 * exog[1:]
      ) - 0.1 * (np.arange(9) - 2.0 - 1.5 * exog[:-1])
      assert_allclose(mod_resid[0, 0, :], resids[0, 0, :])
      # Resids when: S_t = 0, S_{t-1} = 1
      resids[0, 1, :] = (
          np.arange(1, 10) - 2.0 - 1.5 * exog[1:]
      ) - 0.1 * (np.arange(9) - 3.0 - 1.5 * exog[:-1])
      assert_allclose(mod_resid[0, 1, :], resids[0, 1, :])
      # Resids when: S_t = 1, S_{t-1} = 0
      resids[1, 0, :] = (
          np.arange(1, 10) - 3.0 - 1.5 * exog[1:]
      ) - 0.5 * (np.arange(9) - 2.0 - 1.5 * exog[:-1])
      assert_allclose(mod_resid[1, 0, :], resids[1, 0, :])
      # Resids when: S_t = 1, S_{t-1} = 1
      resids[1, 1, :] = (
          np.arange(1, 10) - 3.0 - 1.5 * exog[1:]
      ) - 0.5 * (np.arange(9) - 3.0 - 1.5 * exog[:-1])
      assert_allclose(mod_resid[1, 1, :], resids[1, 1, :])
  
imports: import warnings
  import os
  import numpy
  from numpy.testing import assert_equal, assert_allclose
  import pandas
  import pytest
  from statsmodels.tools import add_constant
  from statsmodels.tsa.regime_switching import markov_autoregression
label_desc: Use image node_id 1 for calling a global function with example usage: test_predict() without return types