code: def compute_coincident_index(mod, res):
      # Estimate W(1)
      spec = res.specification
      design = mod.ssm["design"]
      transition = mod.ssm["transition"]
      ss_kalman_gain = res.filter_results.kalman_gain[:, :, -1]
      k_states = ss_kalman_gain.shape[0]
  
      W1 = np.linalg.inv(
          np.eye(k_states)
          - np.dot(
              np.eye(k_states) - np.dot(ss_kalman_gain, design),
              transition,
          )
      ).dot(ss_kalman_gain)[0]
  
      # Compute the factor mean vector
      factor_mean = np.dot(
          W1, dta.loc["1972-02-01":, "dln_indprod":"dln_emp"].mean()
      )
  
      # Normalize the factors
      factor = res.factors.filtered[0]
      factor *= np.std(usphci.diff()[1:]) / np.std(factor)
  
      # Compute the coincident index
      coincident_index = np.zeros(mod.nobs + 1)
      # The initial value is arbitrary; here it is set to
      # facilitate comparison
      coincident_index[0] = (
          usphci.iloc[0] * factor_mean / dusphci.mean()
      )
      for t in range(0, mod.nobs):
          coincident_index[t + 1] = (
              coincident_index[t] + factor[t] + factor_mean
          )
  
      # Attach dates
      coincident_index = pd.Series(
          coincident_index, index=dta.index
      ).iloc[1:]
  
      # Normalize to use the same base year as USPHCI
      coincident_index *= (
          usphci.loc["1992-07-01"] / coincident_index.loc["1992-07-01"]
      )
  
      return coincident_index
  
file_path: statsmodels/examples/python/statespace_dfm_coincident.py
imports: import numpy
  import pandas
  import statsmodels.api
  import matplotlib.pyplot
  from pandas_datareader.data import DataReader
  from statsmodels.tsa.statespace import tools
label_desc: Use image node_id 1 for calling a global function with example usage: compute_coincident_index(mod, res) and returns: coincident_index