code: def test_poisson_power_2ratio():
      # power compared to PASS documentation
  
      rate1, rate2 = 2.2, 2.2
      nobs1, nobs2 = 95, 95
      # nobs_ratio = 1
      alpha = 0.025
      exposure = 2.5
      low, upp = 0.8, 1.25
      dispersion = 1
  
      # check power of equivalence test
      cases = [
          (1.9, 704, 704, 0.90012),
          (2.0, 246, 246, 0.90057),
          (2.2, 95, 95, 0.90039),
          (2.5, 396, 396, 0.90045),
      ]
  
      for case in cases:
          rate1, nobs1, nobs2, p = case
          pow_ = power_equivalence_poisson_2indep(
              rate1,
              rate2,
              nobs1,
              low,
              upp,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              alpha=alpha,
              dispersion=dispersion,
          )
          assert_allclose(pow_, p, atol=5e-5)
  
          # compare other method_var for similar results
          pow_2 = power_equivalence_poisson_2indep(
              rate1,
              rate2,
              nobs1,
              low,
              upp,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              alpha=alpha,
              method_var="score",
              dispersion=dispersion,
          )
  
          assert_allclose(pow_2, p, rtol=5e-3)
  
      # check power of onesided test, smaller with a margin
      # non-inferiority
      # alternative smaller H1: rate1 / rate2 < R
      cases = [
          (1.8, 29, 29, 0.90056),
          (1.9, 39, 39, 0.90649),
          (2.2, 115, 115, 0.90014),
          (2.4, 404, 404, 0.90064),
      ]
  
      low = 1.2
      for case in cases:
          rate1, nobs1, nobs2, p = case
          pow_ = power_poisson_ratio_2indep(
              rate1,
              rate2,
              nobs1,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              value=low,
              alpha=0.025,
              dispersion=1,
              alternative="smaller",
          )
  
          assert_allclose(pow_, p, atol=5e-5)
  
          pow_ = power_poisson_ratio_2indep(
              rate1,
              rate2,
              nobs1,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              value=low,
              alpha=0.05,
              dispersion=1,
              alternative="two-sided",
          )
          assert_allclose(pow_, p, atol=5e-5)
  
      # check size, power at null
      pow_ = power_poisson_ratio_2indep(
          rate1,
          rate2,
          nobs1,
          nobs_ratio=nobs2 / nobs1,
          exposure=exposure,
          value=rate1 / rate2,
          alpha=0.05,
          dispersion=1,
          alternative="two-sided",
      )
      assert_allclose(pow_, 0.05, atol=5e-5)
  
      # check power of onesided test, larger with a margin (superiority)
      # alternative larger H1: rate1 / rate2 > R
      # here I just reverse the case of smaller alternative
  
      cases = [
          (1.8, 29, 29, 0.90056),
          (1.9, 39, 39, 0.90649),
          (2.2, 115, 115, 0.90014),
          (2.4, 404, 404, 0.90064),
      ]
  
      rate1 = 2.2
      low = 1 / 1.2
      for case in cases:
          rate2, nobs1, nobs2, p = case
          pow_ = power_poisson_ratio_2indep(
              rate1,
              rate2,
              nobs1,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              value=low,
              alpha=0.025,
              dispersion=1,
              alternative="larger",
          )
          assert_allclose(pow_, p, atol=5e-5)
  
          # compare other method_var for similar results
          pow_2 = power_poisson_ratio_2indep(
              rate1,
              rate2,
              nobs1,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              value=low,
              alpha=0.025,
              method_var="score",
              dispersion=1,
              alternative="larger",
          )
          assert_allclose(pow_2, p, rtol=5e-3)
  
          pow_ = power_poisson_ratio_2indep(
              rate1,
              rate2,
              nobs1,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              value=low,
              alpha=0.05,
              dispersion=1,
              alternative="two-sided",
          )
          assert_allclose(pow_, p, atol=5e-5)
  
          # compare other method_var for similar results
          pow_2 = power_poisson_ratio_2indep(
              rate1,
              rate2,
              nobs1,
              nobs_ratio=nobs2 / nobs1,
              exposure=exposure,
              value=low,
              alpha=0.05,
              method_var="score",
              dispersion=1,
              alternative="two-sided",
          )
          assert_allclose(pow_2, p, rtol=5e-3)
  
imports: import pytest
  import warnings
  import numpy
  from numpy import arange
  from numpy.testing import assert_allclose, assert_equal
  from scipy import stats
  import statsmodels.stats.rates
  from statsmodels.stats.rates import confint_poisson, tolerance_int_poisson, confint_quantile_poisson, etest_poisson_2indep, confint_poisson_2indep, nonequivalence_poisson_2indep, power_poisson_ratio_2indep, power_equivalence_poisson_2indep, power_poisson_diff_2indep, power_equivalence_neginb_2indep, power_negbin_ratio_2indep, method_names_poisson_1samp, method_names_poisson_2indep
label_desc: Use image node_id 15 for calling a global function with example usage: test_poisson_power_2ratio() without return types