Skip to content

Commit

Permalink
Merge pull request #566 from etiennebacher/find-formula-lmBF
Browse files Browse the repository at this point in the history
  • Loading branch information
bwiernik authored Oct 10, 2022
2 parents 2f1b03a + 3b6cf10 commit c68af2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/find_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,9 @@ find_formula.BFBayesFactor <- function(x, verbose = TRUE, ...) {
for (i in frand) {
fcond <- sub(i, "", fcond, fixed = TRUE)
}
while (grepl("(\\+)\\s+\\1", trim_ws(fcond))) {
fcond <- gsub("(\\+)\\s+\\1", "\\1", trim_ws(fcond))
}
while (grepl("\\+$", trim_ws(fcond))) {
fcond <- gsub("(.*)\\+$", "\\1", trim_ws(fcond))
}
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-BayesFactorBF.R
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,26 @@ if (.runThisTest && requiet("testthat") && requiet("insight") && requiet("stats"
tolerance = 1e-5
)
})


# ---------------------------
# Comes from https://github.com/easystats/bayestestR/issues/505

mtcars$cyl <- factor(mtcars$cyl)
mtcars$gear <- factor(mtcars$gear)
model <- lmBF(mpg ~ cyl + gear + cyl:gear, mtcars,
progress = FALSE, whichRandom = c("gear", "cyl:gear"))

test_that("find_formula for lmBF", {

predicted_form <- find_formula(model)$conditional
true_form <- formula(mpg ~ cyl + cyl:gear)

expect_equal(
predicted_form,
true_form,
ignore_attr = TRUE
)
})

}

0 comments on commit c68af2c

Please sign in to comment.