Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jul 9, 2024
1 parent 6a1cc64 commit 5c5fbdc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Suggests:
mclust,
mediation,
modelbased,
ordbetareg,
parameters,
patchwork,
performance,
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/test-bayesian_as_frequentist.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,51 @@ test_that("rstanarm to freq", {

expect_equal(lme4::fixef(m1), lme4::fixef(m2), tolerance = 1e-3)
})


test_that("brms beta to freq", {
skip_on_cran()
skip_if_offline()
skip_if_not_or_load_if_installed("brms")
skip_if_not_or_load_if_installed("glmmTMB")
skip_if_not_or_load_if_installed("lme4")
skip_if_not_or_load_if_installed("httr")
skip_if_not_or_load_if_installed("betareg")

set.seed(333)
m <- insight::download_model("brms_beta_1")
data(FoodExpenditure, package = "betareg")
m1 <- glmmTMB::glmmTMB(
I(food / income) ~ income + (1 | persons),
data = FoodExpenditure,
family = glmmTMB::beta_family()
)
m2 <- convert_bayesian_as_frequentist(m)

expect_equal(lme4::fixef(m1)$cond[2], lme4::fixef(m2)$cond[2], tolerance = 1e-2)
})


test_that("ordbetareg to freq", {
skip_on_cran()
skip_if_offline()
skip_if_not_or_load_if_installed("brms")
skip_if_not_or_load_if_installed("ordbetareg")
skip_if_not_or_load_if_installed("glmmTMB")
skip_if_not_or_load_if_installed("lme4")
skip_if_not_or_load_if_installed("httr")
skip_if_not_or_load_if_installed("datawizard")

set.seed(333)
data(sleepstudy, package = "lme4")
m <- insight::download_model("ordbetareg_1")
sleepstudy$y <- datawizard::normalize(sleepstudy$Reaction)
m1 <- glmmTMB::glmmTMB(
y ~ Days + (Days | Subject),
data = sleepstudy,
family = glmmTMB::ordbeta()
)
m2 <- convert_bayesian_as_frequentist(m)

expect_equal(lme4::fixef(m1), lme4::fixef(m2), tolerance = 1e-1)
})

0 comments on commit 5c5fbdc

Please sign in to comment.