code: def test_smoothed_state_obs_weights_varmax(use_exog, trend):
      endog = np.zeros((5, 2))
      endog[0, 0] = np.nan
      endog[1, :] = np.nan
      endog[2, 1] = np.nan
      exog = np.array([2, 5.3, -1, 3.4, 0.0]) if use_exog else None
  
      trend_params = [0.1, 0.2]
      var_params = [0.5, -0.1, 0.0, 0.2]
      exog_params = [1.0, 2.0]
      cov_params = [1.0, 0.0, 1.0]
  
      params = []
      if trend in ["c", "t"]:
          params += trend_params
      params += var_params
      if use_exog:
          params += exog_params
      params += cov_params
  
      # Fit the model
      mod = varmax.VARMAX(
          endog,
          order=(1, 0),
          trend=trend,
          exog=exog if use_exog else None,
      )
      prior_mean = np.array([-0.4, 0.9])
      prior_cov = np.array([[1.4, 0.3], [0.3, 2.6]])
      mod.ssm.initialize_known(prior_mean, prior_cov)
      res = mod.smooth(params)
  
      # Compute the desiried weights
      n = mod.nobs
      m = mod.k_states
      p = mod.k_endog
  
      desired = np.zeros((n, n, m, p)) * np.nan
      # Here we manually compute the weights by adjusting one observation at a
      # time
      for j in range(n):
          for i in range(p):
              if np.isnan(endog[j, i]):
                  desired[:, j, :, i] = np.nan
              else:
                  y = endog.copy()
                  y[j, i] = 1.0
                  tmp_mod = varmax.VARMAX(
                      y,
                      order=(1, 0),
                      trend=trend,
                      exog=exog if use_exog else None,
                  )
                  tmp_mod.ssm.initialize_known(prior_mean, prior_cov)
                  tmp_res = tmp_mod.smooth(params)
  
                  desired[:, j, :, i] = (
                      tmp_res.smoothed_state.T - res.smoothed_state.T
                  )
  
      desired_state_intercept_weights = np.zeros((n, n, m, m)) * np.nan
      # Here we manually compute the weights by adjusting one state intercept
      # at a time
      for j in range(n):
          for ell in range(m):
              tmp_mod = varmax.VARMAX(
                  endog,
                  order=(1, 0),
                  trend=trend,
                  exog=exog if use_exog else None,
              )
              tmp_mod.ssm.initialize_known(prior_mean, prior_cov)
              tmp_mod.update(params)
              if tmp_mod["state_intercept"].ndim == 1:
                  si = tmp_mod["state_intercept"]
                  tmp_mod["state_intercept"] = np.zeros(
                      (mod.k_states, mod.nobs)
                  )
                  tmp_mod["state_intercept", :, :] = si[:, None]
              tmp_mod["state_intercept", ell, j] += 1.0
              tmp_res = tmp_mod.ssm.smooth()
  
              desired_state_intercept_weights[:, j, :, ell] = (
                  tmp_res.smoothed_state.T - res.smoothed_state.T
              )
  
      desired_prior_weights = np.zeros((n, m, m)) * np.nan
      for i in range(m):
          a = prior_mean.copy()
          a[i] += 1
          tmp_mod = varmax.VARMAX(
              endog,
              order=(1, 0),
              trend=trend,
              exog=exog if use_exog else None,
          )
          tmp_mod.ssm.initialize_known(a, prior_cov)
          tmp_res = tmp_mod.smooth(params)
  
          desired_prior_weights[:, :, i] = (
              tmp_res.smoothed_state.T - res.smoothed_state.T
          )
  
      mod.ssm.initialize_known(prior_mean, prior_cov)
      (
          actual,
          actual_state_intercept_weights,
          actual_prior_weights,
      ) = tools.compute_smoothed_state_weights(res)
  
      assert_allclose(actual, desired, atol=1e-8)
      assert_allclose(
          actual_state_intercept_weights,
          desired_state_intercept_weights,
          atol=1e-12,
      )
      assert_allclose(
          actual_prior_weights, desired_prior_weights, atol=1e-12
      )
  
file_path: statsmodels/statsmodels/tsa/statespace/tests/test_weights.py
imports: import pytest
  import numpy
  import pandas
  from numpy.testing import assert_equal, assert_allclose
  from statsmodels import datasets
  from statsmodels.tsa.statespace import sarimax, varmax
  from statsmodels.tsa.statespace import tools
  from statsmodels.tsa.statespace.tests.test_impulse_responses import TVSS
label_desc: Use image node_id 2 for calling a global function with example usage: test_smoothed_state_obs_weights_varmax(use_exog, trend) without return types