code: def test_poisson(
      count,
      nobs,
      value,
      method=None,
      alternative="two-sided",
      dispersion=1,
  ):
      """Test for one sample poisson mean or rate
  
      Parameters
      ----------
      count : array_like
          Observed count, number of events.
      nobs : arrat_like
          Currently this is total exposure time of the count variable.
          This will likely change.
      value : float, array_like
          This is the value of poisson rate under the null hypothesis.
      method : str
          Method to use for confidence interval.
          This is required, there is currently no default method.
          See Notes for available methods.
      alternative : {'two-sided', 'smaller', 'larger'}
          alternative hypothesis, which can be two-sided or either one of the
          one-sided tests.
      dispersion : float
          Dispersion scale coefficient for Poisson QMLE. Default is that the
          data follows a Poisson distribution. Dispersion different from 1
          correspond to excess-dispersion in Poisson quasi-likelihood (GLM).
          Dispersion coeffficient different from one is currently only used in
          wald and score method.
  
      Returns
      -------
      HolderTuple instance with test statistic, pvalue and other attributes.
  
      Notes
      -----
      The implementatio of the hypothesis test is mainly based on the references
      for the confidence interval, see confint_poisson.
  
      Available methods are:
  
      - "score" : based on score test, uses variance under null value
      - "wald" : based on wald test, uses variance base on estimated rate.
      - "waldccv" : based on wald test with 0.5 count added to variance
        computation. This does not use continuity correction for the center of
        the confidence interval.
      - "exact-c" central confidence interval based on gamma distribution
      - "midp-c" : based on midp correction of central exact confidence interval.
        this uses numerical inversion of the test function. not vectorized.
      - "sqrt" : based on square root transformed counts
      - "sqrt-a" based on Anscombe square root transformation of counts + 3/8.
  
      See Also
      --------
      confint_poisson
  
      """
  
      n = nobs  # short hand
      rate = count / n
  
      if method is None:
          msg = "method needs to be specified, currently no default method"
          raise ValueError(msg)
  
      if dispersion != 1:
          if method not in ["wald", "waldcc", "score"]:
              msg = "excess dispersion only supported in wald and score methods"
              raise ValueError(msg)
  
      dist = "normal"
  
      if method == "wald":
          std = np.sqrt(dispersion * rate / n)
          statistic = (rate - value) / std
  
      elif method == "waldccv":
          # WCC in Barker 2002
          # add 0.5 event, not 0.5 event rate as in waldcc
          # std = np.sqrt((rate + 0.5 / n) / n)
          # statistic = (rate + 0.5 / n - value) / std
          std = np.sqrt(dispersion * (rate + 0.5 / n) / n)
          statistic = (rate - value) / std
  
      elif method == "score":
          std = np.sqrt(dispersion * value / n)
          statistic = (rate - value) / std
          pvalue = stats.norm.sf(statistic)
  
      elif method.startswith("exact-c") or method.startswith("midp-c"):
          pv1 = stats.poisson.cdf(count, n * value)
          pv2 = stats.poisson.sf(count - 1, n * value)
          if method.startswith("midp-c"):
              pv1 = pv1 - 0.5 * stats.poisson.pmf(count, n * value)
              pv2 = pv2 - 0.5 * stats.poisson.pmf(count, n * value)
          if alternative == "two-sided":
              pvalue = 2 * np.minimum(pv1, pv2)
          elif alternative == "larger":
              pvalue = pv2
          elif alternative == "smaller":
              pvalue = pv1
          else:
              msg = 'alternative should be "two-sided", "larger" or "smaller"'
              raise ValueError(msg)
  
          statistic = np.nan
          dist = "Poisson"
  
      elif method == "sqrt":
          std = 0.5
          statistic = (np.sqrt(count) - np.sqrt(n * value)) / std
  
      elif method == "sqrt-a":
          # anscombe, based on Swift 2009 (with transformation to rate)
          std = 0.5
          statistic = (
              np.sqrt(count + 3 / 8) - np.sqrt(n * value + 3 / 8)
          ) / std
  
      elif method == "sqrt-v":
          # vandenbroucke, based on Swift 2009 (with transformation to rate)
          std = 0.5
          crit = stats.norm.isf(0.025)
          statistic = (
              np.sqrt(count + (crit**2 + 2) / 12)
              -
              # np.sqrt(n * value + (crit**2 + 2) / 12)) / std
              np.sqrt(n * value)
          ) / std
  
      else:
          raise ValueError("unknown method %s" % method)
  
      if dist == "normal":
          statistic, pvalue = _zstat_generic2(statistic, 1, alternative)
  
      res = HolderTuple(
          statistic=statistic,
          pvalue=np.clip(pvalue, 0, 1),
          distribution=dist,
          method=method,
          alternative=alternative,
          rate=rate,
          nobs=n,
      )
      return res
  
imports: import numpy
  import warnings
  from scipy import stats, optimize
  from statsmodels.stats.base import HolderTuple
  from statsmodels.stats.weightstats import _zstat_generic2
  from statsmodels.stats._inference_tools import _mover_confint
label_desc: Use image node_id 1 for calling a global function with example usage: test_poisson(count, nobs, value, method, alternative, dispersion) and returns: res