From b17d28f5a0f3289f45512db51d455a96b74ba064 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 27 Feb 2023 20:33:23 +0100 Subject: [PATCH] Revise the way we calculate % in ROPE (SGPV) for frequentist models? #849 --- R/equivalence_test.R | 19 +++++++++++++++++-- man/model_parameters.aov.Rd | 4 ++-- man/model_parameters.htest.Rd | 4 ++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/R/equivalence_test.R b/R/equivalence_test.R index 01d35a2b8..b97d2ef97 100644 --- a/R/equivalence_test.R +++ b/R/equivalence_test.R @@ -435,6 +435,7 @@ equivalence_test.ggeffects <- function(x, ci_narrow, range_rope = range, rule = rule, + ci = ci, verbose = verbose ) }, conf_int, conf_int2 @@ -522,6 +523,7 @@ equivalence_test.ggeffects <- function(x, ci_narrow, range_rope = range, rule = rule, + ci = ci, verbose = verbose ) }, conf_int, conf_int2 @@ -539,7 +541,7 @@ equivalence_test.ggeffects <- function(x, #' @keywords internal -.equivalence_test_numeric <- function(ci_wide, ci_narrow, range_rope, rule, verbose) { +.equivalence_test_numeric <- function(ci_wide, ci_narrow, range_rope, rule, ci = 0.95, verbose) { final_ci <- NULL # ==== HDI+ROPE decision rule, by Kruschke ==== @@ -598,6 +600,7 @@ equivalence_test.ggeffects <- function(x, data.frame( CI_low = final_ci[1], CI_high = final_ci[2], + SGPV = .sgpv(range_rope, final_ci, ci), ROPE_low = range_rope[1], ROPE_high = range_rope[2], ROPE_Percentage = .rope_coverage(range_rope, final_ci), @@ -612,7 +615,7 @@ equivalence_test.ggeffects <- function(x, # helper --------------------- -.rope_coverage <- function(rope, ci) { +.sgpv <- function(rope, ci) { diff_rope <- abs(diff(rope)) diff_ci <- abs(diff(ci)) @@ -643,6 +646,18 @@ equivalence_test.ggeffects <- function(x, } +.rope_coverage <- function(rope, ci_range, ci) { + diff_ci <- abs(diff(ci_range)) + out <- bayestestR::distribution_normal( + n = 1000, + mean = ci_range[2] - (diff_ci / 2), + sd = diff_ci / 3.28 + ) + + rc <- bayestestR::rope(x, range = rope, ci = ci) + rc$ROPE_Percentage +} + .add_p_to_equitest <- function(model, ci, range) { tryCatch( diff --git a/man/model_parameters.aov.Rd b/man/model_parameters.aov.Rd index f3a40fba6..cf20623a2 100644 --- a/man/model_parameters.aov.Rd +++ b/man/model_parameters.aov.Rd @@ -224,7 +224,7 @@ Parameters from ANOVAs \item For an object of class \code{htest}, data is extracted via \code{\link[insight:get_data]{insight::get_data()}}, and passed to the relevant function according to: \itemize{ \item A \strong{t-test} depending on \code{type}: \code{"cohens_d"} (default), \code{"hedges_g"}, or one of \code{"p_superiority"}, \code{"u1"}, \code{"u2"}, \code{"u3"}, \code{"overlap"}. -\item A \strong{Chi-squared tests of independence} or \strong{Fisher's Exact Test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"tschuprows_t"}, \code{"phi"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, or \code{"riskratio"}. +\item A \strong{Chi-squared tests of independence} or \strong{Fisher's Exact Test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"tschuprows_t"}, \code{"phi"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, \code{"riskratio"}, \code{"arr"}, or \code{"nnt"}. \item A \strong{Chi-squared tests of goodness-of-fit}, depending on \code{type}: \code{"fei"} (default) \code{"cohens_w"}, \code{"pearsons_c"} \item A \strong{One-way ANOVA test}, depending on \code{type}: \code{"eta"} (default), \code{"omega"} or \code{"epsilon"} -squared, \code{"f"}, or \code{"f2"}. \item A \strong{McNemar test} returns \emph{Cohen's g}. @@ -237,7 +237,7 @@ Parameters from ANOVAs \itemize{ \item A \strong{t-test} depending on \code{type}: \code{"cohens_d"} (default) or one of \code{"p_superiority"}, \code{"u1"}, \code{"u2"}, \code{"u3"}, \code{"overlap"}. \item A \strong{correlation test} returns \emph{r}. -\item A \strong{contingency table test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"phi"}, \code{"tschuprows_t"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, or \code{"riskratio"}. +\item A \strong{contingency table test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"phi"}, \code{"tschuprows_t"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, or \code{"riskratio"}, \code{"arr"}, or \code{"nnt"}. \item A \strong{proportion test} returns \emph{p}. } \item Objects of class \code{anova}, \code{aov}, \code{aovlist} or \code{afex_aov}, depending on \code{type}: \code{"eta"} (default), \code{"omega"} or \code{"epsilon"} -squared, \code{"f"}, or \code{"f2"}. diff --git a/man/model_parameters.htest.Rd b/man/model_parameters.htest.Rd index a8bccddfb..011d0dd57 100644 --- a/man/model_parameters.htest.Rd +++ b/man/model_parameters.htest.Rd @@ -78,7 +78,7 @@ Parameters of h-tests (correlations, t-tests, chi-squared, ...). \item For an object of class \code{htest}, data is extracted via \code{\link[insight:get_data]{insight::get_data()}}, and passed to the relevant function according to: \itemize{ \item A \strong{t-test} depending on \code{type}: \code{"cohens_d"} (default), \code{"hedges_g"}, or one of \code{"p_superiority"}, \code{"u1"}, \code{"u2"}, \code{"u3"}, \code{"overlap"}. -\item A \strong{Chi-squared tests of independence} or \strong{Fisher's Exact Test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"tschuprows_t"}, \code{"phi"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, or \code{"riskratio"}. +\item A \strong{Chi-squared tests of independence} or \strong{Fisher's Exact Test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"tschuprows_t"}, \code{"phi"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, \code{"riskratio"}, \code{"arr"}, or \code{"nnt"}. \item A \strong{Chi-squared tests of goodness-of-fit}, depending on \code{type}: \code{"fei"} (default) \code{"cohens_w"}, \code{"pearsons_c"} \item A \strong{One-way ANOVA test}, depending on \code{type}: \code{"eta"} (default), \code{"omega"} or \code{"epsilon"} -squared, \code{"f"}, or \code{"f2"}. \item A \strong{McNemar test} returns \emph{Cohen's g}. @@ -91,7 +91,7 @@ Parameters of h-tests (correlations, t-tests, chi-squared, ...). \itemize{ \item A \strong{t-test} depending on \code{type}: \code{"cohens_d"} (default) or one of \code{"p_superiority"}, \code{"u1"}, \code{"u2"}, \code{"u3"}, \code{"overlap"}. \item A \strong{correlation test} returns \emph{r}. -\item A \strong{contingency table test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"phi"}, \code{"tschuprows_t"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, or \code{"riskratio"}. +\item A \strong{contingency table test}, depending on \code{type}: \code{"cramers_v"} (default), \code{"phi"}, \code{"tschuprows_t"}, \code{"cohens_w"}, \code{"pearsons_c"}, \code{"cohens_h"}, \code{"oddsratio"}, or \code{"riskratio"}, \code{"arr"}, or \code{"nnt"}. \item A \strong{proportion test} returns \emph{p}. } \item Objects of class \code{anova}, \code{aov}, \code{aovlist} or \code{afex_aov}, depending on \code{type}: \code{"eta"} (default), \code{"omega"} or \code{"epsilon"} -squared, \code{"f"}, or \code{"f2"}.