class_docstr: Results from applying the Kalman smoother and/or filter to a state space
  model.
  
  Parameters
  ----------
  model : Representation
      A Statespace representation
  
  Attributes
  ----------
  nobs : int
      Number of observations.
  k_endog : int
      The dimension of the observation series.
  k_states : int
      The dimension of the unobserved state process.
  k_posdef : int
      The dimension of a guaranteed positive definite covariance matrix
      describing the shocks in the measurement equation.
  dtype : dtype
      Datatype of representation matrices
  prefix : str
      BLAS prefix of representation matrices
  shapes : dictionary of name:tuple
      A dictionary recording the shapes of each of the representation
      matrices as tuples.
  endog : ndarray
      The observation vector.
  design : ndarray
      The design matrix, :math:`Z`.
  obs_intercept : ndarray
      The intercept for the observation equation, :math:`d`.
  obs_cov : ndarray
      The covariance matrix for the observation equation :math:`H`.
  transition : ndarray
      The transition matrix, :math:`T`.
  state_intercept : ndarray
      The intercept for the transition equation, :math:`c`.
  selection : ndarray
      The selection matrix, :math:`R`.
  state_cov : ndarray
      The covariance matrix for the state equation :math:`Q`.
  missing : array of bool
      An array of the same size as `endog`, filled with boolean values that
      are True if the corresponding entry in `endog` is NaN and False
      otherwise.
  nmissing : array of int
      An array of size `nobs`, where the ith entry is the number (between 0
      and k_endog) of NaNs in the ith row of the `endog` array.
  time_invariant : bool
      Whether or not the representation matrices are time-invariant
  initialization : str
      Kalman filter initialization method.
  initial_state : array_like
      The state vector used to initialize the Kalamn filter.
  initial_state_cov : array_like
      The state covariance matrix used to initialize the Kalamn filter.
  filter_method : int
      Bitmask representing the Kalman filtering method
  inversion_method : int
      Bitmask representing the method used to invert the forecast error
      covariance matrix.
  stability_method : int
      Bitmask representing the methods used to promote numerical stability in
      the Kalman filter recursions.
  conserve_memory : int
      Bitmask representing the selected memory conservation method.
  tolerance : float
      The tolerance at which the Kalman filter determines convergence to
      steady-state.
  loglikelihood_burn : int
      The number of initial periods during which the loglikelihood is not
      recorded.
  converged : bool
      Whether or not the Kalman filter converged.
  period_converged : int
      The time period in which the Kalman filter converged.
  filtered_state : ndarray
      The filtered state vector at each time period.
  filtered_state_cov : ndarray
      The filtered state covariance matrix at each time period.
  predicted_state : ndarray
      The predicted state vector at each time period.
  predicted_state_cov : ndarray
      The predicted state covariance matrix at each time period.
  kalman_gain : ndarray
      The Kalman gain at each time period.
  forecasts : ndarray
      The one-step-ahead forecasts of observations at each time period.
  forecasts_error : ndarray
      The forecast errors at each time period.
  forecasts_error_cov : ndarray
      The forecast error covariance matrices at each time period.
  loglikelihood : ndarray
      The loglikelihood values at each time period.
  collapsed_forecasts : ndarray
      If filtering using collapsed observations, stores the one-step-ahead
      forecasts of collapsed observations at each time period.
  collapsed_forecasts_error : ndarray
      If filtering using collapsed observations, stores the one-step-ahead
      forecast errors of collapsed observations at each time period.
  collapsed_forecasts_error_cov : ndarray
      If filtering using collapsed observations, stores the one-step-ahead
      forecast error covariance matrices of collapsed observations at each
      time period.
  standardized_forecast_error : ndarray
      The standardized forecast errors
  smoother_output : int
      Bitmask representing the generated Kalman smoothing output
  scaled_smoothed_estimator : ndarray
      The scaled smoothed estimator at each time period.
  scaled_smoothed_estimator_cov : ndarray
      The scaled smoothed estimator covariance matrices at each time period.
  smoothing_error : ndarray
      The smoothing error covariance matrices at each time period.
  smoothed_state : ndarray
      The smoothed state at each time period.
  smoothed_state_cov : ndarray
      The smoothed state covariance matrices at each time period.
  smoothed_state_autocov : ndarray
      The smoothed state lago-one autocovariance matrices at each time
      period: :math:`Cov(\alpha_{t+1}, \alpha_t)`.
  smoothed_measurement_disturbance : ndarray
      The smoothed measurement at each time period.
  smoothed_state_disturbance : ndarray
      The smoothed state at each time period.
  smoothed_measurement_disturbance_cov : ndarray
      The smoothed measurement disturbance covariance matrices at each time
      period.
  smoothed_state_disturbance_cov : ndarray
      The smoothed state disturbance covariance matrices at each time period.
docstr: Decompose smoothed output into contributions from observations
  
  Parameters
  ----------
  decomposition_of : {"smoothed_state", "smoothed_signal"}
      The object to perform a decomposition of. If it is set to
      "smoothed_state", then the elements of the smoothed state vector
      are decomposed into the contributions of each observation. If it
      is set to "smoothed_signal", then the predictions of the
      observation vector based on the smoothed state vector are
      decomposed. Default is "smoothed_state".
  state_index : array_like, optional
      An optional index specifying a subset of states to use when
      constructing the decomposition of the "smoothed_signal". For
      example, if `state_index=[0, 1]` is passed, then only the
      contributions of observed variables to the smoothed signal arising
      from the first two states will be returned. Note that if not all
      states are used, the contributions will not sum to the smoothed
      signal. Default is to use all states.
  
  Returns
  -------
  data_contributions : array
      Contributions of observations to the decomposed object. If the
      smoothed state is being decomposed, then `data_contributions` are
      shaped `(nobs, k_states, nobs, k_endog)`, where the
      `(t, m, j, p)`-th element is the contribution of the `p`-th
      observation at time `j` to the `m`-th state at time `t`. If the
      smoothed signal is being decomposed, then `data_contributions` are
      shaped `(nobs, k_endog, nobs, k_endog)`, where the
      `(t, k, j, p)`-th element is the contribution of the `p`-th
      observation at time `j` to the smoothed prediction of the `k`-th
      observation at time `t`.
  obs_intercept_contributions : array
      Contributions of the observation intercept to the decomposed
      object. If the smoothed state is being decomposed, then
      `obs_intercept_contributions` are shaped
      `(nobs, k_states, nobs, k_endog)`, where the `(t, m, j, p)`-th
      element is the contribution of the `p`-th observation intercept at
      time `j` to the `m`-th state at time `t`. If the smoothed signal
      is being decomposed, then `obs_intercept_contributions` are shaped
      `(nobs, k_endog, nobs, k_endog)`, where the `(t, k, j, p)`-th
      element is the contribution of the `p`-th observation at time `j`
      to the smoothed prediction of the `k`-th observation at time `t`.
  state_intercept_contributions : array
      Contributions of the state intercept to the decomposed object. If
      the smoothed state is being decomposed, then
      `state_intercept_contributions` are shaped
      `(nobs, k_states, nobs, k_states)`, where the `(t, m, j, l)`-th
      element is the contribution of the `l`-th state intercept at
      time `j` to the `m`-th state at time `t`. If the smoothed signal
      is being decomposed, then `state_intercept_contributions` are
      shaped `(nobs, k_endog, nobs, k_endog)`, where the
      `(t, k, j, l)`-th element is the contribution of the `p`-th
      observation at time `j` to the smoothed prediction of the `k`-th
      observation at time `t`.
  prior_contributions : array
      Contributions of the prior to the decomposed object. If the
      smoothed state is being decomposed, then `prior_contributions` are
      shaped `(nobs, k_states, k_states)`, where the `(t, m, l)`-th
      element is the contribution of the `l`-th element of the prior
      mean to the `m`-th state at time `t`. If the smoothed signal is
      being decomposed, then `prior_contributions` are shaped
      `(nobs, k_endog, k_states)`, where the `(t, k, l)`-th
      element is the contribution of the `l`-th element of the prior mean
      to the smoothed prediction of the `k`-th observation at time `t`.
  
  Notes
  -----
  Denote the smoothed state at time :math:`t` by :math:`\alpha_t`. Then
  the smoothed signal is :math:`Z_t \alpha_t`, where :math:`Z_t` is the
  design matrix operative at time :math:`t`.
docstr_tok: ["Decompose","smoothed","output","into","contributions","from","observations","Parameters","--","--","--","--","--","decomposition_of",":","{","``","smoothed_state","''",",","``","smoothed_signal","''","}","The","object","to","perform","a","decomposition","of",".","If","it","is","set","to","``","smoothed_state","''",",","then","the","elements","of","the","smoothed","state","vector","are","decomposed","into","the","contributions","of","each","observation",".","If","it","is","set","to","``","smoothed_signal","''",",","then","the","predictions","of","the","observation","vector","based","on","the","smoothed","state","vector","are","decomposed",".","Default","is","``","smoothed_state","''",".","state_index",":","array_like",",","optional","An","optional","index","specifying","a","subset","of","states","to","use","when","constructing","the","decomposition","of","the","``","smoothed_signal","''",".","For","example",",","if","`","state_index=","[","0",",","1","]","`","is","passed",",","then","only","the","contributions","of","observed","variables","to","the","smoothed","signal","arising","from","the","first","two","states","will","be","returned",".","Note","that","if","not","all","states","are","used",",","the","contributions","will","not","sum","to","the","smoothed","signal",".","Default","is","to","use","all","states",".","Returns","--","--","--","-","data_contributions",":","array","Contributions","of","observations","to","the","decomposed","object",".","If","the","smoothed","state","is","being","decomposed",",","then","`","data_contributions","`","are","shaped","`","(","nobs",",","k_states",",","nobs",",","k_endog",")","`",",","where","the","`","(","t",",","m",",","j",",","p",")","`","-th","element","is","the","contribution","of","the","`","p","`","-th","observation","at","time","`","j","`","to","the","`","m","`","-th","state","at","time","`","t","`",".","If","the","smoothed","signal","is","being","decomposed",",","then","`","data_contributions","`","are","shaped","`","(","nobs",",","k_endog",",","nobs",",","k_endog",")","`",",","where","the","`","(","t",",","k",",","j",",","p",")","`","-th","element","is","the","contribution","of","the","`","p","`","-th","observation","at","time","`","j","`","to","the","smoothed","prediction","of","the","`","k","`","-th","observation","at","time","`","t","`",".","obs_intercept_contributions",":","array","Contributions","of","the","observation","intercept","to","the","decomposed","object",".","If","the","smoothed","state","is","being","decomposed",",","then","`","obs_intercept_contributions","`","are","shaped","`","(","nobs",",","k_states",",","nobs",",","k_endog",")","`",",","where","the","`","(","t",",","m",",","j",",","p",")","`","-th","element","is","the","contribution","of","the","`","p","`","-th","observation","intercept","at","time","`","j","`","to","the","`","m","`","-th","state","at","time","`","t","`",".","If","the","smoothed","signal","is","being","decomposed",",","then","`","obs_intercept_contributions","`","are","shaped","`","(","nobs",",","k_endog",",","nobs",",","k_endog",")","`",",","where","the","`","(","t",",","k",",","j",",","p",")","`","-th","element","is","the","contribution","of","the","`","p","`","-th","observation","at","time","`","j","`","to","the","smoothed","prediction","of","the","`","k","`","-th","observation","at","time","`","t","`",".","state_intercept_contributions",":","array","Contributions","of","the","state","intercept","to","the","decomposed","object",".","If","the","smoothed","state","is","being","decomposed",",","then","`","state_intercept_contributions","`","are","shaped","`","(","nobs",",","k_states",",","nobs",",","k_states",")","`",",","where","the","`","(","t",",","m",",","j",",","l",")","`","-th","element","is","the","contribution","of","the","`","l","`","-th","state","intercept","at","time","`","j","`","to","the","`","m","`","-th","state","at","time","`","t","`",".","If","the","smoothed","signal","is","being","decomposed",",","then","`","state_intercept_contributions","`","are","shaped","`","(","nobs",",","k_endog",",","nobs",",","k_endog",")","`",",","where","the","`","(","t",",","k",",","j",",","l",")","`","-th","element","is","the","contribution","of","the","`","p","`","-th","observation","at","time","`","j","`","to","the","smoothed","prediction","of","the","`","k","`","-th","observation","at","time","`","t","`",".","prior_contributions",":","array","Contributions","of","the","prior","to","the","decomposed","object",".","If","the","smoothed","state","is","being","decomposed",",","then","`","prior_contributions","`","are","shaped","`","(","nobs",",","k_states",",","k_states",")","`",",","where","the","`","(","t",",","m",",","l",")","`","-th","element","is","the","contribution","of","the","`","l","`","-th","element","of","the","prior","mean","to","the","`","m","`","-th","state","at","time","`","t","`",".","If","the","smoothed","signal","is","being","decomposed",",","then","`","prior_contributions","`","are","shaped","`","(","nobs",",","k_endog",",","k_states",")","`",",","where","the","`","(","t",",","k",",","l",")","`","-th","element","is","the","contribution","of","the","`","l","`","-th","element","of","the","prior","mean","to","the","smoothed","prediction","of","the","`","k","`","-th","observation","at","time","`","t","`",".","Notes","--","--","-","Denote","the","smoothed","state","at","time",":","math",":","`","t","`","by",":","math",":","`","\\alpha_t","`",".","Then","the","smoothed","signal","is",":","math",":","`","Z_t","\\alpha_t","`",",","where",":","math",":","`","Z_t","`","is","the","design","matrix","operative","at","time",":","math",":","`","t","`","."]
code: def get_smoothed_decomposition(
      self, decomposition_of="smoothed_state", state_index=None
  ):
      r"""
      Decompose smoothed output into contributions from observations
  
      Parameters
      ----------
      decomposition_of : {"smoothed_state", "smoothed_signal"}
          The object to perform a decomposition of. If it is set to
          "smoothed_state", then the elements of the smoothed state vector
          are decomposed into the contributions of each observation. If it
          is set to "smoothed_signal", then the predictions of the
          observation vector based on the smoothed state vector are
          decomposed. Default is "smoothed_state".
      state_index : array_like, optional
          An optional index specifying a subset of states to use when
          constructing the decomposition of the "smoothed_signal". For
          example, if `state_index=[0, 1]` is passed, then only the
          contributions of observed variables to the smoothed signal arising
          from the first two states will be returned. Note that if not all
          states are used, the contributions will not sum to the smoothed
          signal. Default is to use all states.
  
      Returns
      -------
      data_contributions : array
          Contributions of observations to the decomposed object. If the
          smoothed state is being decomposed, then `data_contributions` are
          shaped `(nobs, k_states, nobs, k_endog)`, where the
          `(t, m, j, p)`-th element is the contribution of the `p`-th
          observation at time `j` to the `m`-th state at time `t`. If the
          smoothed signal is being decomposed, then `data_contributions` are
          shaped `(nobs, k_endog, nobs, k_endog)`, where the
          `(t, k, j, p)`-th element is the contribution of the `p`-th
          observation at time `j` to the smoothed prediction of the `k`-th
          observation at time `t`.
      obs_intercept_contributions : array
          Contributions of the observation intercept to the decomposed
          object. If the smoothed state is being decomposed, then
          `obs_intercept_contributions` are shaped
          `(nobs, k_states, nobs, k_endog)`, where the `(t, m, j, p)`-th
          element is the contribution of the `p`-th observation intercept at
          time `j` to the `m`-th state at time `t`. If the smoothed signal
          is being decomposed, then `obs_intercept_contributions` are shaped
          `(nobs, k_endog, nobs, k_endog)`, where the `(t, k, j, p)`-th
          element is the contribution of the `p`-th observation at time `j`
          to the smoothed prediction of the `k`-th observation at time `t`.
      state_intercept_contributions : array
          Contributions of the state intercept to the decomposed object. If
          the smoothed state is being decomposed, then
          `state_intercept_contributions` are shaped
          `(nobs, k_states, nobs, k_states)`, where the `(t, m, j, l)`-th
          element is the contribution of the `l`-th state intercept at
          time `j` to the `m`-th state at time `t`. If the smoothed signal
          is being decomposed, then `state_intercept_contributions` are
          shaped `(nobs, k_endog, nobs, k_endog)`, where the
          `(t, k, j, l)`-th element is the contribution of the `p`-th
          observation at time `j` to the smoothed prediction of the `k`-th
          observation at time `t`.
      prior_contributions : array
          Contributions of the prior to the decomposed object. If the
          smoothed state is being decomposed, then `prior_contributions` are
          shaped `(nobs, k_states, k_states)`, where the `(t, m, l)`-th
          element is the contribution of the `l`-th element of the prior
          mean to the `m`-th state at time `t`. If the smoothed signal is
          being decomposed, then `prior_contributions` are shaped
          `(nobs, k_endog, k_states)`, where the `(t, k, l)`-th
          element is the contribution of the `l`-th element of the prior mean
          to the smoothed prediction of the `k`-th observation at time `t`.
  
      Notes
      -----
      Denote the smoothed state at time :math:`t` by :math:`\alpha_t`. Then
      the smoothed signal is :math:`Z_t \alpha_t`, where :math:`Z_t` is the
      design matrix operative at time :math:`t`.
      """
      if decomposition_of not in ["smoothed_state", "smoothed_signal"]:
          raise ValueError(
              "Invalid value for `decomposition_of`. Must be"
              ' one of "smoothed_state" or "smoothed_signal".'
          )
  
      (
          weights,
          state_intercept_weights,
          prior_weights,
      ) = tools._compute_smoothed_state_weights(
          self.model, compute_prior_weights=True, scale=self.scale
      )
  
      # Get state space objects
      ZT = self.model.design.T  # t, m, p
      dT = self.model.obs_intercept.T  # t, p
      cT = self.model.state_intercept.T  # t, m
  
      # Subset the states used for the impacts if applicable
      if (
          decomposition_of == "smoothed_signal"
          and state_index is not None
      ):
          ZT = ZT[:, state_index, :]
          weights = weights[:, :, state_index]
          prior_weights = prior_weights[:, state_index, :]
  
      # Convert the weights in terms of smoothed signal
      # t, j, m, p, i
      if decomposition_of == "smoothed_signal":
          # Multiplication gives: t, j, m, p * t, j, m, p, k
          # Sum along axis=2 gives: t, j, p, k
          # Transpose to: t, j, k, p (i.e. like t, j, m, p but with k instead
          # of m)
          weights = np.nansum(
              weights[..., None] * ZT[:, None, :, None, :], axis=2
          ).transpose(0, 1, 3, 2)
  
          # Multiplication gives: t, j, m, l * t, j, m, l, k
          # Sum along axis=2 gives: t, j, l, k
          # Transpose to: t, j, k, l (i.e. like t, j, m, p but with k instead
          # of m and l instead of p)
          state_intercept_weights = np.nansum(
              state_intercept_weights[..., None]
              * ZT[:, None, :, None, :],
              axis=2,
          ).transpose(0, 1, 3, 2)
  
          # Multiplication gives: t, m, l * t, m, l, k = t, m, l, k
          # Sum along axis=1 gives: t, l, k
          # Transpose to: t, k, l (i.e. like t, m, l but with k instead of m)
          prior_weights = np.nansum(
              prior_weights[..., None] * ZT[:, :, None, :], axis=1
          ).transpose(0, 2, 1)
  
      # Contributions of observations: multiply weights by observations
      # Multiplication gives t, j, {m,k}, p
      data_contributions = (
          weights * self.model.endog.T[None, :, None, :]
      )
      # Transpose to: t, {m,k}, j, p
      data_contributions = data_contributions.transpose(0, 2, 1, 3)
  
      # Contributions of obs intercept: multiply data weights by obs
      # intercept
      # Multiplication gives t, j, {m,k}, p
      obs_intercept_contributions = -weights * dT[None, :, None, :]
      # Transpose to: t, {m,k}, j, p
      obs_intercept_contributions = (
          obs_intercept_contributions.transpose(0, 2, 1, 3)
      )
  
      # Contributions of state intercept: multiply state intercept weights
      # by state intercept
      # Multiplication gives t, j, {m,k}, l
      state_intercept_contributions = (
          state_intercept_weights * cT[None, :, None, :]
      )
      # Transpose to: t, {m,k}, j, l
      state_intercept_contributions = (
          state_intercept_contributions.transpose(0, 2, 1, 3)
      )
  
      # Contributions of prior: multiply weights by prior
      # Multiplication gives t, {m, k}, l
      prior_contributions = (
          prior_weights * self.initial_state[None, None, :]
      )
  
      return (
          data_contributions,
          obs_intercept_contributions,
          state_intercept_contributions,
          prior_contributions,
      )
  
imports: import numpy
  from types import SimpleNamespace
  from statsmodels.tsa.statespace.representation import OptionWrapper
  from statsmodels.tsa.statespace.kalman_filter import KalmanFilter, FilterResults
  from statsmodels.tsa.statespace.tools import reorder_missing_matrix, reorder_missing_vector, copy_index_matrix
  from statsmodels.tsa.statespace import tools, initialization
label_desc: Use image node_id 11 for calling the SmootherResults obj's underlying member method code with example usage: obj.get_smoothed_decomposition(decomposition_of, state_index) and returns: data_contributions,  obs_intercept_contributions,  state_intercept_contributions,  prior_contributions