code: def test_structural():
      steps = 10
  
      # AR(1)
      mod = structural.UnobservedComponents([0], autoregressive=1)
      phi = 0.5
      actual = mod.impulse_responses([1, phi], steps)
      desired = np.r_[[phi**i for i in range(steps + 1)]]
      assert_allclose(actual, desired)
  
      # ARX(1)
      # This is adequately tested in test_simulate.py, since in the time-varying
      # case `impulse_responses` just calls `simulate`
  
      # Irregular
      mod = structural.UnobservedComponents([0], "irregular")
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 0)
  
      # Fixed intercept
      # (in practice this is a deterministic constant, because an irregular
      #  component must be added)
      with warnings.catch_warnings():
          warnings.simplefilter("ignore")
          mod = structural.UnobservedComponents([0], "fixed intercept")
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 0)
  
      # Deterministic constant
      mod = structural.UnobservedComponents(
          [0], "deterministic constant"
      )
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 0)
  
      # Local level
      mod = structural.UnobservedComponents([0], "local level")
      actual = mod.impulse_responses([1.0, 1.0], steps)
      assert_allclose(actual, 1)
  
      # Random walk
      mod = structural.UnobservedComponents([0], "random walk")
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 1)
  
      # Fixed slope
      # (in practice this is a deterministic trend, because an irregular
      #  component must be added)
      with warnings.catch_warnings():
          warnings.simplefilter("ignore")
          mod = structural.UnobservedComponents([0], "fixed slope")
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 0)
  
      # Deterministic trend
      mod = structural.UnobservedComponents([0], "deterministic trend")
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 0)
  
      # Local linear deterministic trend
      mod = structural.UnobservedComponents(
          [0], "local linear deterministic trend"
      )
      actual = mod.impulse_responses([1.0, 1.0], steps)
      assert_allclose(actual, 1)
  
      # Random walk with drift
      mod = structural.UnobservedComponents(
          [0], "random walk with drift"
      )
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 1)
  
      # Local linear trend
      mod = structural.UnobservedComponents([0], "local linear trend")
      # - shock the level
      actual = mod.impulse_responses([1.0, 1.0, 1.0], steps)
      assert_allclose(actual, 1)
      # - shock the trend
      actual = mod.impulse_responses([1.0, 1.0, 1.0], steps, impulse=1)
      assert_allclose(actual, np.arange(steps + 1))
  
      # Smooth trend
      mod = structural.UnobservedComponents([0], "smooth trend")
      actual = mod.impulse_responses([1.0, 1.0], steps)
      assert_allclose(actual, np.arange(steps + 1))
  
      # Random trend
      mod = structural.UnobservedComponents([0], "random trend")
      actual = mod.impulse_responses([1.0, 1.0], steps)
      assert_allclose(actual, np.arange(steps + 1))
  
      # Seasonal (deterministic)
      mod = structural.UnobservedComponents(
          [0], "irregular", seasonal=2, stochastic_seasonal=False
      )
      actual = mod.impulse_responses([1.0], steps)
      assert_allclose(actual, 0)
  
      # Seasonal (stochastic)
      mod = structural.UnobservedComponents(
          [0], "irregular", seasonal=2
      )
      actual = mod.impulse_responses([1.0, 1.0], steps)
      desired = np.r_[1, np.tile([-1, 1], steps // 2)]
      assert_allclose(actual, desired)
  
      # Cycle (deterministic)
      mod = structural.UnobservedComponents(
          [0], "irregular", cycle=True
      )
      actual = mod.impulse_responses([1.0, 1.2], steps)
      assert_allclose(actual, 0)
  
      # Cycle (stochastic)
      mod = structural.UnobservedComponents(
          [0], "irregular", cycle=True, stochastic_cycle=True
      )
      actual = mod.impulse_responses([1.0, 1.0, 1.2], steps=10)
      x1 = [np.cos(1.2), np.sin(1.2)]
      x2 = [-np.sin(1.2), np.cos(1.2)]
      T = np.array([x1, x2])
      desired = np.zeros(steps + 1)
      states = [1, 0]
      for i in range(steps + 1):
          desired[i] += states[0]
          states = np.dot(T, states)
      assert_allclose(actual, desired)
  
imports: from statsmodels.compat.pandas import MONTH_END
  import warnings
  import numpy
  from numpy.testing import assert_, assert_allclose
  import pandas
  import pytest
  from scipy.stats import ortho_group
  from statsmodels.tools.sm_exceptions import EstimationWarning
  from statsmodels.tsa.statespace import dynamic_factor, mlemodel, sarimax, structural, varmax
  from statsmodels.tsa.vector_ar.tests.test_var import get_macrodata
label_desc: Use image node_id 2 for calling a global function with example usage: test_structural() without return types