[R-sig-ME] Post-hoc analysis for the effect of a lower-order interaction

Lenth, Russell V ru@@e||-|enth @end|ng |rom u|ow@@edu
Fri Feb 4 21:34:08 CET 2022


Please refer to the package's vignette on interactions:
    https://cran.r-project.org/web/packages/emmeans/vignettes/interactions.html

The simple way is to use the 'interaction' argument in 'contrast()' to generate interaction contrasts. For example:

    > library(emmens)

    > noise.lm <- lm(noise/10 ~ size * type * side, data = auto.noise)
    > EMM <- emmeans(noise.lm, ~ size*side*type)

    > contrast(EMM, interaction = "pairwise")
     size_pairwise side_pairwise type_pairwise estimate    SE df t.ratio p.value
     S - M         L - R         Std - Octel       0.50 0.624 24   0.802  0.4305
     S - L         L - R         Std - Octel       2.67 0.624 24   4.276  0.0003
     M - L         L - R         Std - Octel       2.17 0.624 24   3.474  0.0020

It is possible to do this manually by using 'contrast()' (or 'pairs()' method for pairwise comparisons) to create contrasts for one factor, calling 'contrast()' on the result to obtain contrasts of contrasts, etc. Here is the same example (with a multiplicity adjustment added) done manually:

> PR1 = pairs(EMM, by = c("side", "type"), name = "size.diff")
> PR2 = pairs(PR1, by = c("size.diff", "type"), name = "side.diff")
> PR3 = pairs(PR2, by = c("size.diff", "side.diff"), name = "type.diff")

> test(PR3, by = NULL, adjust = "sidak")
 type.diff   size.diff side.diff estimate    SE df t.ratio p.value
 Std - Octel S - M     L - R         0.50 0.624 24   0.802  0.8153
 Std - Octel S - L     L - R         2.67 0.624 24   4.276  0.0008
 Std - Octel M - L     L - R         2.17 0.624 24   3.474  0.0059

P value adjustment: sidak method for 3 tests

Russ Lenth

> Hi everyone,
>
> I recently got stuck in the post-hoc analysis for my model's interactions. 
>
>Let's say the interaction in the model is A:B:C, with the three variables being all two-level factors. I want to check if the effect of A:B varies across the two levels of C (getting a t-test between C's two levels, as what we get from the pairs() function for getting the difference of marginal means/slopes in a 2-way interaction).
>
> I've tried both emmeans and emtrends functions but failed. It always ended up expanding the higher-order interaction of all the three variables into basic cell contrasts (i.e. on specific levels of A and B), but not provided the overall contrast of how the lower-order interaction (A:B) performs in general on the two different levels of C. I also tried the joint_test function, but there is only the output of coefficients but not a between-level comparison on C. I am looking for the estimations of A:B on the two levels of C, and a t-test between these two estimations at the same time. Is this possible only using the emmeans package? Can I have some hints from you guys?



More information about the R-sig-mixed-models mailing list