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

supporting one-sample designs for Cohen's and Hedge's g #46

Closed IndrajeetPatil closed 4 years ago

IndrajeetPatil commented 4 years ago

Sorry, I missed this, but are we also supporting these measures for one-sample designs?

For example-

tobj <- t.test(
  x = ggplot2::msleep$sleep_rem,
  mu = 2
)

# Hedge's g
statsExpressions:::effsize_t_parametric(
  formula = ~ sleep_rem,
  data = ggplot2::msleep,
  mu = 2,
  hedges.correction = TRUE,
  noncentral = TRUE,
  tobject = tobj
)

#> # A tibble: 1 x 9
#>   method estimate conf.low conf.high conf.level alternative paired noncentral
#>   <chr>     <dbl>    <dbl>     <dbl>      <dbl> <chr>       <chr>  <lgl>     
#> 1 Hedge~  -0.0947   -0.350     0.157       0.95 two.sided   <NA>   TRUE      
#> # ... with 1 more variable: var.equal <lgl>

# Cohen's d
statsExpressions:::effsize_t_parametric(
  formula = ~ sleep_rem,
  data = ggplot2::msleep,
  mu = 2,
  hedges.correction = FALSE,
  noncentral = TRUE,
  tobject = tobj
)

#> # A tibble: 1 x 9
#>   method estimate conf.low conf.high conf.level alternative paired noncentral
#>   <chr>     <dbl>    <dbl>     <dbl>      <dbl> <chr>       <chr>  <lgl>     
#> 1 Cohen~  -0.0960   -0.350     0.157       0.95 two.sided   <NA>   TRUE      
#> # ... with 1 more variable: var.equal <lgl>

This is what I get with effectsize:

library(effectsize)

cohens_d( ~ wt, data = mtcars)
#> Warning in mean.default(y, na.rm = TRUE): argument is not numeric or logical:
#> returning NA
#> Cohens_d |       95% CI
#> -----------------------
#>          | [4.92, 8.64]

hedges_g( ~ wt, data = mtcars)
#> Warning in mean.default(y, na.rm = TRUE): argument is not numeric or logical:
#> returning NA
#> Hedges_g |       95% CI
#> -----------------------
#>          | [4.80, 8.42]

Created on 2020-03-27 by the reprex package (v0.3.0.9001)

Session info ``` r sessioninfo::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R Under development (unstable) (2020-02-28 r77874) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz Europe/Berlin #> date 2020-03-27 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0) #> backports 1.1.5 2019-10-02 [1] CRAN (R 4.0.0) #> bayestestR 0.5.3 2020-03-26 [1] Github (easystats/bayestestR@a071680) #> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0) #> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0) #> effectsize * 0.3.0 2020-03-26 [1] Github (easystats/effectsize@d72c762) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0) #> fs 1.3.2 2020-03-05 [1] CRAN (R 4.0.0) #> glue 1.3.2 2020-03-12 [1] CRAN (R 4.0.0) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 4.0.0) #> insight 0.8.2.1 2020-03-26 [1] Github (easystats/insight@269bbf1) #> knitr 1.28 2020-02-06 [1] CRAN (R 4.0.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0) #> parameters 0.6.0.1 2020-03-26 [1] Github (easystats/parameters@b3b784b) #> pillar 1.4.3 2019-12-20 [1] CRAN (R 4.0.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0) #> purrr 0.3.3 2019-10-18 [1] CRAN (R 4.0.0) #> Rcpp 1.0.4 2020-03-17 [1] CRAN (R 4.0.0) #> reprex 0.3.0.9001 2020-03-25 [1] Github (tidyverse/reprex@a019cc4) #> rlang 0.4.5 2020-03-01 [1] CRAN (R 4.0.0) #> rmarkdown 2.1 2020-01-20 [1] CRAN (R 4.0.0) #> rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.0) #> styler 1.3.2 2020-02-23 [1] CRAN (R 4.0.0) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 4.0.0) #> withr 2.1.2 2018-03-15 [1] CRAN (R 4.0.0) #> xfun 0.12 2020-01-13 [1] CRAN (R 4.0.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0) #> #> [1] C:/Users/inp099/Documents/R/win-library/4.0 #> [2] C:/Program Files/R/R-devel/library ```
mattansb commented 4 years ago

On dev:

effectsize::cohens_d( ~ sleep_rem, data = ggplot2::msleep)
#> Error: Formula must have the 'outcome ~ group'.

Created on 2020-03-27 by the reprex package (v0.3.0)

So one sample is supported, but not via formula:

effectsize::cohens_d("sleep_rem", data = ggplot2::msleep)
#> Cohens_d |       95% CI
#> -----------------------
#>     1.44 | [1.14, 1.76]

Created on 2020-03-27 by the reprex package (v0.3.0)

I guess if you wanted some other "mu", you could:

effectsize::hedges_g(ggplot2::msleep$sleep_rem - 2)
#> Hedges_g |        95% CI
#> ------------------------
#>    -0.10 | [-0.31, 0.12]

Created on 2020-03-27 by the reprex package (v0.3.0)