Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare CRAN release #697

Merged
merged 7 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tests\^spelling
\.lintr$
^CRAN-SUBMISSION$
^data-raw$
^tests/testthat/_snaps/.

^man/figures/JASP.
^man/figures/b.
Expand Down
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.15.1.2
Version: 0.15.2
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/describe_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#' - Makowski, D., Ben-Shachar, M. S., Chen, S. H. A., and Lüdecke, D. (2019).
#' *Indices of Effect Existence and Significance in the Bayesian Framework*.
#' Frontiers in Psychology 2019;10:2767. \doi{10.3389/fpsyg.2019.02767}
#' - [Region of Practical Equivalence (ROPE)](https://easystats.github.io/bayestestR/articles/region_of_practical_equivalence.html)

Check warning on line 49 in R/describe_posterior.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/describe_posterior.R,line=49,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.
#' - [Bayes factors](https://easystats.github.io/bayestestR/articles/bayes_factors.html)
#'
#' @examples
Expand Down Expand Up @@ -120,7 +120,7 @@


#' @keywords internal
.describe_posterior <- function(x,

Check warning on line 123 in R/describe_posterior.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/describe_posterior.R,line=123,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 68 to at most 40.
centrality = "median",
dispersion = FALSE,
ci = 0.95,
Expand Down Expand Up @@ -1448,5 +1448,5 @@
"equivalence", "equivalence_test", "equitest"
)

return(is.character(test) && length(test) > 0L && any(need_rope %in% tolower(test)))

Check warning on line 1451 in R/describe_posterior.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/describe_posterior.R,line=1451,col=3,[return_linter] Use implicit return behavior; explicit return() is not needed.
}
}
14 changes: 7 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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***

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand Down
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# bayestestR <img src='man/figures/logo.png' align="right" height="139" />

[![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***

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -477,7 +475,7 @@ By contributing to this project, you agree to abide by its terms.
# References

<div id="refs" class="references csl-bib-body hanging-indent"
line-spacing="2">
entry-spacing="0" line-spacing="2">

<div id="ref-kruschke2018rejecting" class="csl-entry">

Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ lm
maths
mattansb
mcmc
mfx
modelling
nbinom
neq
Expand Down
Binary file modified man/figures/unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 12 additions & 14 deletions tests/testthat/test-rope.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,19 @@
})


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))
Expand All @@ -107,9 +118,7 @@
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))

Check warning on line 121 in tests/testthat/test-rope.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-rope.R,line=121,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
rope <- rope(model, verbose = FALSE)

test_that("rope (brms, multivariate)", {
Expand All @@ -122,14 +131,3 @@
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)
})
2 changes: 1 addition & 1 deletion vignettes/bayes_factors.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
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)
```
Expand Down Expand Up @@ -969,7 +969,7 @@
```{r eval=FALSE}
library(emmeans)

(group_diff <- emmeans(model, pairwise ~ group, data = sleep))

Check warning on line 972 in vignettes/bayes_factors.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/bayes_factors.Rmd,line=972,col=2,[implicit_assignment_linter] Call print() explicitly instead of relying on implicit printing behavior via '('.

# pass the original model via prior
bayesfactor_parameters(group_diff, prior = model)
Expand All @@ -977,7 +977,7 @@
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(emmeans)

suppressWarnings((group_diff <- emmeans(model, pairwise ~ group, data = sleep)))

Check warning on line 980 in vignettes/bayes_factors.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/bayes_factors.Rmd,line=980,col=19,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.

# pass the original model via prior
suppressWarnings(bayesfactor_parameters(group_diff, prior = model))
Expand Down Expand Up @@ -1045,7 +1045,7 @@
```

```{r eval=FALSE}
(pairs_sum <- pairs(emmeans(fit_sum, ~Species)))

Check warning on line 1048 in vignettes/bayes_factors.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/bayes_factors.Rmd,line=1048,col=2,[implicit_assignment_linter] Call print() explicitly instead of relying on implicit printing behavior via '('.

ggplot(stack(insight::get_parameters(pairs_sum)), aes(x = values, fill = ind)) +
geom_density(linewidth = 1) +
Expand All @@ -1054,7 +1054,7 @@
theme(legend.position = "none")
```
```{r echo=FALSE, warning=FALSE, message=FALSE}
(pairs_sum <- suppressWarnings(pairs(emmeans(fit_sum, ~Species, data = iris))))

Check warning on line 1057 in vignettes/bayes_factors.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/bayes_factors.Rmd,line=1057,col=2,[implicit_assignment_linter] Call print() explicitly instead of relying on implicit printing behavior via '('.

ggplot(stack(insight::get_parameters(pairs_sum)), aes(x = values, fill = ind)) +
geom_density(linewidth = 1) +
Expand Down Expand Up @@ -1109,7 +1109,7 @@


```{r eval=FALSE}
(pairs_bayes <- pairs(emmeans(fit_bayes, ~Species)))

Check warning on line 1112 in vignettes/bayes_factors.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/bayes_factors.Rmd,line=1112,col=2,[implicit_assignment_linter] Call print() explicitly instead of relying on implicit printing behavior via '('.

ggplot(stack(insight::get_parameters(pairs_bayes)), aes(x = values, fill = ind)) +
geom_density(linewidth = 1) +
Expand All @@ -1118,7 +1118,7 @@
theme(legend.position = "none")
```
```{r echo=FALSE, warning=FALSE, message=FALSE}
(pairs_bayes <- suppressWarnings(pairs(emmeans(fit_bayes, ~Species, data = iris))))

Check warning on line 1121 in vignettes/bayes_factors.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/bayes_factors.Rmd,line=1121,col=2,[implicit_assignment_linter] Call print() explicitly instead of relying on implicit printing behavior via '('.

ggplot(stack(insight::get_parameters(pairs_bayes)), aes(x = values, fill = ind)) +
geom_density(linewidth = 1) +
Expand Down
Loading