rvlenth / emmeans

Estimated marginal means
https://rvlenth.github.io/emmeans/
364 stars 32 forks source link

How exactly should I specify contrasts for a pre-post design? #362

Closed qdread closed 2 years ago

qdread commented 2 years ago

Hi Russ, thanks again for being a wizard with this package! I just wanted to make sure I am doing a certain contrast correctly, and hoped you have a spare moment to take a look. I have a design with five levels of flooding treatment: a control without flooding and four different flooding regimes (the treatment column is called field in the data frame). Measurements were taken before and after flooding (the column time is a factor with two levels, "pre" and "post"). I am not sure exactly which contrasts to run to test the hypothesis if a particular treatment differs from the control, adjusting for the baseline values. I believe it is

fit <- lmer(log(inorn) ~ field + depth + time + field:depth + field:time + depth:time + field:depth:time + (1|site) + (1|pos:site), data = flooding)
emm_trt_by_time <- emmeans(fit, specs = ~ field + time, type = 'response')
contrasts_trt_by_time <- contrast(emm_trt_by_time, interaction = 'trt.vs.ctrl', adjust = 'sidak', by = NULL)

which results in

field_trt.vs.ctrl time_trt.vs.ctrl ratio    SE  df null t.ratio p.value
 P / C             post / pre       0.601 0.121 437    1  -2.531  0.0461
 F / C             post / pre       0.611 0.123 437    1  -2.450  0.0574
 W / C             post / pre       0.608 0.122 437    1  -2.471  0.0543
 FW / C            post / pre       0.715 0.144 437    1  -1.665  0.3340

Results are averaged over the levels of: depth 
Degrees-of-freedom method: kenward-roger 
P value adjustment: sidak method for 4 tests 
Tests are performed on the log scale 

(Note there is an additional variable in the model, depth, which I've glossed over for the purposes of this question.) I just want to check and see if these are the correct contrasts for a design where pre-post measurements were taken in control and treated units, as well as if I adjusted for the correct number of multiple comparisons. Thanks in advance!

rvlenth commented 2 years ago

Looks OK to me

Russ

Sent from my iPad

On Jul 26, 2022, at 9:36 AM, Quentin Read @.***> wrote:



Hi Russ, thanks again for being a wizard with this package! I just wanted to make sure I am doing a certain contrast correctly, and hoped you have a spare moment to take a look. I have a design with five levels of flooding treatment: a control without flooding and four different flooding regimes (the treatment column is called field in the data frame). Measurements were taken before and after flooding (the column time is a factor with two levels, "pre" and "post"). I am not sure exactly which contrasts to run to test the hypothesis if a particular treatment differs from the control, adjusting for the baseline values. I believe it is

emm_trt_by_time <- emmeans(fit, specs = ~ field + time, type = 'response') contrasts_trt_by_time <- contrast(emm_trt_by_time, interaction = 'trt.vs.ctrl', adjust = 'sidak', by = NULL)

which results in

field_trt.vs.ctrl time_trt.vs.ctrl ratio SE df null t.ratio p.value P / C post / pre 0.601 0.121 437 1 -2.531 0.0461 F / C post / pre 0.611 0.123 437 1 -2.450 0.0574 W / C post / pre 0.608 0.122 437 1 -2.471 0.0543 FW / C post / pre 0.715 0.144 437 1 -1.665 0.3340

Results are averaged over the levels of: depth Degrees-of-freedom method: kenward-roger P value adjustment: sidak method for 4 tests Tests are performed on the log scale

(Note there is an additional variable in the model, depth, which I've glossed over for the purposes of this question.) I just want to check and see if these are the correct contrasts for a design where pre-post measurements were taken in control and treated units, as well as if I adjusted for the correct number of multiple comparisons. Thanks in advance!

— Reply to this email directly, view it on GitHubhttps://github.com/rvlenth/emmeans/issues/362, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGMJPLYEVX3JZQ3L73ZSFI3VV7ZU7ANCNFSM54WF26BQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

qdread commented 2 years ago

Thanks Russ!