class_docstr: Test power.py.
docstr: Test function power_ttest.
  Values are compared to the pwr R package.
code: def test_power_ttest(self):
      """Test function power_ttest.
      Values are compared to the pwr R package.
      """
      # ONE-SAMPLE / PAIRED
      # Alternative = 'greater'
      assert np.isclose(
          power_ttest(
              d=0.5, n=20, contrast="one-sample", alternative="greater"
          ),
          0.6951493,
      )
      assert np.isclose(
          power_ttest(
              d=0.5, n=20, contrast="paired", alternative="greater"
          ),
          0.6951493,
      )
      assert np.isclose(
          power_ttest(
              d=0.5,
              power=0.80,
              contrast="one-sample",
              alternative="greater",
          ),
          26.13753,
      )
      assert np.isclose(
          power_ttest(
              n=20,
              power=0.80,
              contrast="one-sample",
              alternative="greater",
          ),
          0.5769185,
      )
      assert np.isclose(
          power_ttest(
              d=0.5,
              n=20,
              power=0.80,
              alpha=None,
              alternative="greater",
              contrast="one-sample",
          ),
          0.09004593,
          rtol=1e-03,
      )
      # Alternative = 'less'
      assert np.isclose(
          power_ttest(
              d=0.5, n=20, contrast="one-sample", alternative="less"
          ),
          7.083752e-05,
      )
      assert np.isclose(
          power_ttest(
              d=-0.5, n=20, contrast="one-sample", alternative="less"
          ),
          0.6951493,
      )
      assert np.isclose(
          power_ttest(
              d=0.5, n=20, contrast="paired", alternative="less"
          ),
          7.083752e-05,
      )
      assert np.isclose(
          power_ttest(
              d=-0.5,
              power=0.80,
              contrast="one-sample",
              alternative="less",
          ),
          26.13753,
      )
      assert np.isclose(
          power_ttest(
              n=20,
              power=0.80,
              contrast="one-sample",
              alternative="less",
          ),
          -0.5769185,
      )
      assert np.isclose(
          power_ttest(
              d=-0.5,
              n=20,
              power=0.80,
              alpha=None,
              alternative="less",
              contrast="one-sample",
          ),
          0.09004593,
          rtol=1e-03,
      )
      # Two-sided
      assert np.isclose(
          power_ttest(d=0.5, n=20, contrast="one-sample"),
          0.5645044,
          rtol=1e-03,
      )
      assert np.isclose(
          power_ttest(d=0.5, power=0.80, contrast="one-sample"),
          33.36713,
      )
      assert np.isclose(
          power_ttest(n=20, power=0.80, contrast="one-sample"),
          0.6604413,
      )
      assert np.isclose(
          power_ttest(
              d=0.5, n=20, power=0.80, alpha=None, contrast="one-sample"
          ),
          0.1798043,
          rtol=1e-02,
      )
  
      # TWO-SAMPLES
      # Alternative = 'greater'
      assert np.isclose(
          power_ttest(d=0.5, n=20, alternative="greater"), 0.4633743
      )
      assert np.isclose(
          power_ttest(d=0.5, power=0.80, alternative="greater"), 50.1508
      )
      assert np.isclose(
          power_ttest(n=20, power=0.80, alternative="greater"),
          0.8006879,
      )
      assert np.isclose(
          power_ttest(
              d=0.5, n=20, power=0.80, alpha=None, alternative="greater"
          ),
          0.2315111,
          rtol=1e-01,
      )
      # Alternative = 'less'
      assert np.isclose(
          power_ttest(d=-0.5, n=20, alternative="less"), 0.4633743
      )
      assert np.isclose(
          power_ttest(d=-0.5, power=0.80, alternative="less"), 50.1508
      )
      assert np.isclose(
          power_ttest(n=20, power=0.80, alternative="less"), -0.8006879
      )
      assert np.isclose(
          power_ttest(
              d=-0.5, n=20, power=0.80, alpha=None, alternative="less"
          ),
          0.2315111,
          rtol=1e-01,
      )
      # Two-sided
      assert np.isclose(power_ttest(d=0.5, n=20), 0.337939, rtol=1e-03)
      assert np.isclose(power_ttest(d=0.5, power=0.80), 63.76561)
      assert np.isclose(
          power_ttest(n=20, power=0.80), 0.9091587, rtol=1e-03
      )
      assert np.isclose(
          power_ttest(d=0.5, n=20, power=0.80, alpha=None),
          0.4430163,
          rtol=1e-01,
      )
      # Error
      with pytest.raises(ValueError):
          power_ttest(d=0.5)
  
file_path: pingouin/pingouin/tests/test_power.py
imports: import pytest
  import numpy
  from unittest import TestCase
  from pingouin.power import power_ttest, power_ttest2n, power_anova, power_rm_anova, power_corr, power_chi2
label_desc: Use image node_id 1 for calling the TestPower obj's underlying member method code with example usage: obj.test_power_ttest() without return types