easystats / effectsize

:dragon: Compute and work with indices of effect size and standardized parameters
https://easystats.github.io/effectsize/
Other
337 stars 23 forks source link

Allow Cohen's D interpreter to keep direction of negative effects #650

Closed abanihas closed 3 months ago

abanihas commented 3 months ago

Describe the bug Cohen's D interpreter changes direction of negative effect for estimate and its 95% CI. When 95% CI bounds are on either side of zero the values become confusing with current behaviour, masking non-significant effects.

To Reproduce Steps to reproduce the behavior:

# Shows direction of effect correctly for estimate and its 95% CI
effectsize::cohens_d(mtcars$wt, mu = 3.4) 
#> Cohen's d |        95% CI
#> -------------------------
#> -0.19     | [-0.53, 0.16]
#> 
#> - Deviation from a difference of 3.4.
# Changes all directions to positive
effectsize::cohens_d(mtcars$wt, mu = 3.4) |> effectsize::interpret_cohens_d()
#> Cohen's d |       95% CI | Interpretation
#> -----------------------------------------
#> 0.19      | [0.53, 0.16] |     very small
#> 
#> - Deviation from a difference of 3.4.
#> - Interpretation rule: cohen1988

Created on 2024-06-25 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.1 (2024-06-14) #> os macOS Sonoma 14.5 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Toronto #> date 2024-06-25 #> pandoc 3.1.11 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> bayestestR 0.13.2 2024-02-12 [1] CRAN (R 4.4.0) #> cli 3.6.2 2023-12-11 [1] CRAN (R 4.4.0) #> datawizard 0.11.0 2024-06-05 [1] CRAN (R 4.4.0) #> digest 0.6.35 2024-03-11 [1] CRAN (R 4.4.0) #> effectsize 0.8.8 2024-05-12 [1] CRAN (R 4.4.0) #> emmeans 1.10.2 2024-05-20 [1] CRAN (R 4.4.0) #> estimability 1.5.1 2024-05-12 [1] CRAN (R 4.4.0) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.4.0) #> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.0) #> fs 1.6.4 2024-04-25 [1] CRAN (R 4.4.0) #> glue 1.7.0 2024-01-09 [1] CRAN (R 4.4.0) #> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0) #> insight 0.20.1 2024-06-11 [1] CRAN (R 4.4.0) #> knitr 1.47 2024-05-29 [1] CRAN (R 4.4.0) #> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0) #> mvtnorm 1.2-5 2024-05-21 [1] CRAN (R 4.4.0) #> parameters 0.21.7 2024-05-14 [1] CRAN (R 4.4.0) #> reprex 2.1.0 2024-01-11 [1] CRAN (R 4.4.0) #> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.4.0) #> rmarkdown 2.27 2024-05-17 [1] CRAN (R 4.4.0) #> rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.4.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.0) #> withr 3.0.0 2024-01-16 [1] CRAN (R 4.4.0) #> xfun 0.44 2024-05-15 [1] CRAN (R 4.4.0) #> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.4.0) #> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.4.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```

Expected behavior Keep direction of effect as is. Thanks for the great work!

Screenshots See Reprex.

Specifiations (please complete the following information):

mattansb commented 3 months ago

Oh, good catch.

Will be fixed in the next version (in a few days hopfully).

library(effectsize)

cohens_d(mtcars$wt, mu = 4) |> 
  interpret_cohens_d()
#> Cohen's d |         95% CI | Interpretation
#> -------------------------------------------
#> -0.80     | [-1.19, -0.40] |         medium
#> 
#> - Deviation from a difference of 4.
#> - Interpretation rule: cohen1988

cohens_d(-mtcars$wt, mu = -4) |> 
  interpret_cohens_d()
#> Cohen's d |       95% CI | Interpretation
#> -----------------------------------------
#> 0.80      | [0.40, 1.19] |         medium
#> 
#> - Deviation from a difference of -4.
#> - Interpretation rule: cohen1988

Created on 2024-06-26 with reprex v2.1.0