code: def test_quasi_newton_fitting(reset_randomstate):
      # Test that the typical state space quasi-Newton fitting mechanisms work
      # here too, even if they aren't used much
      # Note: to match the quasi-Newton results, which use the stationary
      # initialization, we need to set em_initialization=False
      # Note: one thing that this test reveals is that there are some numerical
      # issues with the EM algorithm when em_initialization=False around the
      # true optimum, where apparently numerical issues case the EM algorithm to
      # decrease the log-likelihood. In particular, testing updating each block
      # of parameters shows that it is the updating of the factor autoregressive
      # coefficients and (it appears) the factor error variance term that are
      # to blame here.
      endog, _, _, _, _, _ = gen_dfm_data(k_endog=2, nobs=1000)
  
      # Create the test Dynamic Factor MQ models
      mod_dfm = dynamic_factor_mq.DynamicFactorMQ(
          endog,
          factor_orders=1,
          standardize=False,
          idiosyncratic_ar1=False,
      )
      mod_dfm_ar1 = dynamic_factor_mq.DynamicFactorMQ(
          endog,
          factor_orders=1,
          standardize=False,
          idiosyncratic_ar1=True,
      )
  
      # Check that transform and untransform works
      x = mod_dfm_ar1.start_params
      y = mod_dfm_ar1.untransform_params(x)
      z = mod_dfm_ar1.transform_params(y)
      assert_allclose(x, z)
  
      # Check lbfgs and em converge to the same thing: idiosyncratic_ar1=False
      res_lbfgs = mod_dfm.fit(method="lbfgs")
      params_lbfgs = res_lbfgs.params.copy()
  
      start_params = params_lbfgs.copy()
      start_params["L1.0->0"] += 1e-2
      start_params["fb(0).cov.chol[1,1]"] += 1e-2
      res_em = mod_dfm.fit(start_params, em_initialization=False)
      params_em = res_em.params.copy()
  
      assert_allclose(res_lbfgs.llf, res_em.llf, atol=5e-2, rtol=1e-5)
      assert_allclose(params_lbfgs, params_em, atol=5e-2, rtol=1e-5)
  
      # Check lbfgs and em converge to the same thing: idiosyncratic_ar1=True
      res_lbfgs = mod_dfm_ar1.fit(method="lbfgs")
      params_lbfgs = res_lbfgs.params.copy()
  
      start_params = params_lbfgs.copy()
      start_params["L1.0->0"] += 1e-2
      start_params["fb(0).cov.chol[1,1]"] += 1e-2
      res_em = mod_dfm_ar1.fit(params_lbfgs, em_initialization=False)
      params_em = res_em.params.copy()
  
      assert_allclose(res_lbfgs.llf, res_em.llf, atol=5e-2, rtol=1e-5)
      assert_allclose(params_lbfgs, params_em, atol=5e-2, rtol=1e-5)
  
imports: from statsmodels.compat.pandas import MONTH_END, QUARTER_END, assert_frame_equal, assert_series_equal
  import numpy
  from numpy.testing import assert_, assert_allclose, assert_equal
  import pandas
  import pytest
  from statsmodels.regression.linear_model import OLS
  from statsmodels.tools import add_constant
  from statsmodels.tsa.statespace import dynamic_factor, dynamic_factor_mq, sarimax
  from statsmodels.tsa.statespace.tests import test_dynamic_factor_mq_monte_carlo
label_desc: Use image node_id 11 for calling a global function with example usage: test_quasi_newton_fitting(reset_randomstate) without return types