class_docstr: Class to hold results from fitting a state space model.
  
  Parameters
  ----------
  model : MLEModel instance
      The fitted model instance
  params : ndarray
      Fitted parameters
  
  Attributes
  ----------
  model : Model instance
      A reference to the model that was fit.
  nobs : float
      The number of observations used to fit the model.
  params : ndarray
      The parameters of the model.
class_docstr_tok: ["Class","to","hold","results","from","fitting","a","state","space","model",".","Parameters","--","--","--","--","--","model",":","MLEModel","instance","The","fitted","model","instance","params",":","ndarray","Fitted","parameters","Attributes","--","--","--","--","--","model",":","Model","instance","A","reference","to","the","model","that","was","fit",".","nobs",":","float","The","number","of","observations","used","to","fit","the","model",".","params",":","ndarray","The","parameters","of","the","model","."]
docstr: Ljung-Box test for no serial correlation of standardized residuals
  
  Null hypothesis is no serial correlation.
  
  Parameters
  ----------
  method : {'ljungbox','boxpierece', None}
      The statistical test for serial correlation. If None, an attempt is
      made to select an appropriate test.
  lags : None, int or array_like
      If lags is an integer then this is taken to be the largest lag
      that is included, the test result is reported for all smaller lag
      length.
      If lags is a list or array, then all lags are included up to the
      largest lag in the list, however only the tests for the lags in the
      list are reported.
      If lags is None, then the default maxlag is min(10, nobs//5) for
      non-seasonal time series and min (2*m, nobs//5) for seasonal time
      series.
  
  Returns
  -------
  output : ndarray
      An array with `(test_statistic, pvalue)` for each endogenous
      variable and each lag. The array is then sized
      `(k_endog, 2, lags)`. If the method is called as
      `ljungbox = res.test_serial_correlation()`, then `ljungbox[i]`
      holds the results of the Ljung-Box test (as would be returned by
      `statsmodels.stats.diagnostic.acorr_ljungbox`) for the `i` th
      endogenous variable.
  
  See Also
  --------
  statsmodels.stats.diagnostic.acorr_ljungbox
      Ljung-Box test for serial correlation.
  
  Notes
  -----
  For statespace models: let `d` = max(loglikelihood_burn, nobs_diffuse);
  this test is calculated ignoring the first `d` residuals.
  
  Output is nan for any endogenous variable which has missing values.
docstr_tok: ["Ljung-Box","test","for","no","serial","correlation","of","standardized","residuals","Null","hypothesis","is","no","serial","correlation",".","Parameters","--","--","--","--","--","method",":","{","'ljungbox","'",",","'boxpierece","'",",","None","}","The","statistical","test","for","serial","correlation",".","If","None",",","an","attempt","is","made","to","select","an","appropriate","test",".","lags",":","None",",","int","or","array_like","If","lags","is","an","integer","then","this","is","taken","to","be","the","largest","lag","that","is","included",",","the","test","result","is","reported","for","all","smaller","lag","length",".","If","lags","is","a","list","or","array",",","then","all","lags","are","included","up","to","the","largest","lag","in","the","list",",","however","only","the","tests","for","the","lags","in","the","list","are","reported",".","If","lags","is","None",",","then","the","default","maxlag","is","min","(","10",",","nobs\/\/5",")","for","non-seasonal","time","series","and","min","(","2","*","m",",","nobs\/\/5",")","for","seasonal","time","series",".","Returns","--","--","--","-","output",":","ndarray","An","array","with","`","(","test_statistic",",","pvalue",")","`","for","each","endogenous","variable","and","each","lag",".","The","array","is","then","sized","`","(","k_endog",",","2",",","lags",")","`",".","If","the","method","is","called","as","`","ljungbox","=","res.test_serial_correlation","(",")","`",",","then","`","ljungbox","[","i","]","`","holds","the","results","of","the","Ljung-Box","test","(","as","would","be","returned","by","`","statsmodels.stats.diagnostic.acorr_ljungbox","`",")","for","the","`","i","`","th","endogenous","variable",".","See","Also","--","--","--","--","statsmodels.stats.diagnostic.acorr_ljungbox","Ljung-Box","test","for","serial","correlation",".","Notes","--","--","-","For","statespace","models",":","let","`","d","`","=","max","(","loglikelihood_burn",",","nobs_diffuse",")",";","this","test","is","calculated","ignoring","the","first","`","d","`","residuals",".","Output","is","nan","for","any","endogenous","variable","which","has","missing","values","."]
code: def test_serial_correlation(self, method, lags=None):
      """
      Ljung-Box test for no serial correlation of standardized residuals
  
      Null hypothesis is no serial correlation.
  
      Parameters
      ----------
      method : {'ljungbox','boxpierece', None}
          The statistical test for serial correlation. If None, an attempt is
          made to select an appropriate test.
      lags : None, int or array_like
          If lags is an integer then this is taken to be the largest lag
          that is included, the test result is reported for all smaller lag
          length.
          If lags is a list or array, then all lags are included up to the
          largest lag in the list, however only the tests for the lags in the
          list are reported.
          If lags is None, then the default maxlag is min(10, nobs//5) for
          non-seasonal time series and min (2*m, nobs//5) for seasonal time
          series.
  
      Returns
      -------
      output : ndarray
          An array with `(test_statistic, pvalue)` for each endogenous
          variable and each lag. The array is then sized
          `(k_endog, 2, lags)`. If the method is called as
          `ljungbox = res.test_serial_correlation()`, then `ljungbox[i]`
          holds the results of the Ljung-Box test (as would be returned by
          `statsmodels.stats.diagnostic.acorr_ljungbox`) for the `i` th
          endogenous variable.
  
      See Also
      --------
      statsmodels.stats.diagnostic.acorr_ljungbox
          Ljung-Box test for serial correlation.
  
      Notes
      -----
      For statespace models: let `d` = max(loglikelihood_burn, nobs_diffuse);
      this test is calculated ignoring the first `d` residuals.
  
      Output is nan for any endogenous variable which has missing values.
      """
      if method is None:
          method = "ljungbox"
  
      if self.standardized_forecasts_error is None:
          raise ValueError(
              "Cannot compute test statistic when standardized"
              " forecast errors have not been computed."
          )
  
      if method == "ljungbox" or method == "boxpierce":
          from statsmodels.stats.diagnostic import acorr_ljungbox
  
          if hasattr(self, "loglikelihood_burn"):
              d = np.maximum(self.loglikelihood_burn, self.nobs_diffuse)
              # This differs from self.nobs_effective because here we want to
              # exclude exact diffuse periods, whereas self.nobs_effective
              # only excludes explicitly burned (usually approximate diffuse)
              # periods.
              nobs_effective = self.nobs - d
          else:
              nobs_effective = self.nobs_effective
          output = []
  
          # Default lags for acorr_ljungbox is 40, but may not always have
          # that many observations
          if lags is None:
              seasonal_periods = getattr(
                  self.model, "seasonal_periods", 0
              )
              if seasonal_periods:
                  lags = min(2 * seasonal_periods, nobs_effective // 5)
              else:
                  lags = min(10, nobs_effective // 5)
  
          cols = [2, 3] if method == "boxpierce" else [0, 1]
          for i in range(self.model.k_endog):
              if hasattr(self, "filter_results"):
                  x = self.filter_results.standardized_forecasts_error[
                      i
                  ][d:]
              else:
                  x = self.standardized_forecasts_error
              results = acorr_ljungbox(
                  x, lags=lags, boxpierce=(method == "boxpierce")
              )
              output.append(np.asarray(results)[:, cols].T)
  
          output = np.c_[output]
      else:
          raise NotImplementedError(
              "Invalid serial correlation test" " method."
          )
      return output
  
imports: from collections import OrderedDict
  import contextlib
  import warnings
  import numpy
  import pandas
  from scipy.stats import norm
  from statsmodels.base.data import PandasData
  from statsmodels.tools.decorators import cache_readonly
  from statsmodels.tools.eval_measures import aic, aicc, bic, hqic
  from statsmodels.tools.sm_exceptions import PrecisionWarning
  from statsmodels.tools.numdiff import _get_epsilon, approx_fprime, approx_fprime_cs, approx_hess_cs
  from statsmodels.tools.tools import pinv_extended
  import statsmodels.tsa.base.tsa_model
  from statsmodels.tsa.statespace.tools import _safe_cond
label_desc: Use image node_id 19 for calling the StateSpaceMLEResults obj's underlying member method code with example usage: obj.test_serial_correlation(method, lags) and returns: output