From 8d74554eb6f95592a33691eb93a2174193765ead Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Fri, 6 Sep 2024 23:05:29 +0300 Subject: [PATCH] p_direction --- DESCRIPTION | 1 + R/p_direction.R | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index b592a6a4f..8800af169 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -82,6 +82,7 @@ Suggests: bridgesampling, brms, curl, + distributional, effectsize, emmeans, gamm4, diff --git a/R/p_direction.R b/R/p_direction.R index c5b1f84e0..2e8584302 100644 --- a/R/p_direction.R +++ b/R/p_direction.R @@ -286,6 +286,46 @@ p_direction.draws <- function(x, #' @export p_direction.rvar <- p_direction.draws +#' @export +p_direction.distribution <- function(x, + null = 0, + as_p = FALSE, + remove_na = TRUE, + ...) { + obj_name <- insight::safe_deparse_symbol(substitute(x)) + x <- .clean_distributional(x) + pd <- numeric(length = length(x)) + + for (i in seq_along(pd)) { + low <- distributional::cdf(x[[i]], q = null) + if (.is_discrete_dist(x[[i]])) { + high <- 1 - (low + stats::density(x[[i]], at = null)) + } else { + high <- 1 - low + } + pd[i] <- max(low, high) + } + + out <- data.frame( + Parameter = names(x), + pd = pd, + row.names = NULL, + stringsAsFactors = FALSE + ) + + # rename column + if (as_p) { + out$pd <- pd_to_p(out$pd) + colnames(out)[2] <- "p" + } + + attr(out, "object_name") <- obj_name + attr(out, "as_p") <- as_p + class(out) <- unique(c("p_direction", "see_p_direction", class(out))) + + out +} + #' @rdname p_direction #' @export