code: def test_results_from_r(self, parameters, rresult):
      alternative = parameters.alternative.replace(".", "-")
      result = odds_ratio(parameters.table)
      # The results computed by R are not very accurate.
      if result.statistic < 400:
          or_rtol = 5e-4
          ci_rtol = 2e-2
      else:
          or_rtol = 5e-2
          ci_rtol = 1e-1
      assert_allclose(
          result.statistic, rresult.conditional_odds_ratio, rtol=or_rtol
      )
      ci = result.confidence_interval(
          parameters.confidence_level, alternative
      )
      assert_allclose(
          (ci.low, ci.high),
          rresult.conditional_odds_ratio_ci,
          rtol=ci_rtol,
      )
  
      # Also do a self-check for the conditional odds ratio.
      # With the computed conditional odds ratio as the noncentrality
      # parameter of the noncentral hypergeometric distribution with
      # parameters table.sum(), table[0].sum(), and table[:,0].sum() as
      # total, ngood and nsample, respectively, the mean of the distribution
      # should equal table[0, 0].
      cor = result.statistic
      table = np.array(parameters.table)
      total = table.sum()
      ngood = table[0].sum()
      nsample = table[:, 0].sum()
      # nchypergeom_fisher does not allow the edge cases where the
      # noncentrality parameter is 0 or inf, so handle those values
      # separately here.
      if cor == 0:
          nchg_mean = hypergeom.support(total, ngood, nsample)[0]
      elif cor == np.inf:
          nchg_mean = hypergeom.support(total, ngood, nsample)[1]
      else:
          nchg_mean = nchypergeom_fisher.mean(
              total, ngood, nsample, cor
          )
      assert_allclose(nchg_mean, table[0, 0], rtol=1e-13)
  
      # Check that the confidence interval is correct.
      alpha = 1 - parameters.confidence_level
      if alternative == "two-sided":
          if ci.low > 0:
              sf = nchypergeom_fisher.sf(
                  table[0, 0] - 1, total, ngood, nsample, ci.low
              )
              assert_allclose(sf, alpha / 2, rtol=1e-11)
          if np.isfinite(ci.high):
              cdf = nchypergeom_fisher.cdf(
                  table[0, 0], total, ngood, nsample, ci.high
              )
              assert_allclose(cdf, alpha / 2, rtol=1e-11)
      elif alternative == "less":
          if np.isfinite(ci.high):
              cdf = nchypergeom_fisher.cdf(
                  table[0, 0], total, ngood, nsample, ci.high
              )
              assert_allclose(cdf, alpha, rtol=1e-11)
      else:
          # alternative == 'greater'
          if ci.low > 0:
              sf = nchypergeom_fisher.sf(
                  table[0, 0] - 1, total, ngood, nsample, ci.low
              )
              assert_allclose(sf, alpha, rtol=1e-11)
  
file_path: scipy/scipy/stats/tests/test_odds_ratio.py
imports: import pytest
  import numpy
  from numpy.testing import assert_equal, assert_allclose
  from .._discrete_distns import nchypergeom_fisher, hypergeom
  from scipy.stats._odds_ratio import odds_ratio
  from .data.fisher_exact_results_from_r import data
label_desc: Use image node_id 1 for calling the TestOddsRatio obj's underlying member method code with example usage: obj.test_results_from_r(parameters, rresult) without return types