Skip to content

Commit

Permalink
Update test-glmmTMB.R
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jan 25, 2025
1 parent 3aaa54f commit 8d6d66c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/testthat/test-glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test_that("estimate_means - glmmTMB", {
## marginaleffects for zero-inflated model, zero-inflation probabilities
estim1 <- estimate_means(model, by = "mined", backend = "marginaleffects", predict = "zprob")
estim2 <- estimate_means(model, backend = "marginaleffects", predict = "zprob")
expect_equal(estim1$Probability, estim2$predicted, tolerance = 1e-3)
expect_equal(estim1$Probability, estim2$Probability, tolerance = 1e-3)
# validated against ggeffects
expect_equal(estim1$Probability, c(0.75755, 0.35508), tolerance = 1e-3)
estim_me <- marginaleffects::avg_predictions(
Expand All @@ -62,15 +62,15 @@ test_that("estimate_contrasts - glmmTMB", {

## contrasts marginaleffects for zero-inflated model, count component
estim3 <- suppressMessages(estimate_contrasts(model, contrast = "mined", backend = "marginaleffects"))
expect_equal(estim3$Difference, -1.99344, tolerance = 1e-3)
expect_equal(estim3$Difference, 1.99344, tolerance = 1e-3)
estim_me <- marginaleffects::avg_predictions(
model,
newdata = insight::get_datagrid(model, by = "mined", factors = "all", include_random = TRUE),
by = "mined",
hypothesis = ~pairwise,
re.form = NULL
)
expect_equal(estim3$Difference, estim_me$estimate[2], tolerance = 1e-3)
expect_equal(estim3$Difference, estim_me$estimate, tolerance = 1e-3)

# select default for contrast automatically works
estim4 <- suppressMessages(estimate_contrasts(model, backend = "marginaleffects"))
Expand All @@ -80,7 +80,7 @@ test_that("estimate_contrasts - glmmTMB", {
estim1 <- suppressMessages(estimate_contrasts(model, component = "zi", backend = "emmeans"))
estim2 <- predict(model, type = "zprob", newdata = insight::get_datagrid(model, "mined"))
expect_identical(dim(estim1), c(1L, 9L))
expect_equal(estim1$Difference, diff(estim2), tolerance = 1e-1)
expect_equal(estim1$Difference * -1, diff(estim2), tolerance = 1e-1)
expect_identical(c(estim1$Level1[1], estim1$Level2[1]), c("yes", "no"))

## contrasts marginaleffects for zero-inflated model, zero-inflation probability component
Expand Down

0 comments on commit 8d6d66c

Please sign in to comment.