diff --git a/.Rbuildignore b/.Rbuildignore index 82cd8b483..aed852bd5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -24,6 +24,7 @@ tests\^spelling \.lintr$ ^CRAN-SUBMISSION$ ^data-raw$ +^tests/testthat/_snaps/. ^man/figures/JASP. ^man/figures/b. diff --git a/DESCRIPTION b/DESCRIPTION index b44c233d2..a1ffd3b0b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: bayestestR Title: Understand and Describe Bayesian Models and Posterior Distributions -Version: 0.15.1.2 +Version: 0.15.2 Authors@R: c(person(given = "Dominique", family = "Makowski", diff --git a/NEWS.md b/NEWS.md index 5f440d4eb..12b273646 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,13 @@ * `describe_posterior()` no longer re-samples a model when computing indices. +* `describe_posterior()` calls tests only when needed. Before, there was a + minimal overhead by calling tests that were not requested. + +## Bug fixes + +* Fixed failing test for Mac OS. + # bayestestR 0.15.1 ## Changes diff --git a/R/describe_posterior.R b/R/describe_posterior.R index 7a5bbc80b..30f24d3ab 100644 --- a/R/describe_posterior.R +++ b/R/describe_posterior.R @@ -1449,4 +1449,4 @@ describe_posterior.BFBayesFactor <- function(posterior, ) return(is.character(test) && length(test) > 0L && any(need_rope %in% tolower(test))) -} \ No newline at end of file +} diff --git a/README.Rmd b/README.Rmd index aef473de4..7be2b756c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -24,7 +24,7 @@ knitr::opts_chunk$set( ) ``` -[![DOI](https://joss.theoj.org/papers/10.21105/joss.01541/status.svg)](https://doi.org/10.21105/joss.01541) [![status](https://tinyverse.netlify.com/badge/bayestestR)](https://CRAN.R-project.org/package=bayestestR) [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html) +[![DOI](https://joss.theoj.org/papers/10.21105/joss.01541/status.svg)](https://doi.org/10.21105/joss.01541) ***Become a Bayesian master you will*** @@ -95,14 +95,14 @@ In the Bayesian framework, parameters are estimated in a probabilistic fashion a - [**Centrality**](https://easystats.github.io/bayestestR/articles/web_only/indicesEstimationComparison.html) - `mean()`, `median()` or [`map_estimate()`](https://easystats.github.io/bayestestR/reference/map_estimate.html) for an estimation of the mode. - [`point_estimate()`](https://easystats.github.io/bayestestR/reference/point_estimate.html) can be used to get them at once and can be run directly on models. - + - [**Uncertainty**](https://easystats.github.io/bayestestR/articles/credible_interval.html) - [`hdi()`](https://easystats.github.io/bayestestR/reference/hdi.html) for *Highest Density Intervals (HDI)*, [`spi()`](https://easystats.github.io/bayestestR/reference/spi.html) for *Shortest Probability Intervals (SPI)* or [`eti()`](https://easystats.github.io/bayestestR/reference/eti.html) for *Equal-Tailed Intervals (ETI)*. - [`ci()`](https://easystats.github.io/bayestestR/reference/ci.html) can be used as a general method for Confidence and Credible Intervals (CI). - + - [**Effect Existence**](https://easystats.github.io/bayestestR/articles/indicesExistenceComparison.html): whether an effect is different from 0. - [`p_direction()`](https://easystats.github.io/bayestestR/reference/p_direction.html) for a Bayesian equivalent of the frequentist *p*-value (see [Makowski et al., 2019](https://doi.org/10.3389/fpsyg.2019.02767)) - - [`p_pointnull()`](https://easystats.github.io/bayestestR/reference/p_map.html) represents the odds of null hypothesis (*h0 = 0*) compared to the most likely hypothesis (the MAP). + - [`p_pointnull()`](https://easystats.github.io/bayestestR/reference/p_map.html) represents the odds of null hypothesis (*h0 = 0*) compared to the most likely hypothesis (the MAP). - [`bf_pointnull()`](https://easystats.github.io/bayestestR/reference/bayesfactor_parameters.html) for a classic *Bayes Factor (BF)* assessing the likelihood of effect presence against its absence (*h0 = 0*). - [**Effect Significance**](https://easystats.github.io/bayestestR/articles/indicesExistenceComparison.html): whether the effect size can be considered as non-negligible. @@ -199,7 +199,7 @@ While the **median** and the **mean** are available through base R functions, [` [`hdi()`](https://easystats.github.io/bayestestR/reference/hdi.html) computes the **Highest Density Interval (HDI)** of a posterior distribution, i.e., the interval which contains all points within the interval have a higher probability density than points outside the interval. The HDI can be used in the context of Bayesian posterior characterization as **Credible Interval (CI)**. -Unlike equal-tailed intervals (see [`eti()`](https://easystats.github.io/bayestestR/reference/eti.html)) that typically exclude 2.5\% from each tail of the distribution, the HDI is *not* equal-tailed and therefore always includes the mode(s) of posterior distributions. +Unlike equal-tailed intervals (see [`eti()`](https://easystats.github.io/bayestestR/reference/eti.html)) that typically exclude 2.5\% from each tail of the distribution, the HDI is *not* equal-tailed and therefore always includes the mode(s) of posterior distributions. ```{r message=FALSE, warning=FALSE} posterior <- distribution_chisquared(10000, 4) @@ -322,9 +322,9 @@ ggplot(dat4, aes(x = x, y = y, fill = fill)) + ### Bayes Factor -[`bayesfactor_parameters()`](https://easystats.github.io/bayestestR/reference/bayesfactor_parameters.html) computes Bayes factors against the null (either a point or an interval), bases on prior and posterior samples of a single parameter. This Bayes factor indicates the degree by which the mass of the posterior distribution has shifted further away from or closer to the null value(s) (relative to the prior distribution), thus indicating if the null value has become less or more likely given the observed data. +[`bayesfactor_parameters()`](https://easystats.github.io/bayestestR/reference/bayesfactor_parameters.html) computes Bayes factors against the null (either a point or an interval), bases on prior and posterior samples of a single parameter. This Bayes factor indicates the degree by which the mass of the posterior distribution has shifted further away from or closer to the null value(s) (relative to the prior distribution), thus indicating if the null value has become less or more likely given the observed data. -When the null is an interval, the Bayes factor is computed by comparing the prior and posterior odds of the parameter falling within or outside the null; When the null is a point, a Savage-Dickey density ratio is computed, which is also an approximation of a Bayes factor comparing the marginal likelihoods of the model against a model in which the tested parameter has been restricted to the point null [@wagenmakers2010bayesian]. +When the null is an interval, the Bayes factor is computed by comparing the prior and posterior odds of the parameter falling within or outside the null; When the null is a point, a Savage-Dickey density ratio is computed, which is also an approximation of a Bayes factor comparing the marginal likelihoods of the model against a model in which the tested parameter has been restricted to the point null [@wagenmakers2010bayesian]. ```{r message=FALSE, warning=FALSE} diff --git a/README.md b/README.md index d9abfc326..d50b93f19 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ # bayestestR [![DOI](https://joss.theoj.org/papers/10.21105/joss.01541/status.svg)](https://doi.org/10.21105/joss.01541) -[![status](https://tinyverse.netlify.com/badge/bayestestR)](https://CRAN.R-project.org/package=bayestestR) -[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html) ***Become a Bayesian master you will*** @@ -46,9 +44,9 @@ badge](https://easystats.r-universe.dev/badges/bayestestR)](https://easystats.r- The *bayestestR* package is available on CRAN, while its latest development version is available on R-universe (from *rOpenSci*). -| Type | Source | Command | -|-------------|------------|------------------------------------------------------------------------------| -| Release | CRAN | `install.packages("bayestestR")` | +| Type | Source | Command | +|----|----|----| +| Release | CRAN | `install.packages("bayestestR")` | | Development | R-universe | `install.packages("bayestestR", repos = "https://easystats.r-universe.dev")` | Once you have downloaded the package, you can then load it using: @@ -159,9 +157,9 @@ describe_posterior( ) ## Summary of Posterior Distribution ## -## Parameter | Median | 95% CI | pd | ps -## -------------------------------------------------- -## Posterior | -0.01 | [-1.98, 1.93] | 50.52% | 0.46 +## Parameter | Median | 95% CI | pd | ps +## ---------------------------------------------------- +## Posterior | 3.05e-03 | [-1.92, 1.95] | 50.09% | 0.46 ``` `describe_posterior()` works for many objects, including more complex @@ -464,7 +462,7 @@ Compute the density of a given point of a distribution. ``` r density_at(rnorm(1000, 1, 1), 1) -## [1] 0.41 +## [1] 0.36 ``` ## Code of Conduct @@ -477,7 +475,7 @@ By contributing to this project, you agree to abide by its terms. # References
+entry-spacing="0" line-spacing="2">
diff --git a/inst/WORDLIST b/inst/WORDLIST index 91e5ec922..5cff26074 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -162,6 +162,7 @@ lm maths mattansb mcmc +mfx modelling nbinom neq diff --git a/man/figures/unnamed-chunk-10-1.png b/man/figures/unnamed-chunk-10-1.png index 1fd78d4f3..dc80563e1 100644 Binary files a/man/figures/unnamed-chunk-10-1.png and b/man/figures/unnamed-chunk-10-1.png differ diff --git a/man/figures/unnamed-chunk-12-1.png b/man/figures/unnamed-chunk-12-1.png index 2d571465f..ca82e6f62 100644 Binary files a/man/figures/unnamed-chunk-12-1.png and b/man/figures/unnamed-chunk-12-1.png differ diff --git a/man/figures/unnamed-chunk-14-1.png b/man/figures/unnamed-chunk-14-1.png index 4365bb70d..e74b404e9 100644 Binary files a/man/figures/unnamed-chunk-14-1.png and b/man/figures/unnamed-chunk-14-1.png differ diff --git a/man/figures/unnamed-chunk-16-1.png b/man/figures/unnamed-chunk-16-1.png index a2904caa2..68e17e6f1 100644 Binary files a/man/figures/unnamed-chunk-16-1.png and b/man/figures/unnamed-chunk-16-1.png differ diff --git a/man/figures/unnamed-chunk-7-1.png b/man/figures/unnamed-chunk-7-1.png index d79e409fd..214108c1f 100644 Binary files a/man/figures/unnamed-chunk-7-1.png and b/man/figures/unnamed-chunk-7-1.png differ diff --git a/man/figures/unnamed-chunk-8-1.png b/man/figures/unnamed-chunk-8-1.png index c21b84b91..0172129b4 100644 Binary files a/man/figures/unnamed-chunk-8-1.png and b/man/figures/unnamed-chunk-8-1.png differ diff --git a/tests/testthat/test-rope.R b/tests/testthat/test-rope.R index a4124dc6e..a4b399e5f 100644 --- a/tests/testthat/test-rope.R +++ b/tests/testthat/test-rope.R @@ -94,8 +94,19 @@ test_that("rope", { }) +test_that("BayesFactor", { + skip_on_os(c("linux", "mac")) + skip_if_not_or_load_if_installed("BayesFactor") + + mods <- regressionBF(mpg ~ am + cyl, mtcars, progress = FALSE) + rx <- suppressMessages(rope(mods, verbose = FALSE)) + expect_equal(rx$ROPE_high, -rx$ROPE_low, tolerance = 0.01) + expect_equal(rx$ROPE_high[1], 0.6026948, tolerance = 0.01) +}) + + skip_if_not_or_load_if_installed("brms") -skip_on_os("windows") +skip_on_os(c("windows", "mac")) set.seed(123) model <- suppressWarnings(brms::brm(mpg ~ wt + gear, data = mtcars, iter = 500)) @@ -107,8 +118,6 @@ test_that("rope (brms)", { expect_equal(rope$ROPE_Percentage, c(0.00, 0.00, 0.50), tolerance = 0.1) }) -skip_on_os("mac") - model <- suppressWarnings(brm(bf(mvbind(mpg, disp) ~ wt + gear) + set_rescor(TRUE), data = mtcars, iter = 500, refresh = 0)) rope <- rope(model, verbose = FALSE) @@ -122,14 +131,3 @@ test_that("rope (brms, multivariate)", { tolerance = 0.1 ) }) - -skip_on_os("linux") - -test_that("BayesFactor", { - skip_if_not_or_load_if_installed("BayesFactor") - - mods <- regressionBF(mpg ~ am + cyl, mtcars, progress = FALSE) - rx <- suppressMessages(rope(mods, verbose = FALSE)) - expect_equal(rx$ROPE_high, -rx$ROPE_low, tolerance = 0.01) - expect_equal(rx$ROPE_high[1], 0.6026948, tolerance = 0.01) -}) diff --git a/vignettes/bayes_factors.Rmd b/vignettes/bayes_factors.Rmd index 90ebd471a..44ae8aca8 100644 --- a/vignettes/bayes_factors.Rmd +++ b/vignettes/bayes_factors.Rmd @@ -429,7 +429,7 @@ than the prior densities. In `bayestestR`, this can be achieved with the `si()` function: ```{r} -my_first_si <- si(model, BF = 1) +my_first_si <- si(model, BF = 1, verbose = FALSE) print(my_first_si) ```