Skip to content

Commit

Permalink
bayesian_as_frequentist() fails for brms 0 + Intercept formula
Browse files Browse the repository at this point in the history
Fixes #646
  • Loading branch information
strengejacke committed Jul 9, 2024
1 parent 5c5fbdc commit 9779dbf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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.13.2.4
Version: 0.13.2.5
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
* `bayesian_as_frequentist()` now supports more model families from Bayesian
models that can be successfully converted to their frequentists counterparts.

## Bug fixes

* Fixed issue in `bayesian_as_frequentist()` for *brms* models with `0 + Intercept`
specification in the model formula.

# bayestestR 0.13.2

## Breaking Changes
Expand Down
8 changes: 8 additions & 0 deletions R/convert_bayesian_to_frequentist.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ convert_bayesian_as_frequentist <- function(model, data = NULL, REML = TRUE) {
model_formula <- insight::find_formula(model)
model_family <- insight::get_family(model)

# fix exception: The 0 + Intercept syntax in brms can be used to facilitate
# prior specification for the intercept, but but it leads to issues where it
# wrongly can be believed that Intercept is a variable and not a special term.
f_string <- insight::safe_deparse(model_formula$conditional)
if (grepl("0 + Intercept", f_string, fixed = TRUE)) {
model_formula$conditional <- stats::as.formula(gsub("0 + Intercept", "1", f_string, fixed = TRUE))
}

if (inherits(model_family, "brmsfamily")) {
insight::check_if_installed("glmmTMB")
# exception: ordbetareg()
Expand Down

0 comments on commit 9779dbf

Please sign in to comment.