Skip to content

Commit 64e224e

Browse files
committed
fix, tests
1 parent 65b8f0a commit 64e224e

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

R/format_p_adjust.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ format_p_adjust <- function(method) {
101101
if (!is.null(by_vars) && by_vars %in% colnames(params)) {
102102
correction <- insight::n_unique(params[[by_vars]])
103103
} else {
104-
correction <- prod(vapply(model@model.info$xlev, length, numeric(1)))
104+
correction <- .safe(prod(vapply(model@model.info$xlev, length, numeric(1))))
105+
correction <- .safe(insight::n_unique(unlist(strsplit(
106+
model@levels$contrast,
107+
" - ",
108+
fixed = TRUE
109+
))))
105110
}
106111

107112
correction

tests/testthat/test-p_adjust.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ test_that("model_parameters, emmeans, p-adjust", {
8888
myc <- pairs(emmeans::emmeans(warp.lm, ~ wool + tension))
8989
mp <- model_parameters(myc, p_adjust = "tukey")
9090
expect_equal(mp$p, as.data.frame(myc)$p.value, tolerance = 1e-4)
91+
92+
skip_if(getRversion() < "4.5.0")
93+
data(penguins)
94+
m <- lm(bill_len ~ sex * species + island, data = penguins)
95+
emm <- pairs(emmeans::emmeans(m, ~ sex + species))
96+
mp <- model_parameters(emm, p_adjust = "tukey")
97+
expect_equal(mp$p, as.data.frame(emm)$p.value, tolerance = 1e-4)
9198
})
9299

93100

0 commit comments

Comments
 (0)