test_that("GLMM supports Poisson", { skip_if_not_installed("glmmTMB") set.seed(123) dat <- data.frame( id = factor(rep(1:10, each = 5)), x = rnorm(50) ) dat$y <- rpois( 50, lambda = exp(1 + 0.3 * dat$x) ) m <- fit_glmm( y ~ x + (1 | id), data = dat, family = "poisson" ) expect_s3_class(m, "biomix_glmm") expect_equal(m$family, "poisson") expect_false(m$zero_inflated) }) test_that("GLMM supports negative binomial 1", { skip_if_not_installed("glmmTMB") set.seed(123) dat <- data.frame( id = factor(rep(1:20, each = 10)), x = rnorm(200) ) ## Deliberately overdispersed count data mu <- exp(1 + 0.2 * dat$x) dat$y <- rpois( 200, lambda = mu * rgamma(200, shape = 2, rate = 2) ) m <- fit_glmm( y ~ x + (1 | id), data = dat, family = "nbinom1" ) expect_s3_class(m, "biomix_glmm") expect_equal(m$family, "nbinom1") expect_false(m$zero_inflated) }) test_that("GLMM supports negative binomial 2", { skip_if_not_installed("glmmTMB") set.seed(123) dat <- data.frame( id = factor(rep(1:20, each = 10)), x = rnorm(200) ) ## Overdispersed count data mu <- exp(1 + 0.2 * dat$x) dat$y <- rpois( 200, lambda = mu * rgamma(200, shape = 1.5, rate = 1.5) ) m <- fit_glmm( y ~ x + (1 | id), data = dat, family = "nbinom2" ) expect_s3_class(m, "biomix_glmm") expect_equal(m$family, "nbinom2") expect_false(m$zero_inflated) }) test_that("GLMM rejects unsupported family", { skip_if_not_installed("glmmTMB") dat <- data.frame( y = rpois(20, 5), x = rnorm(20) ) expect_error( fit_glmm( y ~ x, data = dat, family = "unsupported" ), "arg.*should be one of" ) })