R/format_pd.R

Defines functions format_pd

Documented in format_pd

#' Probability of direction (pd) formatting
#'
#' @param pd Probability of direction (pd).
#' @inheritParams format_p
#'
#' @return A formatted string.
#' @examples
#' format_pd(0.12)
#' format_pd(c(0.12, 1, 0.9999, 0.98, 0.995, 0.96), name = NULL)
#' format_pd(c(0.12, 1, 0.9999, 0.98, 0.995, 0.96), stars = TRUE)
#' @export
format_pd <- function(pd, stars = FALSE, stars_only = FALSE, name = "pd") {
  p_text <- ifelse(pd >= 1, "= 100%***",
    ifelse(pd > 0.999, paste0("= ", format_value(pd * 100), "%***"), # nolint
      ifelse(pd > 0.99, paste0("= ", format_value(pd * 100), "%**"), # nolint
        ifelse(pd > 0.97, paste0("= ", format_value(pd * 100), "%*"), # nolint
          paste0("= ", format_value(pd * 100), "%")
        )
      )
    )
  )

  .add_prefix_and_remove_stars(p_text, stars, stars_only, name)
}
easystats/insight documentation built on Oct. 2, 2024, 8:19 a.m.