I am fitting a Linear Mixed Model using the lmerTest package. I have two fixed effects: group (categorical, 2 levels) and period (categorical, 3 levels). I have an interaction term between the two fixed effects period*group The response variable is continuous. I have one random effect (id). Please see the data below:
> moddf <- dput(mydata)
structure(list(id = c("id3", "id5", "id3", "id5", "id3", "id5",
"id1", "id2", "id4", "id6", "id7", "id8", "new", "id1", "id2",
"id4", "id6", "id7", "id8", "new", "id1", "id2", "id4", "id6",
"id7", "id8", "new"), area = c(28.28, 11.04, 31, 10.28, 18.4,
18.12, 17.56, 18.28, 13.04, 14.24, 21.44, 26.48, 22.56, 7.92,
16.28, 8.52, 16.8, 7.36, 11.56, 17.64, 4.56, 5.04, 8.16, 6.2,
3.24, 5.28, 6.6), period = structure(c(1L, 1L, 2L, 2L, 3L, 3L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 3L, 3L, 3L), levels = c("night", "outside", "within"), class = "factor"),
group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L), levels = c("groupN", "groupP"), class = "factor")), row.names = c(NA,
-27L), class = "data.frame")
I specified the following model:
lmR_g <- lmerTest::lmer(area ~ group + period + period*group + (1|id), data = moddf, REML = F)
The summary shows that the interaction is significant. And visual representation asks for a post hoc analysis as the effects of period clearly differs in the two groups (see plot). While there are different options described online, I am unsure which one is most appropriate. I have used lsmeans so far to test for each period at the levels of the group (see below). However, any advice regarding post hoc options for this situation as well as advice if the $lsmeans or $contrasts should be used if lsmeans() is applied would be highly appreciated.
lsmeans(lmR_g, pairwise ~ period | group)
$lsmeans
group = groupN:
period lsmean SE df lower.CL upper.CL
night 19.66 3.89 29.9 11.71 27.61
outside 20.64 3.89 29.9 12.69 28.59
within 18.26 3.89 29.9 10.31 26.21
group = groupP:
period lsmean SE df lower.CL upper.CL
night 19.09 2.08 29.9 14.83 23.34
outside 12.30 2.08 29.9 8.05 16.55
within 5.58 2.08 29.9 1.33 9.83
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
$contrasts
group = groupN:
contrast estimate SE df t.ratio p.value
night - outside -0.98 4.65 23.1 -0.211 0.9759
night - within 1.40 4.65 23.1 0.301 0.9515
outside - within 2.38 4.65 23.1 0.511 0.8666
group = groupP:
contrast estimate SE df t.ratio p.value
night - outside 6.79 2.49 23.1 2.729 0.0309
night - within 13.50 2.49 23.1 5.427 <.0001
outside - within 6.71 2.49 23.1 2.699 0.0329
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates