Help me with Contrast Coding for Linear Mixed Models with Interactions of Group and Continuous value - emmeans and lme4

x-post: regression - Contrast Coding for Linear Mixed Models with Interactions of Group and Continuous value - emmeans and lme4 - Cross Validated

Data: structure(list(record_id = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1 - Pastebin.com

I wrote the following mixed model:

lmer(cumulative.wk.dose ~ poly(date,2,raw=TRUE)*bin + (1|record_id), data=df)

There are 52 days (date) and 3 bins (high, medium, and low). I want to compare the cumulative.wk.dose at date 52 for the 3 bins with emmeans but cannot figure out how to code it. I want to get confidence intervals and p-values for the high, med, and low bins at week 52.

The closest I got was

emmeans::emmeans(lmm.2, ~ bin|date,
                         cov.reduce = FALSE)

Which returns the following for every single date. How can I just return date 52?

date =  1:
 bin  emmean  SE  df asymp.LCL asymp.UCL
 high    767 303 Inf     174.3      1360
 med     428 206 Inf      25.5       831
 low     133 316 Inf    -486.6       752

date =  2:
 bin  emmean  SE  df asymp.LCL asymp.UCL
 high   1078 301 Inf     487.6      1668
 med     631 205 Inf     230.3      1032
 low     274 314 Inf    -341.8       891

...

date = 52:
 bin  emmean  SE  df asymp.LCL asymp.UCL
 high   9924 303 Inf    9330.6     10517
 med    6628 206 Inf    6225.5      7031
 low    5451 316 Inf    4831.5      6070

and then using emmeans:pairs() I can return

date =  1:
 contrast   estimate  SE    df t.ratio p.value
 high - med      339 366 107.8   0.927  0.6247
 high - low      635 438 107.8   1.450  0.3190
 med - low       296 377 107.8   0.784  0.7136

date =  2:
 contrast   estimate  SE    df t.ratio p.value
 high - med      447 364 105.6   1.227  0.4401
 high - low      803 435 105.6   1.845  0.1601
 med - low       357 375 105.6   0.951  0.6094

...

date = 52:
 contrast   estimate  SE    df t.ratio p.value
 high - med     3295 366 107.8   9.008  <.0001
 high - low     4473 438 107.8  10.223  <.0001
 med - low      1178 377 107.8   3.123  0.0064

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.