code: def test_coefficient_of_determination(
      reset_randomstate, close_figures
  ):
      # Get simulated data, and add in some missing entries
      endog, _, _, _, _, _ = gen_dfm_data(k_endog=3, nobs=1000)
      endog.iloc[0, 10:20] = np.nan
      endog.iloc[2, 15:25] = np.nan
  
      # Setup the model and get the results
      factors = {
          0: ["global", "block"],
          1: ["global", "block"],
          2: ["global"],
      }
      mod = dynamic_factor_mq.DynamicFactorMQ(
          endog,
          factors=factors,
          standardize=False,
          idiosyncratic_ar1=False,
      )
      res = mod.smooth(mod.start_params)
  
      # For most of the tests, we'll use smoothed estimates, which are the
      # default
      factors = res.factors.smoothed
  
      # Test for method='individual'
      actual = res.get_coefficients_of_determination(
          method="individual"
      )
      desired = pd.DataFrame(
          np.zeros((3, 2)), index=[0, 1, 2], columns=["global", "block"]
      )
      for i in range(3):
          for j in range(2):
              if i == 2 and j == 1:
                  desired.iloc[i, j] = np.nan
              else:
                  y = endog.iloc[:, i]
                  X = add_constant(factors.iloc[:, j])
                  mod_ols = OLS(y, X, missing="drop")
                  res_ols = mod_ols.fit()
                  desired.iloc[i, j] = res_ols.rsquared
      assert_(actual.index.equals(desired.index))
      assert_(actual.columns.equals(desired.columns))
      assert_allclose(actual, desired)
  
      # Test for method='joint'
      actual = res.get_coefficients_of_determination(method="joint")
      desired = pd.Series(np.zeros(3), index=[0, 1, 2])
      for i in range(3):
          y = endog.iloc[:, i]
          if i == 2:
              X = add_constant(factors.iloc[:, 0])
          else:
              X = add_constant(factors)
          mod_ols = OLS(y, X, missing="drop")
          res_ols = mod_ols.fit()
          desired.iloc[i] = res_ols.rsquared
      assert_(actual.index.equals(desired.index))
      assert_allclose(actual, desired)
  
      # Test for method='cumulative'
      actual = res.get_coefficients_of_determination(
          method="cumulative"
      )
      desired = pd.DataFrame(
          np.zeros((3, 2)), index=[0, 1, 2], columns=["global", "block"]
      )
      for i in range(3):
          for j in range(2):
              if i == 2 and j == 1:
                  desired.iloc[i, j] = np.nan
              else:
                  y = endog.iloc[:, i]
                  X = add_constant(factors.iloc[:, : j + 1])
                  mod_ols = OLS(y, X, missing="drop")
                  res_ols = mod_ols.fit()
                  desired.iloc[i, j] = res_ols.rsquared
      assert_(actual.index.equals(desired.index))
      assert_(actual.columns.equals(desired.columns))
      assert_allclose(actual, desired)
  
      # Test for method='individual', which='filtered'
      factors = res.factors.filtered
      actual = res.get_coefficients_of_determination(
          method="individual", which="filtered"
      )
      desired = pd.DataFrame(
          np.zeros((3, 2)), index=[0, 1, 2], columns=["global", "block"]
      )
      for i in range(3):
          for j in range(2):
              if i == 2 and j == 1:
                  desired.iloc[i, j] = np.nan
              else:
                  y = endog.iloc[:, i]
                  X = add_constant(factors.iloc[:, j])
                  mod_ols = OLS(y, X, missing="drop")
                  res_ols = mod_ols.fit()
                  desired.iloc[i, j] = res_ols.rsquared
      assert_allclose(actual, desired)
  
      # Optional smoke test for plot_coefficient_of_determination
      try:
          import matplotlib.pyplot as plt
  
          try:
              from pandas.plotting import register_matplotlib_converters
  
              register_matplotlib_converters()
          except ImportError:
              pass
          fig1 = plt.figure()
          res.plot_coefficients_of_determination(
              method="individual", fig=fig1
          )
          fig2 = plt.figure()
          res.plot_coefficients_of_determination(
              method="joint", fig=fig2
          )
          fig3 = plt.figure()
          res.plot_coefficients_of_determination(
              method="cumulative", fig=fig3
          )
          fig4 = plt.figure()
          res.plot_coefficients_of_determination(
              which="filtered", fig=fig4
          )
      except ImportError:
          pass
  
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 10 for calling a global function with example usage: test_coefficient_of_determination(reset_randomstate, close_figures) without return types