Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Apr 19, 2022
1 parent aca2585 commit beb6588
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 53 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: bayestestR
Title: Understand and Describe Bayesian Models and Posterior Distributions
Version: 0.12.0.2
Version: 0.12.0.3
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# bayestestR 0.12.0
# bayestestR 0.12.5

## Breaking

Expand All @@ -8,6 +8,8 @@

* All `distribution_*(random = FALSE)` functions now rely on `ppoints()`, which will result in slightly different results, especially with small `n`s.

* Uncertainty estimation now defaults to `"eti"` (formerly was `"hdi"`).

## Canges

* *bayestestR* functions now support `draws` objects from package *posterior*.
Expand Down
2 changes: 1 addition & 1 deletion R/ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ci <- function(x, ...) {
} else if (tolower(method) %in% c("si")) {
return(si(x, BF = BF, effects = effects, component = component, parameters = parameters, verbose = verbose, ...))
} else {
stop("`method` should be 'ETI' (for equal-tailed interval),'HDI' (for highest density interval), `BCI` (for bias corrected and accelerated bootstrap intervals) or 'SI' (for support interval).")
stop(insight::format_message("`method` should be 'ETI' (for equal-tailed interval),'HDI' (for highest density interval), 'BCI' (for bias corrected and accelerated bootstrap intervals), 'SPI' (for shortest probability interval) or 'SI' (for support interval)."), call. = FALSE)
}
}

Expand Down
38 changes: 19 additions & 19 deletions R/describe_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#'
#' @param posteriors A vector, data frame or model of posterior draws.
#' @param ci_method The type of index used for Credible Interval. Can be
#' `"HDI"` (default, see [bayestestR::hdi()]), `"ETI"`
#' (see [bayestestR::eti()]), `"BCI"` (see
#' `"ETI"` (default, see [bayestestR::eti()]), `"HDI"`
#' (see [bayestestR::hdi()]), `"BCI"` (see
#' [bayestestR::bci()]), `"SPI"` (see [bayestestR::spi()]), or
#' `"SI"` (see [bayestestR::si()]).
#' @param test The indices of effect existence to compute. Character (vector) or
Expand Down Expand Up @@ -96,7 +96,7 @@ describe_posterior <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand All @@ -111,7 +111,7 @@ describe_posterior <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -146,7 +146,7 @@ describe_posterior <- function(posteriors,
# Uncertainty

if (!is.null(ci)) {
ci_method <- match.arg(tolower(ci_method), c("hdi", "quantile", "ci", "eti", "si", "bci", "bcai"))
ci_method <- match.arg(tolower(ci_method), c("hdi", "spi", "quantile", "ci", "eti", "si", "bci", "bcai"))
if (ci_method == "si") {
uncertainty <- ci(x, BF = BF, method = ci_method, prior = bf_prior, ...)
} else {
Expand Down Expand Up @@ -433,7 +433,7 @@ describe_posterior.numeric <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -482,7 +482,7 @@ describe_posterior.bayesQR <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -532,7 +532,7 @@ describe_posterior.draws <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -570,7 +570,7 @@ describe_posterior.effectsize_std_params <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -634,7 +634,7 @@ describe_posterior.get_predicted <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = NULL,
...) {
if ("iterations" %in% names(attributes(posteriors))) {
Expand Down Expand Up @@ -663,7 +663,7 @@ describe_posterior.emmGrid <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -724,7 +724,7 @@ describe_posterior.stanreg <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -794,7 +794,7 @@ describe_posterior.stanmvreg <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = "p_direction",
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -859,7 +859,7 @@ describe_posterior.stanfit <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -912,7 +912,7 @@ describe_posterior.brmsfit <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -991,7 +991,7 @@ describe_posterior.MCMCglmm <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -1028,7 +1028,7 @@ describe_posterior.bcplm <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -1067,7 +1067,7 @@ describe_posterior.bamlss <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
Expand Down Expand Up @@ -1109,7 +1109,7 @@ describe_posterior.BFBayesFactor <- function(posteriors,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "hdi",
ci_method = "eti",
test = c("p_direction", "rope", "bf"),
rope_range = "default",
rope_ci = 0.95,
Expand Down
26 changes: 13 additions & 13 deletions R/rope.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ rope.default <- function(x, ...) {

#' @rdname rope
#' @export
rope.numeric <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.numeric <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
if (all(range == "default")) {
range <- c(-0.1, 0.1)
} else if (!all(is.numeric(range)) || length(range) != 2) {
Expand Down Expand Up @@ -173,7 +173,7 @@ rope.numeric <- function(x, range = "default", ci = 0.95, ci_method = "HDI", ver

#' @rdname rope
#' @export
rope.data.frame <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.data.frame <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
out <- .prepare_rope_df(x, range, ci, ci_method, verbose)
HDI_area_attributes <- insight::compact_list(out$HDI_area)
dat <- data.frame(
Expand All @@ -193,15 +193,15 @@ rope.data.frame <- function(x, range = "default", ci = 0.95, ci_method = "HDI",


#' @export
rope.draws <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.draws <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
rope(.posterior_draws_to_df(x), range = range, ci = ci, ci_method = ci_method, verbose = verbose, ...)
}



#' @rdname rope
#' @export
rope.emmGrid <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.emmGrid <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
xdf <- insight::get_parameters(x)

dat <- rope(xdf, range = range, ci = ci, ci_method = ci_method, verbose = verbose, ...)
Expand All @@ -216,7 +216,7 @@ rope.emm_list <- rope.emmGrid

#' @rdname rope
#' @export
rope.BFBayesFactor <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.BFBayesFactor <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
if (all(range == "default")) {
range <- rope_range(x, verbose = verbose)
}
Expand All @@ -232,7 +232,7 @@ rope.bamlss <- rope.BFBayesFactor

#' @rdname rope
#' @export
rope.MCMCglmm <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.MCMCglmm <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
nF <- x$Fixed$nfl
out <- rope(as.data.frame(x$Sol[, 1:nF, drop = FALSE]), range = range, ci = ci, ci_method = ci_method, verbose = verbose, ...)
attr(out, "object_name") <- insight::safe_deparse(substitute(x))
Expand All @@ -241,7 +241,7 @@ rope.MCMCglmm <- function(x, range = "default", ci = 0.95, ci_method = "HDI", ve


#' @export
rope.mcmc <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.mcmc <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
out <- rope(as.data.frame(x), range = range, ci = ci, ci_method = ci_method, verbose = verbose, ...)
attr(out, "object_name") <- NULL
attr(out, "data") <- insight::safe_deparse(substitute(x))
Expand All @@ -252,7 +252,7 @@ rope.mcmc <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbos


#' @export
rope.bcplm <- function(x, range = "default", ci = 0.95, ci_method = "HDI", verbose = TRUE, ...) {
rope.bcplm <- function(x, range = "default", ci = 0.95, ci_method = "ETI", verbose = TRUE, ...) {
out <- rope(insight::get_parameters(x), range = range, ci = ci, ci_method = ci_method, verbose = verbose, ...)
attr(out, "object_name") <- NULL
attr(out, "data") <- insight::safe_deparse(substitute(x))
Expand All @@ -274,7 +274,7 @@ rope.mcmc.list <- rope.bcplm


#' @keywords internal
.rope <- function(x, range = c(-0.1, 0.1), ci = 0.95, ci_method = "HDI", verbose = TRUE) {
.rope <- function(x, range = c(-0.1, 0.1), ci = 0.95, ci_method = "ETI", verbose = TRUE) {
ci_bounds <- ci(x, ci = ci, method = ci_method, verbose = verbose)

if (anyNA(ci_bounds)) {
Expand Down Expand Up @@ -303,7 +303,7 @@ rope.mcmc.list <- rope.bcplm

#' @rdname rope
#' @export
rope.stanreg <- function(x, range = "default", ci = 0.95, ci_method = "HDI", effects = c("fixed", "random", "all"), component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"), parameters = NULL, verbose = TRUE, ...) {
rope.stanreg <- function(x, range = "default", ci = 0.95, ci_method = "ETI", effects = c("fixed", "random", "all"), component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"), parameters = NULL, verbose = TRUE, ...) {
effects <- match.arg(effects)
component <- match.arg(component)

Expand Down Expand Up @@ -346,7 +346,7 @@ rope.blavaan <- rope.stanreg
rope.brmsfit <- function(x,
range = "default",
ci = 0.95,
ci_method = "HDI",
ci_method = "ETI",
effects = c("fixed", "random", "all"),
component = c("conditional", "zi", "zero_inflated", "all"),
parameters = NULL,
Expand Down Expand Up @@ -427,7 +427,7 @@ rope.brmsfit <- function(x,


#' @export
rope.sim.merMod <- function(x, range = "default", ci = 0.95, ci_method = "HDI", effects = c("fixed", "random", "all"), parameters = NULL, verbose = TRUE, ...) {
rope.sim.merMod <- function(x, range = "default", ci = 0.95, ci_method = "ETI", effects = c("fixed", "random", "all"), parameters = NULL, verbose = TRUE, ...) {
effects <- match.arg(effects)

if (all(range == "default")) {
Expand Down Expand Up @@ -490,7 +490,7 @@ rope.sim.merMod <- function(x, range = "default", ci = 0.95, ci_method = "HDI",


#' @export
rope.sim <- function(x, range = "default", ci = 0.95, ci_method = "HDI", parameters = NULL, verbose = TRUE, ...) {
rope.sim <- function(x, range = "default", ci = 0.95, ci_method = "ETI", parameters = NULL, verbose = TRUE, ...) {
if (all(range == "default")) {
range <- rope_range(x, verbose = verbose)
} else if (!all(is.numeric(range)) || length(range) != 2) {
Expand Down
4 changes: 2 additions & 2 deletions R/sexit.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ sexit <- function(x, significant = "default", large = "default", ci = 0.95, ...)
centrality$Effects <- centrality$Component <- NULL
centrality_text <- paste0("Median = ", insight::format_value(centrality$Median))
direction <- ifelse(centrality$Median < 0, "negative", "positive")
uncertainty <- ci(x, ci = ci, method = "HDI", ...)[c("CI", "CI_low", "CI_high")]
uncertainty <- ci(x, ci = ci, method = "ETI", ...)[c("CI", "CI_low", "CI_high")]
uncertainty_text <- insight::format_ci(uncertainty$CI_low, uncertainty$CI_high, uncertainty$CI)

# Indices
Expand Down Expand Up @@ -216,7 +216,7 @@ sexit <- function(x, significant = "default", large = "default", ci = 0.95, ...)

# Prepare output
attr(out, "sexit_info") <- "Following the Sequential Effect eXistence and sIgnificance Testing (SEXIT) framework, we report the median of the posterior distribution and its 95% CI (Highest Density Interval), along the probability of direction (pd), the probability of significance and the probability of being large."
attr(out, "sexit_ci_method") <- "HDI"
attr(out, "sexit_ci_method") <- "ETI"
attr(out, "sexit_significance") <- significant
attr(out, "sexit_large") <- large
attr(out, "sexit_textlong") <- text_full
Expand Down
Loading

0 comments on commit beb6588

Please sign in to comment.