code: def bayesfactor_ttest(
      t, nx, ny=None, paired=False, alternative="two-sided", r=0.707
  ):
      """
      Bayes Factor of a T-test.
  
      Parameters
      ----------
      t : float
          T-value of the T-test
      nx : int
          Sample size of first group
      ny : int
          Sample size of second group (only needed in case of an independent
          two-sample T-test)
      paired : boolean
          Specify whether the two observations are related (i.e. repeated
          measures) or independent.
      alternative : string
          Defines the alternative hypothesis, or tail of the test. Must be one of
          "two-sided" (default), "greater" or "less".
  
          .. warning:: One-sided Bayes Factor (BF) are simply obtained by
              doubling the two-sided BF, which is not the same behavior
              as R or JASP. Be extra careful when interpretating one-sided BF,
              and if you can, always double-check your results.
      r : float
          Cauchy scale factor. Smaller values of ``r`` (e.g. 0.5), may be
          appropriate when small effect sizes are expected a priori; larger
          values of ``r`` are appropriate when large effect sizes are
          expected (Rouder et al 2009). The default is
          :math:`\\sqrt{2} / 2 \\approx 0.707`.
  
      Returns
      -------
      bf : float
          Scaled Jeffrey-Zellner-Siow (JZS) Bayes Factor (BF10).
          The Bayes Factor quantifies the evidence in favour of the
          alternative hypothesis.
  
      See also
      --------
      ttest : T-test
      pairwise_test : Pairwise T-tests
      bayesfactor_pearson : Bayes Factor of a correlation
      bayesfactor_binom : Bayes Factor of a binomial test
  
      Notes
      -----
      Adapted from a Matlab code found at
      https://github.com/anne-urai/Tools/tree/master/stats/BayesFactors
  
      If you would like to compute the Bayes Factor directly from the raw data
      instead of from the T-value, use the :py:func:`pingouin.ttest` function.
  
      The JZS Bayes Factor is approximated using the formula described
      in ref [1]_:
  
      .. math::
  
          \\text{BF}_{10} = \\frac{\\int_{0}^{\\infty}(1 + Ngr^2)^{-1/2}
          (1 + \\frac{t^2}{v(1 + Ngr^2)})^{-(v+1) / 2}(2\\pi)^{-1/2}g^
          {-3/2}e^{-1/2g}}{(1 + \\frac{t^2}{v})^{-(v+1) / 2}}
  
      where :math:`t` is the T-value, :math:`v` the degrees of freedom,
      :math:`N` the sample size, :math:`r` the Cauchy scale factor
      (= prior on effect size) and :math:`g` is is an auxiliary variable
      that is integrated out numerically.
  
      Results have been validated against JASP and the BayesFactor R package.
  
      References
      ----------
      .. [1] Rouder, J.N., Speckman, P.L., Sun, D., Morey, R.D., Iverson, G.,
         2009. Bayesian t tests for accepting and rejecting the null hypothesis.
         Psychon. Bull. Rev. 16, 225–237. https://doi.org/10.3758/PBR.16.2.225
  
      Examples
      --------
      1. Bayes Factor of an independent two-sample T-test
  
      >>> from pingouin import bayesfactor_ttest
      >>> bf = bayesfactor_ttest(3.5, 20, 20)
      >>> print("Bayes Factor: %.3f (two-sample independent)" % bf)
      Bayes Factor: 26.743 (two-sample independent)
  
      2. Bayes Factor of a paired two-sample T-test
  
      >>> bf = bayesfactor_ttest(3.5, 20, 20, paired=True)
      >>> print("Bayes Factor: %.3f (two-sample paired)" % bf)
      Bayes Factor: 17.185 (two-sample paired)
  
      3. Now specifying the direction of the test
  
      >>> tval = -3.5
      >>> bf_greater = bayesfactor_ttest(tval, 20, alternative='greater')
      >>> bf_less = bayesfactor_ttest(tval, 20, alternative='less')
      >>> print("BF10-greater: %.3f | BF10-less: %.3f" % (bf_greater, bf_less))
      BF10-greater: 0.029 | BF10-less: 34.369
      """
      # Check tail
      assert alternative in [
          "two-sided",
          "greater",
          "less",
      ], "Alternative must be one of 'two-sided' (default), 'greater' or 'less'."
      one_sample = True if ny is None or ny == 1 else False
  
      # Check T-value
      assert isinstance(
          t, (int, float)
      ), "The T-value must be a int or a float."
      if not np.isfinite(t):
          return np.nan
  
      # Function to be integrated
      def fun(g, t, n, r, df):
          return (
              (1 + n * g * r**2) ** (-0.5)
              * (1 + t**2 / ((1 + n * g * r**2) * df))
              ** (-(df + 1) / 2)
              * (2 * pi) ** (-0.5)
              * g ** (-3.0 / 2)
              * exp(-1 / (2 * g))
          )
  
      # Define n and degrees of freedom
      if one_sample or paired:
          n = nx
          df = n - 1
      else:
          n = nx * ny / (nx + ny)
          df = nx + ny - 2
  
      # JZS Bayes factor calculation: eq. 1 in Rouder et al. (2009)
      integr = quad(fun, 0, np.inf, args=(t, n, r, df))[0]
      bf10 = 1 / ((1 + t**2 / df) ** (-(df + 1) / 2) / integr)
  
      # Tail
      tail_binary = (
          "two-sided" if alternative == "two-sided" else "one-sided"
      )
      bf10 = bf10 * (1 / 0.5) if tail_binary == "one-sided" else bf10
      # Now check the direction of the test
      if (
          (alternative == "greater" and t < 0)
          or (alternative == "less" and t > 0)
      ) and bf10 > 1:
          bf10 = 1 / bf10
      return bf10
  
imports: import warnings
  import numpy
  from scipy.integrate import quad
  from math import pi, exp, log, lgamma
label_desc: Use image node_id 2 for calling a global function with example usage: bayesfactor_ttest(t, nx, ny, paired, alternative, r) and returns: bf10, np, unknown