@@ -703,7 +703,7 @@ test_that("estimate_contrasts - p.adjust", {
703703 skip_if(getRversion() < " 4.5.0" )
704704 skip_if_not_installed(" emmeans" )
705705
706- data(penguins )
706+ data(penguins , package = " datasets " )
707707 m_spec <- lm(body_mass ~ species , data = penguins )
708708 out1 <- estimate_contrasts(m_spec , p_adjust = " tukey" )
709709 out2 <- estimate_contrasts(m_spec , p_adjust = " tukey" , backend = " emmeans" )
@@ -1709,7 +1709,7 @@ test_that("estimate_contrast, informative error when `by` and `contrast` are the
17091709
17101710test_that(" estimate_contrast, works with aov (when no statistic is extracted)" , {
17111711 skip_if(getRversion() < " 4.5.0" )
1712- data(penguins )
1712+ data(penguins , package = " datasets " )
17131713 fit <- aov(formula = body_mass ~ species , data = penguins )
17141714
17151715 out1 <- marginaleffects :: avg_predictions(fit , by = " species" , hypothesis = ~ pairwise )
@@ -1736,7 +1736,7 @@ test_that("estimate_contrast, works with aov (when no statistic is extracted)",
17361736test_that(" estimate_contrast, slopes with different estimate options" , {
17371737 skip_if(getRversion() < " 4.5.0" )
17381738 skip_if_not_installed(" datawizard" )
1739- data(penguins )
1739+ data(penguins , package = " datasets " )
17401740 penguins $ long_bill <- factor (
17411741 datawizard :: categorize(penguins $ bill_len ),
17421742 labels = c(" short" , " long" )
@@ -1766,3 +1766,26 @@ test_that("estimate_contrast, comparison-options as strings", {
17661766 out <- estimate_contrasts(mod2 , contrast = " cyl_helmert" , comparison = " poly" )
17671767 expect_equal(out $ Difference , c(- 8.17673 , 0.92996 ), tolerance = 1e-4 )
17681768})
1769+
1770+
1771+ test_that(" estimate_contrast, p-adjust tukey works for contrasting slopes" , {
1772+ skip_if(getRversion() < " 4.5.0" )
1773+ skip_if_not_installed(" emmeans" )
1774+
1775+ data(penguins , package = " datasets" )
1776+ m <- lm(flipper_len ~ body_mass * species , data = penguins )
1777+
1778+ out1 <- as.data.frame(pairs(emmeans :: emtrends(m , ~ species , var = " body_mass" )))
1779+ out2 <- estimate_contrasts(
1780+ m ,
1781+ contrast = " body_mass" ,
1782+ by = " species" ,
1783+ p_adjust = " tukey"
1784+ )
1785+
1786+ # Note: p-values from emmeans::emtrends() + pairs() and estimate_contrasts()
1787+ # can differ slightly due to different underlying calculation/adjustment
1788+ # methods, especially with Tukey p-adjustment. A tolerance of 1e-2 is used
1789+ # here to avoid fragile tests while still ensuring close agreement.
1790+ expect_equal(out1 $ p.value , out2 $ p , tolerance = 1e-2 )
1791+ })
0 commit comments