1
$\begingroup$

I'm trying to understand the difference between the interaction with the anova function and the interaction with the contrast function

library(emmeans)
pigs2 <- subset(pigs, pigs$percent<15)
pigs.lm <- lm(log(conc) ~ source*factor(percent), data = pigs2)
anova(pigs.lm)

This is the output for the interaction

                        Df   Sum Sq  Mean Sq F value   Pr(>F) 
source:factor(percent)  2 0.003116 0.001558  0.1211 0.887130

Now using emmeans

emm <- emmeans(pigs.lm, ~ source * factor(percent))
contrast(emm, list(con = c(1,0,-1,-1,0,1)))

which gives me

     contrast    estimate        SE df t.ratio p.value
    con      -0.01946701 0.1389334 11   -0.14  0.8911

I realize that the significance is very similar, but shouldn't they be exactly the same? Also shouldn't the F value in the anova output above be the same as the t.ratio squared?

$\endgroup$

1 Answer 1

1
$\begingroup$

You will note in the anova table that the interaction has 2 d.f. That means that the interaction comprises two dimensions, and you need to see two interaction contrasts to explain it all. Try this:

(cons = contrast(emm, interaction = "consec"))

That shows one example of two contrasts involved in the interaction, and tests for each one. Do:

coef(cons)

to see exactly the contrast coefficients.

Finally, do

test(cons, joint = TRUE)

to see a test of the two contrasts jointly.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.