code: def test_dynamic_factor_diag_error_cov():
      # Can test fixing the off-diagonal error covariance parameters to zeros
      # with `error_cov_type='unstructured'` against the case
      # `error_cov_type='diagonal'`.
      endog = np.log(macrodata[["cpi", "realgdp"]]).diff().iloc[1:]
      endog = (endog - endog.mean()) / endog.std()
  
      # Basic model
      mod1 = dynamic_factor.DynamicFactor(
          endog, k_factors=1, factor_order=1, error_cov_type="diagonal"
      )
      mod2 = dynamic_factor.DynamicFactor(
          endog,
          k_factors=1,
          factor_order=1,
          error_cov_type="unstructured",
      )
  
      constraints = {"cov.chol[2,1]": 0}
  
      # Start pretty close to optimum to speed up test
      start_params = [-4.5e-06, -1.0e-05, 9.9e-01, 9.9e-01, -1.4e-01]
      res1 = mod1.fit(start_params=start_params, disp=False)
      res2 = mod2.fit_constrained(
          constraints,
          start_params=res1.params,
          includes_fixed=False,
          disp=False,
      )
  
      # Check that the right parameters were fixed
      assert_equal(res1.fixed_params, [])
      assert_equal(res2.fixed_params, ["cov.chol[2,1]"])
  
      # Check that MLE finds the same parameters in either case
      # (need to account for the fact that diagonal params are variances but
      # unstructured params are standard deviations)
      param_vals = np.asarray(res1.params)
      params = np.r_[
          param_vals[:2], param_vals[2:4] ** 0.5, param_vals[4]
      ]
      desired = np.r_[params[:3], 0, params[3:]]
      assert_allclose(res2.params, desired, atol=1e-5)
  
      # Now smooth at the actual parameters (to allow high precision testing
      # below, even if there are small differences between MLE fitted parameters)
      with mod2.fix_params(constraints):
          res2 = mod2.smooth(params)
  
      # Can't check some parameters-related values because of the different
      # parameterization (i.e. cov_params, bse, pvalues, etc. won't match).
      check_results(res1, res2, check_params=False)
  
imports: import numpy
  import pytest
  from statsmodels import datasets
  from statsmodels.tsa.statespace import initialization, mlemodel, sarimax, structural, dynamic_factor, varmax
  from numpy.testing import assert_, assert_raises, assert_equal, assert_allclose
label_desc: Use image node_id 14 for calling a global function with example usage: test_dynamic_factor_diag_error_cov() without return types