diff --git a/DESCRIPTION b/DESCRIPTION index 21d5e72f..54bd9e71 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: modelbased Title: Estimation of Model-Based Predictions, Contrasts and Means -Version: 0.9.0.25 +Version: 0.9.0.26 Authors@R: c(person(given = "Dominique", family = "Makowski", diff --git a/NEWS.md b/NEWS.md index 7dff7aac..28ae53d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -54,6 +54,8 @@ * Fixed issues with contrasting slopes when `backend` was `"emmeans"`. +* Fixed issue in `estimate_slopes()` for models from package *lme4*. + # modelbased 0.9.0 ## Breaking Changes diff --git a/R/get_marginaltrends.R b/R/get_marginaltrends.R index 593b3dfd..534c7b9a 100644 --- a/R/get_marginaltrends.R +++ b/R/get_marginaltrends.R @@ -31,10 +31,15 @@ get_marginaltrends <- function(model, if (is.null(by)) { datagrid <- datagrid_info <- NULL } else { - # setup arguments - dg_args <- list(model, by = by, verbose = FALSE) + dg_args <- list( + model, + by = by, + factors = "all", + include_random = TRUE, + verbose = FALSE + ) # add user-arguments from "...", but remove those arguments that are already set - dots[c("by", "verbose")] <- NULL + dots[c("by", "factors", "include_random", "verbose")] <- NULL dg_args <- insight::compact_list(c(dg_args, dots)) # Get corresponding datagrid (and deal with particular ats) diff --git a/inst/WORDLIST b/inst/WORDLIST index 6aa7ff57..38463fc2 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -104,6 +104,8 @@ intra io jmr lifecycle +lme +lme4 loess marginaleffects marginalizations diff --git a/tests/testthat/_snaps/plot/plot-slopes-5.svg b/tests/testthat/_snaps/plot/plot-slopes-5.svg index 38eca816..a679d8b2 100644 --- a/tests/testthat/_snaps/plot/plot-slopes-5.svg +++ b/tests/testthat/_snaps/plot/plot-slopes-5.svg @@ -27,29 +27,25 @@ - - - - - - - - - - + + + + + + + + + + -0 -1 -2 -3 -4 - - - - - +1 +2 +3 + + + diff --git a/tests/testthat/test-estimate_slopes.R b/tests/testthat/test-estimate_slopes.R index 495c9bdf..397895e7 100644 --- a/tests/testthat/test-estimate_slopes.R +++ b/tests/testthat/test-estimate_slopes.R @@ -93,3 +93,44 @@ test_that("estimate_slopes, custom comparison", { expect_identical(dim(out), c(1L, 7L)) expect_equal(out$Difference, -0.08782885, tolerance = 1e-4) }) + +skip_on_cran() + +test_that("estimate_slopes, works with lme4", { + skip_if_not_installed("lme4") + data(CO2) + model_lme4 <- suppressWarnings(lme4::lmer( + uptake ~ conc * Plant + Treatment + (1 | Type), + data = CO2 + )) + out <- estimate_slopes(model_lme4, trend = "conc", by = "Plant") + expect_identical(dim(out), c(12L, 7L)) + expect_equal( + out$Slope, + c( + 0.01847, 0.02553, 0.02322, 0.02119, 0.02458, 0.02548, 0.01366, + 0.01519, 0.02286, 0.00541, 0.00632, 0.01085 + ), + tolerance = 1e-3 + ) +}) + + +test_that("estimate_slopes, works with glmmTMB", { + skip_if_not_installed("glmmTMB") + data(CO2) + model_glmmTMB <- suppressWarnings(glmmTMB::glmmTMB( + uptake ~ conc * Plant + (1 | Type), + data = CO2 + )) + out <- estimate_slopes(model_glmmTMB, trend = "conc", by = "Plant") + expect_identical(dim(out), c(12L, 7L)) + expect_equal( + out$Slope, + c( + 0.01847, 0.02553, 0.02322, 0.02119, 0.02458, 0.02548, 0.01366, + 0.01519, 0.02286, 0.00541, 0.00632, 0.01085 + ), + tolerance = 1e-3 + ) +})