diff --git a/DESCRIPTION b/DESCRIPTION index 81fce186..c57d0c32 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -111,6 +111,6 @@ Config/Needs/website: rstudio/bslib, r-lib/pkgdown, easystats/easystatstemplate -Config/roxygen2/version: 8.0.0 +Config/roxygen2/version: 8.1.1 Remotes: easystats/datawizard diff --git a/NAMESPACE b/NAMESPACE index 4521cd8f..60348128 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,6 +61,7 @@ S3method(riskratio_to_nnt,default) S3method(riskratio_to_nnt,numeric) S3method(riskratio_to_oddsratio,default) S3method(riskratio_to_oddsratio,numeric) +S3method(transform,rules) export(.es_aov_simple) export(.es_aov_strata) export(.es_aov_table) @@ -127,6 +128,8 @@ export(interpret_agfi) export(interpret_bf) export(interpret_cfi) export(interpret_cohens_d) +export(interpret_cohens_f) +export(interpret_cohens_f2) export(interpret_cohens_g) export(interpret_cramers_v) export(interpret_direction) @@ -240,11 +243,17 @@ export(wmw_odds) export(z_to_d) export(z_to_r) importFrom(bayestestR,equivalence_test) -importFrom(datawizard,standardise) -importFrom(datawizard,standardize) -importFrom(insight,display) -importFrom(insight,print_html) -importFrom(insight,print_md) -importFrom(parameters,standardize_info) -importFrom(parameters,standardize_parameters) -importFrom(parameters,standardize_posteriors) +importFrom(datawizard, + standardise, + standardize +) +importFrom(insight, + display, + print_html, + print_md +) +importFrom(parameters, + standardize_info, + standardize_parameters, + standardize_posteriors +) diff --git a/NEWS.md b/NEWS.md index 67185a45..b4dcd596 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # effectsize (dev) +## New features + +- New `transform()` method for rules, allowing to applied transformed rules. + ## Bug fixes - `rank_biserial(x, y, paired = TRUE)` gives the same CIs as `rank_biserial(x - y)` (#716) diff --git a/R/eta_squared_posterior.R b/R/eta_squared_posterior.R index a8bfbb39..0fe57b35 100644 --- a/R/eta_squared_posterior.R +++ b/R/eta_squared_posterior.R @@ -1,6 +1,6 @@ #' @param ss_function For Bayesian models, the function used to extract -#' sum-of-squares. Uses [`anova()`] by default, but can also be `car::Anova()` -#' for simple linear models. +#' sum-of-squares. Uses [`stats::anova()`] by default, but can also be +#' `car::Anova()` for simple linear models. #' @param draws For Bayesian models, an integer indicating the number of draws #' from the posterior predictive distribution to return. Larger numbers take #' longer to run, but provide estimates that are more stable. diff --git a/R/interpret.R b/R/interpret.R index 517a0081..7fe116ad 100644 --- a/R/interpret.R +++ b/R/interpret.R @@ -19,9 +19,16 @@ #' @seealso [interpret()] #' #' @examples -#' rules(c(0.05), c("significant", "not significant"), right = FALSE) #' rules(c(0.2, 0.5, 0.8), c("small", "medium", "large")) #' rules(c("small" = 0.2, "medium" = 0.5), name = "Cohen's Rules") +#' +#' (sig_rules <- rules(c(0.05), c("significant", "not significant"), right = FALSE)) +#' +#' # Convert the rules for p-values to the rules for S-values +#' p_to_S <- function(p) -log2(p) +#' transform(sig_rules, p_to_S) +#' +#' #' @export rules <- function(values, labels = NULL, name = NULL, right = TRUE) { if (is.null(labels)) { @@ -77,6 +84,28 @@ rules <- function(values, labels = NULL, name = NULL, right = TRUE) { #' @export is.rules <- function(x) inherits(x, "rules") +#' @rdname rules +#' @param `_data` A set of `rules`. +#' @param ... Arguments passed to the `transform` function in `transform()`. Otherwise ignored. +#' @param new_name Name to give to the new rule. Defaults to `transform(old_name)` +#' @param transform Transformation to apply to the rules' values. +#' @export +transform.rules <- function( + `_data`, + transform = "identity", + new_name = NULL, + ... +) { + if (is.null(new_name)) { + f_name <- make.names(as.character(substitute(transform))) + new_name <- sprintf("%s(%s)", f_name, attr(`_data`, "rule_name")) + } + + transform <- match.fun(transform) + `_data`$values <- transform(`_data`$values, ...) + attr(`_data`, "rule_name") <- new_name + `_data` +} # Interpret --------------------------------------------------------------- diff --git a/R/interpret_omega_squared.R b/R/interpret_omega_squared.R index 0082af54..11ef2c55 100644 --- a/R/interpret_omega_squared.R +++ b/R/interpret_omega_squared.R @@ -1,7 +1,9 @@ #' Interpret ANOVA Effect Sizes #' -#' @param es Value or vector of (partial) eta / omega / epsilon squared or semipartial r squared values. -#' @param rules Can be `"field2013"` (default), `"cohen1992"` or custom set of [rules()]. +#' @param es Value or vector of (partial) eta / omega / epsilon squared or +#' semipartial r squared values, or Cohen's f or f squared. +#' @param rules Can be `"field2013"` (default for eta squared), `"cohen1992"` +#' (default for f squared) or custom set of [rules()]. #' @param ... Not used for now. #' #' @section Rules: @@ -11,16 +13,39 @@ #' - **0.01 <= ES < 0.06** - Small #' - **0.06 <= ES < 0.14** - Medium #' - **ES >= 0.14 ** - Large -#' - Cohen (1992) (`"cohen1992"`) applicable to one-way anova, or to *partial* -#' eta / omega / epsilon squared in multi-way anova. +#' - Cohen (1992) table 1 row 8 (`"cohen1992r8"` or `"cohen1992"`; multiple and multiple partial correlation) #' - **ES < 0.02** - Very small #' - **0.02 <= ES < 0.13** - Small #' - **0.13 <= ES < 0.26** - Medium #' - **ES >= 0.26** - Large +#' - Cohen (1992) row 7 (`"cohen1992r7"`; one-way ANOVA) +#' - **ES < 0.01** - Very small +#' - **0.01 <= ES < 0.06** - Small +#' - **0.06 <= ES < 0.14** - Medium +#' - **ES >= 0.14** - Large +#' +#' The same rules can be applied to Cohen's \eqn{f^2} (and \eqn{f}) by transforming those values: +#' +#' ```{r} +#' # Field (2013) +#' eta2_to_f2(c(small = 0.01, medium = 0.06, large = 0.14)) +#' ``` +#' +#' Cohen's rules are derived by applying the reverse transformation on Cohen's +#' cut-offs for \eqn{f^2} (row 8) and \eqn{f} (row 7): +#' +#' ```{r} +#' # Row 8 +#' f2_to_eta2(c(small = 0.02, medium = 0.15, large = 0.35)) +#' +#' # Row 7 +#' f_to_eta2(c(small = 0.1, medium = 0.25, large = 0.4)) +#' ``` #' #' @examples #' interpret_eta_squared(.02) -#' interpret_eta_squared(c(.5, .02), rules = "cohen1992") +#' interpret_eta_squared(c(.5, .02), rules = "cohen1992r8") +#' #' @seealso https://imaging.mrc-cbu.cam.ac.uk/statswiki/FAQ/effectSize/ #' #' @@ -28,28 +53,13 @@ #' - Field, A (2013) Discovering statistics using IBM SPSS Statistics. Fourth #' Edition. Sage:London. #' -#' - Cohen, J. (1992). A power primer. Psychological bulletin, 112(1), 155. +#' - Cohen, J. (1992). [A power primer](https://doi.org/10.1037/0033-2909.112.1.155). +#' Psychological Bulletin, 112(1), 155-159. #' #' @keywords interpreters #' @export interpret_omega_squared <- function(es, rules = "field2013", ...) { - rules <- .match.rules( - rules, - list( - field2013 = rules( - c(0.01, 0.06, 0.14), - c("very small", "small", "medium", "large"), - name = "field2013", - right = FALSE - ), - cohen1992 = rules( - c(0.02, 0.13, 0.26), - c("very small", "small", "medium", "large"), - name = "cohen1992", - right = FALSE - ) - ) - ) + rules <- .match.rules(rules, .anova_rules) interpret(es, rules) } @@ -65,3 +75,51 @@ interpret_epsilon_squared <- interpret_omega_squared #' @export #' @rdname interpret_omega_squared interpret_r2_semipartial <- interpret_omega_squared + +#' @export +#' @rdname interpret_omega_squared +interpret_cohens_f2 <- function(es, rules = "field2013", ...) { + rules <- .match.rules( + rules, + lapply(.anova_rules, transform, transform = eta2_to_f2) + ) + + interpret(es, rules) +} + +#' @export +#' @rdname interpret_omega_squared +interpret_cohens_f <- function(es, rules = "field2013", ...) { + rules <- .match.rules( + rules, + lapply(.anova_rules, transform, transform = eta2_to_f) + ) + + interpret(es, rules) +} + +# Rules ------------------------------------------------------------------ + +#' @keywords internal +.anova_rules <- list( + field2013 = rules( + c(0.01, 0.06, 0.14), + c("very small", "small", "medium", "large"), + name = "field2013", + right = FALSE + ), + + cohen1992 = rules( + f2_to_eta2(c(0.02, 0.15, 0.35)), + c("very small", "small", "medium", "large"), + name = "cohen1992", + right = FALSE + ), + cohen1992r7 = rules( + f_to_eta2(c(0.1, 0.25, 0.40)), + c("very small", "small", "medium", "large"), + name = "cohen1992", + right = FALSE + ) +) +.anova_rules$cohen1992r8 <- .anova_rules$cohen1992 diff --git a/man/eta_squared.Rd b/man/eta_squared.Rd index cd9310c6..10ca6cb2 100644 --- a/man/eta_squared.Rd +++ b/man/eta_squared.Rd @@ -111,8 +111,8 @@ allowed (e.g., \code{"g"}, \code{"l"}, \code{"two"}...). See \emph{One-Sided CIs returns the effect size for R-squared-change between the two models.} \item{ss_function}{For Bayesian models, the function used to extract -sum-of-squares. Uses \code{\link[=anova]{anova()}} by default, but can also be \code{car::Anova()} -for simple linear models.} +sum-of-squares. Uses \code{\link[stats:anova]{stats::anova()}} by default, but can also be +\code{car::Anova()} for simple linear models.} \item{draws}{For Bayesian models, an integer indicating the number of draws from the posterior predictive distribution to return. Larger numbers take diff --git a/man/interpret_omega_squared.Rd b/man/interpret_omega_squared.Rd index a6e366e0..eea7f778 100644 --- a/man/interpret_omega_squared.Rd +++ b/man/interpret_omega_squared.Rd @@ -5,6 +5,8 @@ \alias{interpret_eta_squared} \alias{interpret_epsilon_squared} \alias{interpret_r2_semipartial} +\alias{interpret_cohens_f2} +\alias{interpret_cohens_f} \title{Interpret ANOVA Effect Sizes} \usage{ interpret_omega_squared(es, rules = "field2013", ...) @@ -14,11 +16,17 @@ interpret_eta_squared(es, rules = "field2013", ...) interpret_epsilon_squared(es, rules = "field2013", ...) interpret_r2_semipartial(es, rules = "field2013", ...) + +interpret_cohens_f2(es, rules = "field2013", ...) + +interpret_cohens_f(es, rules = "field2013", ...) } \arguments{ -\item{es}{Value or vector of (partial) eta / omega / epsilon squared or semipartial r squared values.} +\item{es}{Value or vector of (partial) eta / omega / epsilon squared or +semipartial r squared values, or Cohen's f or f squared.} -\item{rules}{Can be \code{"field2013"} (default), \code{"cohen1992"} or custom set of \code{\link[=rules]{rules()}}.} +\item{rules}{Can be \code{"field2013"} (default for eta squared), \code{"cohen1992"} +(default for f squared) or custom set of \code{\link[=rules]{rules()}}.} \item{...}{Not used for now.} } @@ -35,26 +43,56 @@ Interpret ANOVA Effect Sizes \item \strong{0.06 <= ES < 0.14} - Medium \item **ES >= 0.14 ** - Large } -\item Cohen (1992) (\code{"cohen1992"}) applicable to one-way anova, or to \emph{partial} -eta / omega / epsilon squared in multi-way anova. +\item Cohen (1992) table 1 row 8 (\code{"cohen1992r8"} or \code{"cohen1992"}; multiple and multiple partial correlation) \itemize{ \item \strong{ES < 0.02} - Very small \item \strong{0.02 <= ES < 0.13} - Small \item \strong{0.13 <= ES < 0.26} - Medium \item \strong{ES >= 0.26} - Large } +\item Cohen (1992) row 7 (\code{"cohen1992r7"}; one-way ANOVA) +\itemize{ +\item \strong{ES < 0.01} - Very small +\item \strong{0.01 <= ES < 0.06} - Small +\item \strong{0.06 <= ES < 0.14} - Medium +\item \strong{ES >= 0.14} - Large } } +The same rules can be applied to Cohen's \eqn{f^2} (and \eqn{f}) by transforming those values: + +\if{html}{\out{