How to get hypothesis() to test difference between level combination in a regression with interaction

Hi all,

does anyone knows how to compare all possible comparison between levels when the regression includes a interaction term?

Let say I have this data set with 3 species and sex values for each species.

exmp_dat <- data.frame(resp = rep(c(0, 1, 1, 0, 3, 4), each = 10), sp = rep(letters[1:3], each = 20), sx = rep(c("f", "m"), each = 10))
exmp_dat$resp <- exmp_dat$resp + rnorm(nrow(exmp_dat), sd = 0.01)

I would like to compare all combinations between sp and sx against each other (e.g spa_sxf vs spa_sxm, spa_sxf vs spb_sxm, spa_sxf vs spc_sxm, spa_sxm vs spa_sxm, spa_sxm vs spb_sxm, spa_sxm vs spc_sxm, …) . I know the function brms::hyopthesis can do that I but seems to behave differently when having an interaction term.



You could try emmeans. E.g.:

m <- lm(qsec ~ factor(cyl) * factor(am), mtcars)
emmeans(m, pairwise ~ cyl + am)

emmeans supports models fit by brm.

1 Like