Skip to content

Commit

Permalink
p_direction
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Sep 6, 2024
1 parent 51450a2 commit 8d74554
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Suggests:
bridgesampling,
brms,
curl,
distributional,
effectsize,
emmeans,
gamm4,
Expand Down
40 changes: 40 additions & 0 deletions R/p_direction.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d74554

Please sign in to comment.