class_docstr: Test bayesian.py.
class_docstr_tok: ["Test","bayesian.py","."]
docstr: Test function bayesfactor_pearson.
docstr_tok: ["Test","function","bayesfactor_pearson","."]
code: def test_bayesfactor_pearson(self):
      """Test function bayesfactor_pearson."""
      # Compare the analytical solution to JASP / R (method='ly')
      # Similar to JASP with kappa=1, or correlationBF with rscale='wide'
      # check for approximate equality with 1e-3 tolerance
      # (as this is how we store the values here)
      assert bfp(0.1, 83) == appr(0.204)
      assert bfp(-0.1, 83) == appr(0.204)
      assert bfp(0.1, 83, alternative="greater") == appr(0.332)
      assert bfp(0.1, 83, alternative="less") == appr(0.076)
  
      # Example 2. Compare with JASP.
      r, _ = pearsonr(x, y)
      n = 100
      assert bfp(r, n) == appr(0.174)
      assert bfp(r, n, alternative="greater") == appr(0.275)
      assert bfp(r, n, alternative="greater", method="wetzels") == appr(
          0.275
      )
      assert bfp(r, n, alternative="less") == appr(0.073)
      r, _ = pearsonr(v, w)
      # relative tolerance here
      assert bfp(r, n) == appr(2.321e22, rel=True)
      assert bfp(r, n, alternative="greater") == appr(
          4.643e22, rel=True
      )
      # assert bfp(r, n, alternative='less')) == 1.677e-26
  
      # Compare the integral solving method (Wetzels)
      # In R:
      # >>> library(BayesFactor)
      # >>> exp(linearReg.R2stat(N=20, p=1, R2=0.36, rscale = 1)[['bf']])
      assert bfp(0.6, 20, method="wetzels") == appr(8.221)
      assert bfp(-0.6, 20, method="wetzels") == appr(8.221)
      assert bfp(0.6, 10, method="wetzels") == appr(1.278)
  
      # Wrong input
      assert np.isnan(bfp(np.nan, 20))
      assert np.isnan(bfp(0.8, 1))
      assert np.isnan(bfp(np.inf, 1))
      assert np.isinf(bfp(-1, 100))
  
file_path: pingouin/pingouin/tests/test_bayesian.py
imports: import numpy
  from unittest import TestCase
  from scipy.stats import pearsonr
  from pingouin.parametric import ttest
  from pingouin.bayesian import bayesfactor_ttest, bayesfactor_binom
  from pingouin.bayesian import bayesfactor_pearson
  from pytest import approx
label_desc: Use image node_id 2 for calling the TestBayesian obj's underlying member method code with example usage: obj.test_bayesfactor_pearson() without return types