After reading the vignettes of emmeans I am still struggling with what will probably have a very simple solution.
I have simulated some data from 2 groups of 6 subjects. Measurements are being taken up to 360 minutes (ExpDelta). I have the lme model as follows:
library(lme4)
library(emmeans)
lme.model = lmer(Value ~ Treatment*ExpDelta + Baseline + (1 | SubjectNr), data = df)
Now, I can calculate the emmeans contrasts for every time point:
emm.s <- emmeans(lme.model, pairwise ~ Treatment | ExpDelta) # emmeans for every time point
or only by Treatment:
emm.s <- emmeans(lme.model, 'Treatment') # emmeans over the whole investigation period
pairwise_emm<-pairs(emm.s)
Both results look as expected. But now I want to only compare the 2 Treatment groups while excluding the ExpDelta 240 and 360 group and I can't figure out how.
So my question is: what is the p-value of Placebo vs 1 mg drug Y while excluding the data of ExpDelta 240 and 360?
A reference dataset is given below:
df<-structure(list(SubjectNr = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L,
12L, 12L, 12L, 12L), Treatment = structure(c(2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = c("Placebo", "1 mg drug Y"), class = "factor"),
ExpDelta = c("30", "60", "90", "120", "240", "360", "30",
"60", "90", "120", "240", "360", "30", "60", "90", "120",
"240", "360", "30", "60", "90", "120", "240", "360", "30",
"60", "90", "120", "240", "360", "30", "60", "90", "120",
"240", "360", "30", "60", "90", "120", "240", "360", "30",
"60", "90", "120", "240", "360", "30", "60", "90", "120",
"240", "360", "30", "60", "90", "120", "240", "360", "30",
"60", "90", "120", "240", "360", "30", "60", "90", "120",
"240", "360"), Baseline = c(9.64, 9.64, 9.64, 9.64, 9.64,
9.64, 7.92, 7.92, 7.92, 7.92, 7.92, 7.92, 5.88, 5.88, 5.88,
5.88, 5.88, 5.88, 11.79, 11.79, 11.79, 11.79, 11.79, 11.79,
11.07, 11.07, 11.07, 11.07, 11.07, 11.07, 9.38, 9.38, 9.38,
9.38, 9.38, 9.38, 12.37, 12.37, 12.37, 12.37, 12.37, 12.37,
8.51, 8.51, 8.51, 8.51, 8.51, 8.51, 10.86, 10.86, 10.86,
10.86, 10.86, 10.86, 8.13, 8.13, 8.13, 8.13, 8.13, 8.13,
11.79, 11.79, 11.79, 11.79, 11.79, 11.79, 9.3, 9.3, 9.3,
9.3, 9.3, 9.3), Value = c(10.72, 11.58, 11.3, 11.28, 10.39,
10.09, 8.78, 10.71, 11.01, 9.98, 8.15, 7.85, 6.6, 8.65, 7.86,
7.7, 6.61, 6.88, 12.91, 13.3, 14.13, 14.57, 12.31, 11.02,
10.78, 12.93, 13.07, 12.07, 11.92, 11.8, 10.62, 10.62, 12.26,
11.7, 10.86, 8.97, 13.03, 12.86, 13.5, 11.45, 12.78, 12.7,
9.14, 9.08, 7.81, 8.56, 8.51, 7.73, 10.86, 11.25, 11.5, 11.21,
10.6, 11.59, 8.57, 7.54, 7.87, 8.07, 7.56, 8.7, 11.46, 11.33,
12.1, 12.18, 11.69, 11.53, 9.73, 10.01, 8.85, 9.91, 10.02,
9.01)), row.names = c(NA, -72L), class = "data.frame")
subset
in the model fitting stage). – Russ Lenthexclude‘ or
include` argument when you callcontrast()‘ or
pairs()‘. See the documentation forpairwise.emmc
for details. OR useat
in the emmeans() call (see documentation for ‘ref_grid`) – Russ Lenth