effectsize R Package

repository·main·Indexed 43 days ago

https://github.com/easystats/effectsize

An R package for computing, converting, and interpreting indices of effect size and standardized parameters. It provides utilities for standardized differences (Cohen's d, Hedges' g, Glass' delta), contingency table association (Phi, Cramér's V, Cohen's g), and ANOVA models (Eta-squared, Omega-squared, Epsilon-squared). The package also includes tools to standardize model coefficients, convert effect sizes from test statistics (F, t), and automatically interpret magnitudes using rulesets like cohen1988 and funder2019.

Tokens
2.8K
Snippets
16
Records
16
Agent score
54%

What's inside effectsize

  1. Install the effectsize package

    main

    You can install the stable release of effectsize from CRAN or the latest development version from R-universe.

    Stable release (CRAN):

    install.packages("effectsize")

    Development version (R-universe):

    install.packages("effectsize", repos = "https://easystats.r-universe.dev/")

    Tip: For full access to the easystats ecosystem, it is recommended to use library(easystats) instead of library(effectsize). To stay updated, use easystats::install_latest().

    install.packages("effectsize")
  2. Configure effectsize for nice symbols

    main

    To enable the printing of nice mathematical symbols when displaying results, set the es.use_symbols option to TRUE.

    Note: On Windows, this requires R version 4.2.0 or higher.

    library(effectsize)
    options(es.use_symbols = TRUE)
  3. Use the easystats ecosystem

    main

    While you can load effectsize directly using library(effectsize), it is recommended to use library(easystats) instead. This makes all features of the entire easystats ecosystem available in your session.

    To stay updated with the ecosystem, you can use easystats::install_latest().

    library(easystats)
  4. Interpret effect sizes using rules of thumb

    main

    The effectsize package provides convenience functions to apply existing or custom interpretation rules of thumb (such as Cohen's 1988 criteria) to effect size values. This allows you to convert numeric indices into qualitative descriptors like "small", "medium", or "large".

    Note: The package authors advocate for cautious use of these automated judgment-replacing tools. For more detailed guidance, refer to the Automated Interpretation of Indices of Effect Size vignette.

    interpret_d(c(0.02, 0.52, 0.86), rules = "cohen1988")
    #> [1] "very small" "medium"     "large"
    #> (Rules: cohen1988)
  5. Compute standardized differences (Cohen's d, Hedges' g, Glass' delta)

    main

    Use the following functions to compute standardized differences for group comparisons using formula notation:

    • cohens_d(formula, data)
    • hedges_g(formula, data)
    • glass_delta(formula, data)

    Example:

    cohens_d(mpg ~ am, data = mtcars)
    hedges_g(mpg ~ am, data = mtcars)
    glass_delta(mpg ~ am, data = mtcars)
    cohens_d(mpg ~ am, data = mtcars)
  6. Compute effect sizes for ANOVA models

    main

    For ANOVA models (objects created via aov()), you can compute several indices of effect size:

    • eta_squared(model): Calculates $\eta^2$.
    • omega_squared(model): Calculates $\omega^2$.
    • epsilon_squared(model): Calculates $\epsilon^2$.

    Example:

    model <- aov(mpg ~ factor(gear), data = mtcars)
    eta_squared(model)
    omega_squared(model)
    epsilon_squared(model)
    model <- aov(mpg ~ factor(gear), data = mtcars)
    eta_squared(model)
  7. Calculate effect sizes for ANOVAs (Eta-squared, Epsilon-squared, Omega-squared)

    main

    For ANOVA-like models, use eta_squared() to calculate the amount of variance explained by model terms. Supported indices include:

    • Eta-squared ($\eta^2$)
    • Partial Eta-squared ($\eta^2_p$): Use partial = TRUE.
    • Generalized Eta-squared ($\eta^2_G$): Use generalized = "factor_name".
    • $\epsilon^2_p$ (Epsilon-squared): via epsilon_squared().
    • $\omega^2_p$ (Omega-squared): via omega_squared().

    These functions automatically extract necessary information from the model object.

    model <- aov(weight ~ Diet * Time + Error(Chick / Time), data = ChickWeight)
    
    eta_squared(model, partial = TRUE)
    #> Group      | Parameter | Eta2 (partial) |       90% CI
    #> ------------------------------------------------------
    #> Chick      |      Diet |           0.27 | [0.06, 0.42]
    #> Chick:Time |      Time |           0.87 | [0.85, 0.88]
    #> Chick:Time | Diet:Time |           0.22 | [0.11, 0.23]
  8. Convert between different effect size types

    main

    To compare results across different study designs, you can convert between various effect size metrics:

    • r_to_d(r): Correlation $r$ to Cohen's $d$.
    • d_to_oddsratio(d): Cohen's $d$ to Odds Ratio.
    • oddsratio_to_riskratio(oddsratio, p0): Odds Ratio to Risk Ratio (requires baseline probability p0).
    • oddsratio_to_r(oddsratio): Odds Ratio to correlation $r$.
    r_to_d(0.7)
    #> [1] 1.960392
    
    d_to_oddsratio(1.96)
    #> [1] 34.98946
  9. Convert effect sizes from test statistics

    main

    If you only have test statistics (e.g., from a published paper) and not the original model, you can reverse-engineer effect size indices using these functions:

    • F_to_eta2(f, df, df_error): Converts $F$-statistics to Eta-squared.
    • t_to_d(t, df_error): Converts $t$-statistics to Cohen's $d$.
    • t_to_r(t, df_error): Converts $t$-statistics to correlation $r$.
    • effectsize(htest_object): A convenience function that automatically detects the test type (e.g., oneway.test, chisq.test) and returns the appropriate effect size.

    Note: These conversions are approximations based on the relationship between test statistics, effect size, and degrees of freedom.

    t_to_d(t = -5.14, df_error = 22)
    #>     d |         95% CI
    #> ----------------------
    #> -2.19 | [-3.23, -1.12]
    
    # Using the convenience function on a chisq.test object
    extab <- rbind(c(762, 327, 468), c(484, 239, 477), c(484, 239, 477))
    Xsq <- chisq.test(xtab)
    effectsize(Xsq)
    #> Cramer's V |       95% CI
    #> -------------------------
    #>       0.07 | [0.05, 0.09]
  10. Interpret effect size indices automatically

    main

    You can automatically interpret the magnitude of an effect size using interpretation functions. The default ruleset is funder2019.

    • interpret_r(r): Interprets correlation coefficient $r$.
    • interpret_cohens_d(d, rules = "..."): Interprets Cohen's $d$ using specific rule sets.

    Available rule sets include:

    • funder2019 (default)
    • cohen1988
    • gignac2016

    Example:

    interpret_r(r = 0.3)
    interpret_cohens_d(d = 0.45, rules = "cohen1988")
    interpret_r(r = 0.3)
  11. Estimate standardized differences (Cohen's d, Hedges' g, Glass' delta)

    main

    Use the following functions to estimate common indices of standardized differences for both paired and independent samples:

    • cohens_d(formula, data): Estimates Cohen's $d$.
    • hedges_g(formula, data): Estimates Hedges' $g$.
    • glass_delta(formula, data): Estimates Glass' $\Delta$ for independent samples with different variances.

    These functions return the effect size estimate along with its confidence interval (CI).

    cohens_d(mpg ~ am, data = mtcars)
    #> Cohen's d |         95% CI
    #> --------------------------
    #>     -1.48 | [-2.27, -0.67]
    #>
    #> - Estimated using pooled SD.
  12. Convert between different effect size indices

    main

    effectsize provides utilities to convert between various standardized parameters and indices.

    Between indices:

    • d_to_r(d): Converts Cohen's $d$ to correlation $r$.
    • oddsratio_to_riskratio(OR, p0): Converts odds ratio to risk ratio.

    From test statistics:

    • F_to_d(F, df, df_error): Converts $F$-statistic to Cohen's $d$.
    • F_to_r(F, df, df_error): Converts $F$-statistic to correlation $r$.
    • F_to_eta2(F, df, df_error): Converts $F$-statistic to partial $\eta^2$.

    Example:

    d_to_r(d = 0.2)
    F_to_d(15, df = 1, df_error = 60)
    d_to_r(d = 0.2)