code: def test_dynamic_factor():
      np.random.seed(93739)
      nobs = 100
      eps = np.random.normal(size=nobs)
      exog = np.random.normal(size=(nobs, 1))
  
      eps1 = np.zeros(nobs)
      eps2 = np.zeros(nobs)
      eps2[49] = 1
      eps3 = np.zeros(nobs)
      eps3[50:] = 1
  
      # DFM: 2 series, AR(2) factor
      mod1 = dynamic_factor.DynamicFactor(
          [[0, 0]], k_factors=1, factor_order=2
      )
      mod2 = sarimax.SARIMAX([0], order=(2, 0, 0))
      actual = mod1.simulate(
          [-0.9, 0.8, 1.0, 1.0, 0.5, 0.2],
          nobs,
          measurement_shocks=np.c_[eps1, eps1],
          state_shocks=eps,
          initial_state=np.zeros(mod1.k_states),
      )
      desired = mod2.simulate(
          [0.5, 0.2, 1],
          nobs,
          state_shocks=eps,
          initial_state=np.zeros(mod2.k_states),
      )
      assert_allclose(actual[:, 0], -0.9 * desired)
      assert_allclose(actual[:, 1], 0.8 * desired)
  
      # DFM: 2 series, AR(2) factor, exog
      mod1 = dynamic_factor.DynamicFactor(
          np.zeros((nobs, 2)), k_factors=1, factor_order=2, exog=exog
      )
      mod2 = sarimax.SARIMAX([0], order=(2, 0, 0))
      actual = mod1.simulate(
          [-0.9, 0.8, 5, -2, 1.0, 1.0, 0.5, 0.2],
          nobs,
          measurement_shocks=np.c_[eps1, eps1],
          state_shocks=eps,
          initial_state=np.zeros(mod1.k_states),
      )
      desired = mod2.simulate(
          [0.5, 0.2, 1],
          nobs,
          state_shocks=eps,
          initial_state=np.zeros(mod2.k_states),
      )
      assert_allclose(actual[:, 0], -0.9 * desired + 5 * exog[:, 0])
      assert_allclose(actual[:, 1], 0.8 * desired - 2 * exog[:, 0])
  
      # DFM, 3 series, VAR(2) factor, exog, error VAR
      # TODO: This is just a smoke test
      mod = dynamic_factor.DynamicFactor(
          np.random.normal(size=(nobs, 3)),
          k_factors=2,
          factor_order=2,
          exog=exog,
          error_order=2,
          error_var=True,
      )
      mod.simulate(mod.start_params, nobs)
  
imports: from statsmodels.compat.pandas import MONTH_END
  import numpy
  from numpy.testing import assert_, assert_allclose, assert_equal
  import pandas
  import pytest
  from scipy.signal import lfilter
  from statsmodels.tools.sm_exceptions import EstimationWarning, SpecificationWarning
  from statsmodels.tsa.statespace import dynamic_factor, sarimax, structural, varmax
  from .test_impulse_responses import TVSS
label_desc: Use image node_id 5 for calling a global function with example usage: test_dynamic_factor() without return types