Skip to content

Commit 910ee03

Browse files
committed
Improve effect sizes calculation
1 parent d0fe414 commit 910ee03

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

dabest/_effsize_objects.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,16 @@ def _perform_statistical_test(self):
363363
self.__pvalue_mcnemar = _mcnemar.pvalue
364364
self.__statistic_mcnemar = _mcnemar.statistic
365365

366+
elif self.__proportional:
367+
# The Cohen's h calculation is for binary categorical data
368+
try:
369+
self.__proportional_difference = es.cohens_h(
370+
self.__control, self.__test
371+
)
372+
except ValueError as e:
373+
warnings.warn(f"Calculation of Cohen's h failed. This method is applicable "
374+
f"only for binary data (0's and 1's). Details: {e}")
375+
366376
elif self.__effect_size == "cliffs_delta":
367377
# Let's go with Brunner-Munzel!
368378
brunner_munzel = spstats.brunnermunzel(
@@ -411,14 +421,6 @@ def _perform_statistical_test(self):
411421

412422
standardized_es = es.cohens_d(self.__control, self.__test, is_paired=None)
413423

414-
# The Cohen's h calculation is for binary categorical data
415-
try:
416-
self.__proportional_difference = es.cohens_h(
417-
self.__control, self.__test
418-
)
419-
except ValueError as e:
420-
warnings.warn(f"Calculation of Cohen's h failed. This method is applicable "
421-
f"only for binary data (0's and 1's). Details: {e}")
422424

423425
def to_dict(self):
424426
"""

nbs/API/effsize_objects.ipynb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,16 @@
425425
" self.__pvalue_mcnemar = _mcnemar.pvalue\n",
426426
" self.__statistic_mcnemar = _mcnemar.statistic\n",
427427
"\n",
428+
" elif self.__proportional:\n",
429+
" # The Cohen's h calculation is for binary categorical data\n",
430+
" try:\n",
431+
" self.__proportional_difference = es.cohens_h(\n",
432+
" self.__control, self.__test\n",
433+
" )\n",
434+
" except ValueError as e:\n",
435+
" warnings.warn(f\"Calculation of Cohen's h failed. This method is applicable \"\n",
436+
" f\"only for binary data (0's and 1's). Details: {e}\")\n",
437+
"\n",
428438
" elif self.__effect_size == \"cliffs_delta\":\n",
429439
" # Let's go with Brunner-Munzel!\n",
430440
" brunner_munzel = spstats.brunnermunzel(\n",
@@ -473,14 +483,6 @@
473483
"\n",
474484
" standardized_es = es.cohens_d(self.__control, self.__test, is_paired=None)\n",
475485
"\n",
476-
" # The Cohen's h calculation is for binary categorical data\n",
477-
" try:\n",
478-
" self.__proportional_difference = es.cohens_h(\n",
479-
" self.__control, self.__test\n",
480-
" )\n",
481-
" except ValueError as e:\n",
482-
" warnings.warn(f\"Calculation of Cohen's h failed. This method is applicable \"\n",
483-
" f\"only for binary data (0's and 1's). Details: {e}\")\n",
484486
"\n",
485487
" def to_dict(self):\n",
486488
" \"\"\"\n",

0 commit comments

Comments
 (0)