I have attached some published data (at the end) that comes from a link on:
I now want to run a constrained version of the model essentially forcing the main effect for group to be equal to 0. To do this, I followed the steps to 'merge' the treatment and time factors into one with a common baseline level and then new levels for each post treatment (page 12 at the following link):
But I don't know how (or if there's a way) of producing a similar plot using emmip, given the factor levels are combined. I would like to be able to essentially reproduce the first plot above showing the change for each group from the common baseline. I guess I can do this manually in ggplot - just wondered if there was some way of doing it with emmip straight out of the box?
dat <- structure(list(id = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L,
6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L,
13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L,
19L, 20L, 20L), treat = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 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,
2L), .Label = c("veh", "il_17"), class = "factor"), time = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("pre", "post"), class = "factor"),
y = c(63.9871851, 62.7837203, 58.4825871, 59.4795929, 59.7735716,
42.4923719, 51.0754017, 55.5395164, 55.8808155, 42.8811745,
38.686015, 40.6969206, 46.8213372, 61.6, 62.6084263, 62.987013,
54.5901379, 53.0518311, 60.99353, 65.8177226, 66.2765671,
77.6594363, 60.1260258, 80.5687204, 49.444707, 63.7658228,
55.1138485, 77.6594363, 61.4070066, 80.5687204, 52.4932976,
49.444707, 55.1138485, 57.5908965, 61.4070066, 54.4305875,
52.4932976, 68.6955215, 53.5461576, 68.3395943), treat_time = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L,
3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L), .Label = c("baseline",
"veh.post", "il_17.post"), class = "factor")), class = "data.frame", row.names = c(NA,
-40L))
CodePudding user response:
I guess if you are using the same baseline value for each treatment, you can do something like this:
foo = emmeans(m4, "treat_time")
bar = contrast(foo, list(b1 = c(1,0,0), p1 = c(0,1,0),
b2 = c(1,0,0), p2 = c(0,0,1)) )
levels(bar) = list(time = c("baseline", "post"),
treat = c("veh", "il_17") )
emmip(bar, treat ~ time)
simpler way
I discovered you can greatly simplify the second step:
foo = emmeans(m4, "treat_time")
bar = foo[c(1,2,1,3)]
levels(bar) = list(time = c("baseline", "post"),
treat = c("veh", "il_17") )
emmip(bar, treat ~ time)


