if (FALSE) {
if (requireNamespace("marginaleffects") && interactive()) {
data(efc)
efc$c172code <- as.factor(efc$c172code)
efc$c161sex <- as.factor(efc$c161sex)
levels(efc$c161sex) <- c("male", "female")
m <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc)
# direct computation of comparisons
hypothesis_test(m, "c172code")
# passing a `ggeffects` object
pred <- ggpredict(m, "c172code")
hypothesis_test(pred)
# test for slope
hypothesis_test(m, "c12hour")
# interaction - contrasts by groups
m <- lm(barthtot ~ c12hour + c161sex * c172code + neg_c_7, data = efc)
hypothesis_test(m, c("c161sex", "c172code"), test = NULL)
# interaction - pairwise comparisons by groups
hypothesis_test(m, c("c161sex", "c172code"))
# interaction - collapse unique levels
hypothesis_test(m, c("c161sex", "c172code"), collapse_levels = TRUE)
# p-value adjustment
hypothesis_test(m, c("c161sex", "c172code"), p_adjust = "tukey")
# not all comparisons, only by specific group levels
hypothesis_test(m, "c172code", by = "c161sex")
# specific comparisons
hypothesis_test(m, c("c161sex", "c172code"), test = "b2 = b1")
# interaction - slope by groups
m <- lm(barthtot ~ c12hour + neg_c_7 * c172code + c161sex, data = efc)
hypothesis_test(m, c("neg_c_7", "c172code"))
}
}
Run the code above in your browser using DataLab