tests/testthat/test-MixMod.R

skip_on_cran()
skip_on_os(c("mac", "solaris"))

skip_if_not_installed("emmeans")
skip_if_not_installed("GLMMadaptive")
skip_if_not_installed("lme4")

test_that("ggpredict", {
  data(fish, package = "ggeffects")
  set.seed(123)
  m1 <- GLMMadaptive::mixed_model(
    count ~ child + camper,
    random = ~ 1 | persons,
    zi_fixed = ~ child + livebait,
    zi_random = ~ 1 | persons,
    data = fish,
    family = GLMMadaptive::zi.poisson()
  )
  m2 <- GLMMadaptive::mixed_model(
    nofish ~ xb + zg,
    random = ~ 1 | persons,
    data = fish,
    family = binomial
  )
  set.seed(123)
  expect_warning({
    p <- ggpredict(m1, c("child", "camper"), type = "zero_inflated")
  })
  expect_equal(p$predicted[1], 2.045537, tolerance = 1e-2)

  set.seed(123)
  p <- ggpredict(m1, c("child", "camper"), type = "zero_inflated_random", condition = c(count = 3.296))
  expect_equal(p$predicted[1], 4.982773, tolerance = 1e-2)

  set.seed(123)
  p <- ggpredict(m1, c("child", "camper"), type = "zero_inflated_random", condition = c(count = 0))
  expect_equal(p$predicted[1], 0.5115884, tolerance = 1e-2)

  set.seed(123)
  p <- ggemmeans(m1, c("child", "camper"), type = "zero_inflated")
  expect_equal(p$predicted[1], 1.816723, tolerance = 1e-2)

  set.seed(123)
  p <- ggemmeans(m1, c("child", "camper"), type = "zero_inflated_random")
  expect_equal(p$predicted[1], 3.457011, tolerance = 1e-2)

  expect_warning(expect_message(ggpredict(m1, c("child", "camper"), type = "fixed")))
  expect_warning(expect_message(ggpredict(m2, "zg", type = "zero_inflated")))
})

Try the ggeffects package in your browser

Any scripts or data that you put into this service are public.

ggeffects documentation built on Sept. 12, 2024, 7:41 a.m.