code: def bayesfactor_binom(k, n, p=0.5, a=1, b=1):
      """
      Bayes factor of a binomial test with :math:`k` successes,
      :math:`n` trials and base probability :math:`p`.  This means that
      the null hypothesis is that the probability is :math:`p`.  It is
      compared against the alternative hypothesis that :math:`p` is from
      the Beta distribution with parameters :math:`(a, b)`.  By default,
      both :math:`a` and :math:`b` are 1, making the alternative
      hypothesis equivalent to the uniform distribution, i.e., we are
      completely uninformed about :math:`p`.
  
      Parameters
      ----------
      k : int
          Number of successes.
      n : int
          Number of trials.
      p : float
          Base probability of success (range from 0 to 1).
      a : float
          The "a" parameter of the Beta distribution.
      b : float
          The "b" parameter of the Beta distribution.
  
      Returns
      -------
      bf10 : float
          The Bayes Factor quantifies the evidence in favour of the
          alternative hypothesis, where the null hypothesis is that
          the random variable is binomially distributed with base probability
          :math:`p`.
  
      See also
      --------
      bayesfactor_pearson : Bayes Factor of a correlation
      bayesfactor_ttest : Bayes Factor of a T-test
  
      Notes
      -----
      Adapted from a Matlab code found at
      https://github.com/anne-urai/Tools/blob/master/stats/BayesFactors/binombf.m
  
      The Bayes Factor is given by the formula below:
  
      .. math::
  
          BF_{10} = \\frac{\\int_0^1 \\binom{n}{k}g^k(1-g)^{n-k}}
          {\\binom{n}{k} p^k (1-p)^{n-k}}
  
      References
      ----------
      * http://pcl.missouri.edu/bf-binomial
  
      * https://en.wikipedia.org/wiki/Bayes_factor
  
      Examples
      --------
      We want to determine if a coin if fair. After tossing the coin 200 times
      in a row, we report 115 heads (hereafter referred to as "successes") and 85
      tails ("failures"). The Bayes Factor can be easily computed using Pingouin:
  
      >>> import pingouin as pg
      >>> bf = float(pg.bayesfactor_binom(k=115, n=200, p=0.5))
      >>> # Note that Pingouin returns the BF-alt by default.
      >>> # BF-null is simply 1 / BF-alt
      >>> print("BF-null: %.3f, BF-alt: %.3f" % (1 / bf, bf))
      BF-null: 1.197, BF-alt: 0.835
  
      Since the Bayes Factor of the null hypothesis ("the coin is fair") is
      higher than the Bayes Factor of the alternative hypothesis
      ("the coin is not fair"), we can conclude that there is more evidence to
      support the fact that the coin is indeed fair. However, the strength of the
      evidence in favor of the null hypothesis (1.197) is "barely worth
      mentionning" according to Jeffreys's rule of thumb.
  
      Interestingly, a frequentist alternative to this test would give very
      different results. It can be performed using the
      :py:func:`scipy.stats.binom_test` function:
  
      >>> from scipy.stats import binomtest
      >>> result = binomtest(k=115, n=200, p=0.5)
      >>> round(result.pvalue, 5)
      0.04004
  
      The binomial test rejects the null hypothesis that the coin is fair at the
      5% significance level (p=0.04). Thus, whereas a frequentist hypothesis test
      would yield significant results at the 5% significance level, the Bayes
      factor indicates preference of the null hypothesis to the alternative
      hypothesis that we know nothing about p.
  
      We can use a more informed alternative hypothesis too, if desirable.  E.g.,
      the original test using Beta(5, 4) as the alternative hypothesis:
  
      >>> bf = pg.bayesfactor_binom(k=115, n=200, p=0.5, a=5, b=4)
      >>> print("Bayes Factor: %.3f" % bf)
      Bayes Factor: 1.930
  
      Using a different base probability of successes:
  
      >>> bf = pg.bayesfactor_binom(k=100, n=1000, p=0.1)
      >>> print("Bayes Factor: %.3f" % bf)
      Bayes Factor: 0.024
      """
      from scipy.stats import beta, binom
  
      assert 0 < p < 1, "p must be between 0 and 1."
      assert isinstance(k, int), "k must be int."
      assert isinstance(n, int), "n must be int."
      assert k <= n, "k (successes) cannot be higher than n (trials)."
      assert a > 0, "a must be positive."
      assert b > 0, "b must be positive."
  
      def fun(g):
          return beta.pdf(g, a, b) * binom.pmf(k, n, g)
  
      bf10 = quad(fun, 0, 1)[0] / binom.pmf(k, n, p)
      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 4 for calling a global function with example usage: bayesfactor_binom(k, n, p, a, b) and returns: bf10, unknown