code: def test_structural():
      # Many of the forms of UnobservedComponents are just special cases of the
      # most general model with parameter restrictions
      endog = macrodata["infl"]
  
      # Local linear trend is a pretty general model, so we can test fixing
      # parameters against other more specific models
  
      # Local level is local linear trend with sigma2.trend = 0
      mod1 = structural.UnobservedComponents(endog, "llevel")
      mod2 = structural.UnobservedComponents(endog, "lltrend")
  
      # Note: have to reinitialize, so the estimate of the trend term stays at
      # zero.
      init = initialization.Initialization(mod2.k_states)
      init[0] = "approximate_diffuse"
      init.set(1, "known", constant=[0])
      mod2.ssm.initialization = init
      mod2.ssm.loglikelihood_burn = 1
  
      constraints = {"sigma2.trend": 0}
  
      # Start pretty close to optimum to speed up test
      start_params = [3.37, 0.74]
      res1 = mod1.fit(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, ["sigma2.trend"])
  
      # Check that MLE finds the same parameters in either case
      desired = np.r_[res1.params, 0]
      assert_allclose(res2.params, desired)
  
      # 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(res1.params)
  
      check_results(res1, res2)
  
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 13 for calling a global function with example usage: test_structural() without return types