code: def q_stat(x, nobs):
      """
      Compute Ljung-Box Q Statistic.
  
      Parameters
      ----------
      x : array_like
          Array of autocorrelation coefficients.  Can be obtained from acf.
      nobs : int, optional
          Number of observations in the entire sample (ie., not just the length
          of the autocorrelation function results.
  
      Returns
      -------
      q-stat : ndarray
          Ljung-Box Q-statistic for autocorrelation parameters.
      p-value : ndarray
          P-value of the Q statistic.
  
      See Also
      --------
      statsmodels.stats.diagnostic.acorr_ljungbox
          Ljung-Box Q-test for autocorrelation in time series based
          on a time series rather than the estimated autocorrelation
          function.
  
      Notes
      -----
      Designed to be used with acf.
      """
      x = array_like(x, "x")
      nobs = int_like(nobs, "nobs")
  
      ret = (
          nobs
          * (nobs + 2)
          * np.cumsum(
              (1.0 / (nobs - np.arange(1, len(x) + 1))) * x**2
          )
      )
      chi2 = stats.chi2.sf(ret, np.arange(1, len(x) + 1))
      return ret, chi2
  
imports: from __future__ import annotations
  from statsmodels.compat.numpy import lstsq
  from statsmodels.compat.pandas import deprecate_kwarg
  from statsmodels.compat.python import Literal, lzip
  from statsmodels.compat.scipy import _next_regular
  from typing import Union
  import warnings
  import numpy
  from numpy.linalg import LinAlgError
  import pandas
  from scipy import stats
  from scipy.interpolate import interp1d
  from scipy.signal import correlate
  from statsmodels.regression.linear_model import OLS, yule_walker
  from statsmodels.tools.sm_exceptions import CollinearityWarning, InfeasibleTestError, InterpolationWarning, MissingDataError, ValueWarning
  from statsmodels.tools.tools import Bunch, add_constant
  from statsmodels.tools.validation import array_like, bool_like, dict_like, float_like, int_like, string_like
  from statsmodels.tsa._bds import bds
  from statsmodels.tsa._innovations import innovations_algo, innovations_filter
  from statsmodels.tsa.adfvalues import mackinnoncrit, mackinnonp
  from statsmodels.tsa.tsatools import add_trend, lagmat, lagmat2ds
label_desc: Use image node_id 4 for calling a global function with example usage: q_stat(x, nobs) and returns: ret,  chi2