Skip to contents

This function tries to return the best effect-size measure for the provided input model. See details.

Usage

# S3 method for BFBayesFactor
effectsize(model, type = NULL, verbose = TRUE, test = NULL, ...)

effectsize(model, ...)

# S3 method for aov
effectsize(model, type = NULL, ...)

# S3 method for htest
effectsize(model, type = NULL, verbose = TRUE, ...)

Arguments

model

An object of class htest, or a statistical model. See details.

type

The effect size of interest. See details.

verbose

Toggle warnings and messages on or off.

test

The indices of effect existence to compute. Character (vector) or list with one or more of these options: "p_direction" (or "pd"), "rope", "p_map", "equivalence_test" (or "equitest"), "bayesfactor" (or "bf") or "all" to compute all tests. For each "test", the corresponding bayestestR function is called (e.g. rope() or p_direction()) and its results included in the summary output.

...

Arguments passed to or from other methods. See details.

Value

A data frame with the effect size (depending on input) and and its CIs (CI_low and CI_high).

Details

  • For an object of class htest, data is extracted via insight::get_data(), and passed to the relevant function according to:

    • A t-test depending on type: "cohens_d" (default), "hedges_g", or "cles".

    • A Chi-squared tests of independence, depending on type: "cramers_v" (default), "phi", "cohens_w", "pearsons_c", "cohens_h", "oddsratio", or "riskratio".

    • A Chi-squared tests of goodness-of-fit, depending on type: "normalized_chi" (default) "cohens_w", "pearsons_c"

    • A One-way ANOVA test, depending on type: "eta" (default), "omega" or "epsilon" -squared, "f", or "f2".

    • A McNemar test returns Cohen's g.

    • A Wilcoxon test depending on type: returns "rank_biserial" correlation (default) or "cles".

    • A Kruskal-Wallis test returns rank Epsilon squared.

    • A Friedman test returns Kendall's W. (Where applicable, ci and alternative are taken from the htest if not otherwise provided.)

  • For an object of class BFBayesFactor, using bayestestR::describe_posterior(),

    • A t-test depending on type: "cohens_d"(default) or"cles"`.

    • A correlation test returns r.

    • A contingency table test, depending on type: "cramers_v" (default), "phi", "cohens_w", "pearsons_c", "cohens_h", "oddsratio", or "riskratio".

    • A proportion test returns p.

  • Objects of class anova, aov, or aovlist, depending on type: "eta" (default), "omega" or "epsilon" -squared, "f", or "f2".

  • Other objects are passed to parameters::standardize_parameters().

For statistical models it is recommended to directly use the listed functions, for the full range of options they provide.

See also

Other effect size indices: cles(), cohens_d(), eta_squared(), phi(), rank_biserial()

Examples


## Hypothesis Testing
## ------------------
contingency_table <- as.table(rbind(c(762, 327, 468), c(484, 239, 477), c(484, 239, 477)))
Xsq <- chisq.test(contingency_table)
effectsize(Xsq)
#> Cramer's V |       95% CI
#> -------------------------
#> 0.07       | [0.05, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at [1.00].
effectsize(Xsq, type = "cohens_w")
#> Cohen's w |       95% CI
#> ------------------------
#> 0.10      | [0.07, 1.41]
#> 
#> - One-sided CIs: upper bound fixed at [1.41~].

Tt <- t.test(1:10, y = c(7:20), alternative = "less")
effectsize(Tt)
#> Cohen's d |        95% CI
#> -------------------------
#> -2.19     | [-Inf, -1.32]
#> 
#> - Estimated using un-pooled SD.
#> - One-sided CIs: lower bound fixed at [-Inf].

Aov <- oneway.test(extra ~ group, data = sleep, var.equal = TRUE)
effectsize(Aov)
#> Eta2 |       95% CI
#> -------------------
#> 0.16 | [0.00, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at [1.00].
effectsize(Aov, type = "omega")
#> Omega2 |       95% CI
#> ---------------------
#> 0.11   | [0.00, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at [1.00].

Wt <- wilcox.test(1:10, 7:20, mu = -3, alternative = "less")
#> Warning: cannot compute exact p-value with ties
effectsize(Wt)
#> r (rank biserial) |         95% CI
#> ----------------------------------
#> -0.65             | [-1.00, -0.36]
#> 
#> - Deviation from a difference of -3.
#> - One-sided CIs: lower bound fixed at [-1.00].
effectsize(Wt, type = "cles")
#> Parameter       | Coefficient |       95% CI
#> --------------------------------------------
#> Pr(superiority) |        0.18 | [0.00, 0.32]
#> Cohen's U3      |        0.00 | [0.00, 0.13]
#> Overlap         |        0.85 | [0.00, 1.11]
#> 
#> - Non-parametric CLES

## Bayesian Hypothesis Testing
## ---------------------------
# \donttest{
if (require(BayesFactor)) {
  bf_prop <- proportionBF(3, 7, p = 0.3)
  effectsize(bf_prop)

  bf_corr <- correlationBF(attitude$rating, attitude$complaints)
  effectsize(bf_corr)

  data(raceDolls)
  bf_xtab <- contingencyTableBF(raceDolls, sampleType = "poisson", fixedMargin = "cols")
  effectsize(bf_xtab)
  effectsize(bf_xtab, type = "oddsratio")

  bf_ttest <- ttestBF(sleep$extra[sleep$group==1],
                      sleep$extra[sleep$group==2],
                      paired = TRUE, mu = -1)
  effectsize(bf_ttest)
}
#> Loading required package: BayesFactor
#> Loading required package: coda
#> ************
#> Welcome to BayesFactor 0.9.12-4.3. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
#> 
#> Type BFManual() to open the manual.
#> ************
#> Cohen's d |        95% CI
#> -------------------------
#> -0.32     | [-0.99, 0.32]
#> 
#> - Deviation from a difference of -1.
# }

## Models and Anova Tables
## -----------------------
fit <- lm(mpg ~ factor(cyl) * wt + hp, data = mtcars)
effectsize(fit)
#> # Standardization method: refit
#> 
#> Parameter                        | Std. Coef. |         95% CI
#> --------------------------------------------------------------
#> (Intercept)                      |   1.14e-03 | [-0.53,  0.53]
#> factor(cyl)-0.104987808575239    |      -0.20 | [-0.79,  0.38]
#> factor(cyl)1.01488214956065      |      -0.32 | [-1.06,  0.42]
#> wt                               |      -0.90 | [-1.33, -0.46]
#> hp                               |      -0.25 | [-0.52,  0.01]
#> factor(cyl)-0.104987808575239:wt |       0.37 | [-0.63,  1.36]
#> factor(cyl)1.01488214956065:wt   |       0.54 | [ 0.03,  1.06]

anova_table <- anova(fit)
effectsize(anova_table)
#> # Effect Size for ANOVA (Type I)
#> 
#> Parameter      | Eta2 (partial) |       95% CI
#> ----------------------------------------------
#> factor(cyl)    |           0.86 | [0.76, 1.00]
#> wt             |           0.47 | [0.22, 1.00]
#> hp             |           0.14 | [0.00, 1.00]
#> factor(cyl):wt |           0.16 | [0.00, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at [1.00].
effectsize(anova_table, type = "epsilon")
#> # Effect Size for ANOVA (Type I)
#> 
#> Parameter      | Epsilon2 (partial) |       95% CI
#> --------------------------------------------------
#> factor(cyl)    |               0.85 | [0.74, 1.00]
#> wt             |               0.44 | [0.20, 1.00]
#> hp             |               0.11 | [0.00, 1.00]
#> factor(cyl):wt |               0.09 | [0.00, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at [1.00].