class_docstr: Test nonparametric.py.
docstr: Test function wilcoxon
docstr_tok: ["Test","function","wilcoxon"]
code: def test_wilcoxon(self):
      """Test function wilcoxon"""
      # R: wilcox.test(df$x, df$y, paired = TRUE, exact = FALSE)
      # The V value is slightly different between SciPy and R
      # The p-value, however, is almost identical
      wc_scp = scipy.stats.wilcoxon(x2, y2, correction=True)
      wc_pg = wilcoxon(x2, y2, alternative="two-sided")
      assert wc_scp[0] == wc_pg.at["Wilcoxon", "W-val"] == 20.5  # JASP
      assert wc_scp[1] == wc_pg.at["Wilcoxon", "p-val"]
      # Same but using the pre-computed difference
      # The W and p-values should be similar
      wc_pg2 = wilcoxon(np.array(x2) - np.array(y2))
      assert (
          wc_pg.at["Wilcoxon", "W-val"]
          == wc_pg2.at["Wilcoxon", "W-val"]
      )
      assert (
          wc_pg.at["Wilcoxon", "p-val"]
          == wc_pg2.at["Wilcoxon", "p-val"]
      )
      assert wc_pg.at["Wilcoxon", "RBC"] == wc_pg2.at["Wilcoxon", "RBC"]
      assert np.isnan(wc_pg2.at["Wilcoxon", "CLES"])
      wc_pg_less = wilcoxon(x2, y2, alternative="less")
      wc_pg_greater = wilcoxon(x2, y2, alternative="greater")
      # Note that the RBC value are compared to JASP in test_pairwise.py
      # The RBC values in JASP does not change according to the tail.
      assert round(wc_pg.at["Wilcoxon", "RBC"], 3) == -0.379
      assert round(wc_pg_less.at["Wilcoxon", "RBC"], 3) == -0.379
      assert round(wc_pg_greater.at["Wilcoxon", "RBC"], 3) == -0.379
      # CLES is compared to:
      # https://janhove.github.io/reporting/2016/11/16/common-language-effect-sizes
      assert round(wc_pg.at["Wilcoxon", "CLES"], 3) == 0.396
      assert round(wc_pg_less.at["Wilcoxon", "CLES"], 3) == 0.604
      assert round(wc_pg_greater.at["Wilcoxon", "CLES"], 3) == 0.396
      with pytest.raises(ValueError):
          wilcoxon(x2, y2, tail="error")
  
file_path: pingouin/pingouin/tests/test_nonparametric.py
imports: import pytest
  import scipy
  import numpy
  import pandas
  from unittest import TestCase
  from pingouin.nonparametric import mad, madmedianrule, mwu, wilcoxon, kruskal, friedman, cochran, harrelldavis
label_desc: Use image node_id 4 for calling the TestNonParametric obj's underlying member method code with example usage: obj.test_wilcoxon() without return types