code: def test_two_blocks_factor_orders_6(reset_randomstate):
      # This tests that the model is correctly set up when the lag order of the
      # factor is longer than 5 and we have two blocks of factors, one block with
      # a single factor and one block with two factors.
  
      # For the results below, we use nobs=1000, since nobs=10000 takes a very
      # long time and a large amount of memory. As a result, the results below
      # are noisier than they could be, although they still provide pretty good
      # evidence that the model is performing as it should
      nobs = 1000
      idiosyncratic_ar1 = True
      k1 = 3
      k2 = 10
      endog1_M, endog1_Q, f1 = gen_k_factor1(
          nobs, k=k1, idiosyncratic_ar1=idiosyncratic_ar1
      )
      endog2_M, endog2_Q, f2 = gen_k_factor2(
          nobs, k=k2, idiosyncratic_ar1=idiosyncratic_ar1
      )
  
      endog_M = pd.concat([endog1_M, f2, endog2_M], axis=1)
      endog_Q = pd.concat([endog1_Q, endog2_Q], axis=1)
  
      factors = {f"yM{i + 1}_f1": ["a"] for i in range(k1)}
      factors.update({f"yQ{i + 1}_f1": ["a"] for i in range(k1)})
      factors.update({f"f{i + 1}": ["b"] for i in range(2)})
      factors.update({f"yM{i + 1}_f2": ["b"] for i in range(k2)})
      factors.update({f"yQ{i + 1}_f2": ["b"] for i in range(k2)})
      factor_multiplicities = {"b": 2}
  
      mod = dynamic_factor_mq.DynamicFactorMQ(
          endog_M,
          endog_quarterly=endog_Q,
          factors=factors,
          factor_multiplicities=factor_multiplicities,
          factor_orders=6,
          idiosyncratic_ar1=idiosyncratic_ar1,
          standardize=False,
      )
      mod.fit()
  
      # For the 1-factor block:
      # From one run, the following fitted coefficients were estimated:
      #                       True  Fitted
      # loading.a->yM1_f1     1.00   -0.86
      # loading.a->yM2_f1     1.00   -0.85
      # loading.a->yM3_f1     1.00   -0.86
      # loading.a->yQ1_f1     1.00   -0.71
      # loading.a->yQ2_f1     1.00   -0.47
      # loading.a->yQ3_f1     1.00   -0.48
      # L1.a->a               0.00    0.05
      # L2.a->a               0.00    0.06
      # L3.a->a               0.00    0.04
      # L4.a->a               0.00   -0.03
      # L5.a->a               0.00   -0.06
      # L6.a->a               0.50    0.46
      # fb(0).cov.chol[1,1]   1.00    1.63
      # L1.eps_M.yM1_f1       0.70    0.65
      # L1.eps_M.yM2_f1       0.70    0.67
      # L1.eps_M.yM3_f1       0.70    0.68
      # L1.eps_Q.yQ1_f1       0.70    0.76
      # L1.eps_Q.yQ2_f1       0.70    0.59
      # L1.eps_Q.yQ3_f1       0.70    0.62
      # sigma2.yM1_f1         0.40    0.39
      # sigma2.yM2_f1         0.40    0.41
      # sigma2.yM3_f1         0.40    0.40
      # sigma2.yQ1_f1         0.40    0.43
      # sigma2.yQ2_f1         0.40    0.60
      # sigma2.yQ3_f1         0.40    0.59
      # These are pretty good:
      # 1. When we normalize the factor by the first loading, the monthly
      #    variables then all have loading close to 1.0. However, the factor
      #    standard deviation is 0.86 * 1.63 = 1.4, which is higher than it
      #    should be (this is largely due to the existence of the quarterly
      #    variables, which only have 1/3 the number of observations, and make
      #    the estimation more noisy)
      # 2. Similarly, the idiosyncratic AR(1) and error variance are pretty-well
      #    estimated, although more-so for monthly than quarterly variables
      # 3. The factor transition is pretty good, although there is some noise in
  
      # For the 2-factor block:
      # The identification for the VAR system means that it is harder to visually
      # check that the estimation procedure produced good estimates.
  
      # This is the invertible matrix that we'll use to transform the factors
      # and parameter matrices into the original form
      from scipy.linalg import block_diag
  
      M1 = np.kron(np.eye(6), mod["design", 3:5, :2])
      M2 = np.kron(np.eye(6), mod["design", 0:1, 12:13])
      M = block_diag(M1, M2)
      Mi = np.linalg.inv(M)
  
      # Get the estimated parameter matrices
      Z = mod["design", :, :18]
      A = mod["transition", :18, :18]
      R = mod["selection", :18, :3]
      Q = block_diag(
          mod["state_cov", :2, :2], mod["state_cov", 12:13, 12:13]
      )
      RQR = R @ Q @ R.T
  
      # Create the transformed matrices
      Z2 = Z @ Mi
      A2 = M @ A @ Mi
      Q2 = M @ RQR @ M.T
  
      # In this example, both endog_M and endog_Q are equal to the factors,
      # so we expect the loading matrix to look like, which can be confirmed
      # (up to some numerical precision) by printing Z2
      # (where the 1's, 2's, etc. are actually vectors of 1's and 2's, etc.)
      # [ 0 0   0 0   0 0   0 0   0 0  | 1  0  0  0  0 ]
      # [ 0 0   0 0   0 0   0 0   0 0  | 1  2  3  2  1 ]
      # [  I    0 0   0 0   0 0   0 0  | 0  0  0  0  0 ]
      # [ 1 1   0 0   0 0   0 0   0 0  | 0  0  0  0  0 ]
      # [ 1 1   2 2   3 3   2 2   1 1  | 0  0  0  0  0 ]
      print(Z2.round(2))
      # Confirm that for the first factor block this is approximately:
      # [  0  0    0  0    0  0    0  0    0  0    0.5 -0.2 ]
      # [  0  0    0  0    0  0    0  0    0  0    0.1  0.3 ]
      # and for the second factor block this is approximately
      # [  0  0  0  0  0  0.5 ]
      print(A2.round(2))
      # Confirm that this is approximately:
      # [ 1.5  0.2 ]
      # [ 0.2  0.5 ]
      # for the first factor block, and
      # [1.0]
      # for the second factor block (note: actually, this seems to be
      # about [0.3], underestimating this factor's error variance)
      print(Q2.round(2))
  
file_path: statsmodels/statsmodels/tsa/statespace/tests/test_dynamic_factor_mq_monte_carlo.py
imports: from statsmodels.compat.pandas import QUARTER_END
  import numpy
  from numpy.testing import assert_allclose
  import pandas
  import pytest
  from scipy.signal import lfilter
  from statsmodels.tsa.statespace import dynamic_factor, dynamic_factor_mq, sarimax, varmax
label_desc: Use image node_id 10 for calling a global function with example usage: test_two_blocks_factor_orders_6(reset_randomstate) without return types