From dd40f1a190154c5d2b54b5f4b1ace46d52d9feda Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Tue, 12 Dec 2023 23:01:58 +0200 Subject: [PATCH] init #464 --- R/interpret_bf.R | 38 ++++++++++---------- R/interpret_cohens_d.R | 75 +++++++++++++++++++-------------------- R/print.rules.R | 49 +++++++++++++++++++++---- man/effectsize-package.Rd | 1 + man/interpret_bf.Rd | 16 ++++----- man/interpret_cohens_d.Rd | 22 ++++++------ 6 files changed, 119 insertions(+), 82 deletions(-) diff --git a/R/interpret_bf.R b/R/interpret_bf.R index 47e146af3..7f3735bc5 100644 --- a/R/interpret_bf.R +++ b/R/interpret_bf.R @@ -13,20 +13,11 @@ #' #' Rules apply to BF as ratios, so BF of 10 is as extreme as a BF of 0.1 (1/10). #' -#' - Jeffreys (1961) (`"jeffreys1961"`; default) -#' - **BF = 1** - No evidence -#' - **1 < BF <= 3** - Anecdotal -#' - **3 < BF <= 10** - Moderate -#' - **10 < BF <= 30** - Strong -#' - **30 < BF <= 100** - Very strong -#' - **BF > 100** - Extreme. -#' - Raftery (1995) (`"raftery1995"`) -#' - **BF = 1** - No evidence -#' - **1 < BF <= 3** - Weak -#' - **3 < BF <= 20** - Positive -#' - **20 < BF <= 150** - Strong -#' - **BF > 150** - Very strong +#' ```{r, echo = FALSE, results = "asis"} +#' insight::print_md(.i_bf_jeffreys1961, "BF", "Jeffreys(1961) (`{.rn}`; default):\n- **BF = 1** - No evidence") #' +#' insight::print_md(.i_bf_raftery1995, "BF", "Raftery (1995) (`{.rn}`):\n- **BF = 1** - No evidence") +#' ``` #' #' @examples #' interpret_bf(1) @@ -68,12 +59,8 @@ interpret_bf <- function(bf, rules <- .match.rules( rules, list( - jeffreys1961 = rules(c(3, 10, 30, 100), c("anecdotal", "moderate", "strong", "very strong", "extreme"), - name = "jeffreys1961" - ), - raftery1995 = rules(c(3, 20, 150), c("weak", "positive", "strong", "very strong"), - name = "raftery1995" - ) + jeffreys1961 = .i_bf_jeffreys1961, + raftery1995 = .i_bf_raftery1995 ) ) @@ -101,3 +88,16 @@ interpret_bf <- function(bf, interpretation } + + +# rules ------------------------------------------------------------------- + +#' @keywords internal +.i_bf_jeffreys1961 <- rules(c(3, 10, 30, 100), + c("anecdotal", "moderate", "strong", "very strong", "extreme"), + name = "jeffreys1961") + +#' @keywords internal +.i_bf_raftery1995 <- rules(c(3, 20, 150), + c("weak", "positive", "strong", "very strong"), + name = "raftery1995") \ No newline at end of file diff --git a/R/interpret_cohens_d.R b/R/interpret_cohens_d.R index def2aaaf6..4f0861c2d 100644 --- a/R/interpret_cohens_d.R +++ b/R/interpret_cohens_d.R @@ -14,29 +14,16 @@ #' Rules apply to equally to positive and negative *d* (i.e., they are given as #' absolute values). #' -#' - Cohen (1988) (`"cohen1988"`; default) -#' - **d < 0.2** - Very small -#' - **0.2 <= d < 0.5** - Small -#' - **0.5 <= d < 0.8** - Medium -#' - **d >= 0.8** - Large -#' - Sawilowsky (2009) (`"sawilowsky2009"`) -#' - **d < 0.1** - Tiny -#' - **0.1 <= d < 0.2** - Very small -#' - **0.2 <= d < 0.5** - Small -#' - **0.5 <= d < 0.8** - Medium -#' - **0.8 <= d < 1.2** - Large -#' - **1.2 <= d < 2** - Very large -#' - **d >= 2** - Huge -#' - Lovakov & Agadullina (2021) (`"lovakov2021"`) -#' - **d < 0.15** - Very small -#' - **0.15 <= d < 0.36** - Small -#' - **0.36 <= d < 0.65** - Medium -#' - **d >= 0.65** - Large -#' - Gignac & Szodorai (2016) (`"gignac2016"`, based on the [d_to_r()] conversion, see [interpret_r()]) -#' - **d < 0.2** - Very small -#' - **0.2 <= d < 0.41** - Small -#' - **0.41 <= d < 0.63** - Moderate -#' - **d >= 0.63** - Large +#' ```{r, echo = FALSE, results = "asis"} +#' insight::print_md(.i_d_cohen1988, "d", "Cohen (1988) (`{.rn}`; default):") +#' +#' insight::print_md(.i_d_sawilowsky2009, "d", "Sawilowsky (2009) (`{.rn}`):") +#' +#' insight::print_md(.i_d_lovakov2021, "d", "Lovakov & Agadullina (2021) (`{.rn}`):") +#' +#' tit <- "Gignac & Szodorai (2016) (`{.rn}`, based on the [d_to_r()] conversion, see [interpret_r()]):" +#' insight::print_md(i_d_gignac2016, "d", tit) +#' ``` #' #' @examples #' interpret_cohens_d(.02) @@ -59,25 +46,13 @@ #' @keywords interpreters #' @export interpret_cohens_d <- function(d, rules = "cohen1988", ...) { - if (is.character(rules) && rules == "gignac2016") { - return(interpret_r(d_to_r(d), rules)) - } - rules <- .match.rules( rules, list( - cohen1988 = rules(c(0.2, 0.5, 0.8), c("very small", "small", "medium", "large"), - name = "cohen1988", right = FALSE - ), - sawilowsky2009 = rules(c(0.1, 0.2, 0.5, 0.8, 1.2, 2), - c("tiny", "very small", "small", "medium", "large", "very large", "huge"), - name = "sawilowsky2009", right = FALSE - ), - lovakov2021 = rules(c(0.15, 0.36, 0.65), - c("very small", "small", "medium", "large"), - name = "lovakov2021", right = FALSE - ), - gignac2016 = NA # added for the correct error msg + cohen1988 = .i_d_cohen1988, + sawilowsky2009 =.i_d_sawilowsky2009, + lovakov2021 = .i_d_lovakov2021, + gignac2016 = i_d_gignac2016 ) ) @@ -95,3 +70,25 @@ interpret_hedges_g <- function(g, rules = "cohen1988") { interpret_glass_delta <- function(delta, rules = "cohen1988") { interpret_cohens_d(delta, rules) } + + +# rules ------------------------------------------------------------------- + +#' @keywords internal +.i_d_cohen1988 <- rules(c(0.2, 0.5, 0.8), c("very small", "small", "medium", "large"), + name = "cohen1988", right = FALSE) + +#' @keywords internal +.i_d_sawilowsky2009 <- rules(c(0.1, 0.2, 0.5, 0.8, 1.2, 2), + c("tiny", "very small", "small", "medium", "large", "very large", "huge"), + name = "sawilowsky2009", right = FALSE) + +#' @keywords internal +.i_d_lovakov2021 <- rules(c(0.15, 0.36, 0.65), + c("very small", "small", "medium", "large"), + name = "lovakov2021", right = FALSE) + +#' @keywords internal +i_d_gignac2016 <- rules(r_to_d(c(0.1, 0.2, 0.3)), + c("very small", "small", "moderate", "large"), + name = "gignac2016", right = FALSE) \ No newline at end of file diff --git a/R/print.rules.R b/R/print.rules.R index 89b2c8259..a42fa6da6 100644 --- a/R/print.rules.R +++ b/R/print.rules.R @@ -12,14 +12,51 @@ print.rules <- function(x, digits = "signif2", ...) { #' @export -print_md.rules <- function(x, digits = "signif2", ...) { - x_fmt <- format(x, digits = digits, output = "markdown", ...) +print_md.rules <- function(x, value = "x", title = "`{.rn}`:", ...) { - if (length(x$values) == length(x$labels)) { - insight::export_table(x_fmt, align = "rl", format = "markdown", ...) + rule_name <- attr(x, "rule_name") + title <- gsub("\\{\\.rn\\}", rule_name, title) + + values <- insight::format_value(x$values, digits = "signif2", protect_integers = TRUE) + labels <- insight::format_capitalize(x$labels) + + if (length(labels) > length(values)) { + right <- attr(x, "right") + + k <- length(labels) + + if (right) { + l <- "<" + r <- "<=" + } else { + l <- "<=" + r <- "<" + } + + first <- sprintf("\n- **%s %s %s** - %s", value, r, values[1], labels[1]) + last <- sprintf("\n- **%s %s %s** - %s", values[k-1], l, value, labels[k]) + + nth <- "" + if (k > 2L) { + nth <- sprintf("\n- **%s %s %s %s %s** - %s", + values[1:(k-2)], l, value, r, values[2:(k-1)], + labels[2:(k-1)]) + nth <- paste0(nth, collapse = "") + } + + fmt_rules <- paste0(c(first, nth, last), collapse = "") } else { - insight::export_table(x_fmt, align = "rcl", format = "markdown", ...) + fmt_rules <- sprintf("\n- **%s =~ %s** - %s", + value, values, labels) + fmt_rules <- paste0(fmt_rules, collapse = "") } + + cat("\n") + cat(title) + cat(fmt_rules) + cat("\n") + + invisible(x) } @@ -101,4 +138,4 @@ print.effectsize_interpret <- function(x, ...) { insight::print_color(paste0("(Rules: ", name, ")\n"), .pcl["interpret"]) invisible(orig_x) -} +} \ No newline at end of file diff --git a/man/effectsize-package.Rd b/man/effectsize-package.Rd index 30c9a4414..6cd2eb230 100644 --- a/man/effectsize-package.Rd +++ b/man/effectsize-package.Rd @@ -47,6 +47,7 @@ Authors: \item Indrajeet Patil \email{patilindrajeet.science@gmail.com} (\href{https://orcid.org/0000-0003-1995-6531}{ORCID}) (@patilindrajeets) \item Brenton M. Wiernik \email{brenton@wiernik.org} (\href{https://orcid.org/0000-0001-9560-6336}{ORCID}) (@bmwiernik) \item Rémi Thériault \email{remi.theriault@mail.mcgill.ca} (\href{https://orcid.org/0000-0003-4315-6788}{ORCID}) (@rempsyc) + \item Philip Waggoner \email{philip.waggoner@gmail.com} (\href{https://orcid.org/0000-0002-7825-7573}{ORCID}) [contributor] } Other contributors: diff --git a/man/interpret_bf.Rd b/man/interpret_bf.Rd index c547e40ce..ac1c3a168 100644 --- a/man/interpret_bf.Rd +++ b/man/interpret_bf.Rd @@ -39,24 +39,24 @@ Argument names can be partially matched. Rules apply to BF as ratios, so BF of 10 is as extreme as a BF of 0.1 (1/10). -\itemize{ -\item Jeffreys (1961) (\code{"jeffreys1961"}; default) + +Jeffreys(1961) (\code{jeffreys1961}; default): \itemize{ \item \strong{BF = 1} - No evidence -\item \strong{1 < BF <= 3} - Anecdotal +\item \strong{BF <= 3} - Anecdotal \item \strong{3 < BF <= 10} - Moderate \item \strong{10 < BF <= 30} - Strong \item \strong{30 < BF <= 100} - Very strong -\item \strong{BF > 100} - Extreme. +\item \strong{100 < BF} - Extreme } -\item Raftery (1995) (\code{"raftery1995"}) + +Raftery (1995) (\code{raftery1995}): \itemize{ \item \strong{BF = 1} - No evidence -\item \strong{1 < BF <= 3} - Weak +\item \strong{BF <= 3} - Weak \item \strong{3 < BF <= 20} - Positive \item \strong{20 < BF <= 150} - Strong -\item \strong{BF > 150} - Very strong -} +\item \strong{150 < BF} - Very strong } } diff --git a/man/interpret_cohens_d.Rd b/man/interpret_cohens_d.Rd index 4e4c4677f..6d9cd6ad1 100644 --- a/man/interpret_cohens_d.Rd +++ b/man/interpret_cohens_d.Rd @@ -29,15 +29,16 @@ thumb. Rules apply to equally to positive and negative \emph{d} (i.e., they are given as absolute values). -\itemize{ -\item Cohen (1988) (\code{"cohen1988"}; default) + +Cohen (1988) (\code{cohen1988}; default): \itemize{ \item \strong{d < 0.2} - Very small \item \strong{0.2 <= d < 0.5} - Small \item \strong{0.5 <= d < 0.8} - Medium -\item \strong{d >= 0.8} - Large +\item \strong{0.8 <= d} - Large } -\item Sawilowsky (2009) (\code{"sawilowsky2009"}) + +Sawilowsky (2009) (\code{sawilowsky2009}): \itemize{ \item \strong{d < 0.1} - Tiny \item \strong{0.1 <= d < 0.2} - Very small @@ -45,22 +46,23 @@ absolute values). \item \strong{0.5 <= d < 0.8} - Medium \item \strong{0.8 <= d < 1.2} - Large \item \strong{1.2 <= d < 2} - Very large -\item \strong{d >= 2} - Huge +\item \strong{2 <= d} - Huge } -\item Lovakov & Agadullina (2021) (\code{"lovakov2021"}) + +Lovakov & Agadullina (2021) (\code{lovakov2021}): \itemize{ \item \strong{d < 0.15} - Very small \item \strong{0.15 <= d < 0.36} - Small \item \strong{0.36 <= d < 0.65} - Medium -\item \strong{d >= 0.65} - Large +\item \strong{0.65 <= d} - Large } -\item Gignac & Szodorai (2016) (\code{"gignac2016"}, based on the \code{\link[=d_to_r]{d_to_r()}} conversion, see \code{\link[=interpret_r]{interpret_r()}}) + +Gignac & Szodorai (2016) (\code{gignac2016}, based on the \code{\link[=d_to_r]{d_to_r()}} conversion, see \code{\link[=interpret_r]{interpret_r()}}): \itemize{ \item \strong{d < 0.2} - Very small \item \strong{0.2 <= d < 0.41} - Small \item \strong{0.41 <= d < 0.63} - Moderate -\item \strong{d >= 0.63} - Large -} +\item \strong{0.63 <= d} - Large } }