2

How does one perform a contrast of specified contrasts using the emmeans package?

I am interested in the difference of the differences at two time points. Where I have used the pairs(LF) statement at the end I get the correct estimates, but the same p values (and I want individual tests of hypotheses - i.e. I would expect different p values depending on the magnitude of the estimate).

> mod.rg <- ref_grid(mod, at = list(time = c(0, 1, 7, 13, 26)))
> (mod_em <- emmeans(mod.rg, c("TX_GROUP","time")))

TX_GROUP time emmean   SE  df asymp.LCL asymp.UCL
 0           0   57.8 2.77 Inf      52.4      63.2
 1           0   64.0 1.75 Inf      60.6      67.4
 0           1   58.0 2.81 Inf      52.5      63.5
 1           1   64.3 1.76 Inf      60.9      67.8
 0           7   59.0 3.09 Inf      52.9      65.1
 1           7   66.3 1.92 Inf      62.5      70.0
 0          13   60.0 3.49 Inf      53.2      66.9
 1          13   68.2 2.18 Inf      64.0      72.5
 0          26   62.2 4.62 Inf      53.2      71.3
 1          26   72.5 2.93 Inf      66.7      78.2

Covariance estimate used: vbeta 
Confidence level used: 0.95 



> # Test contrasts
> (LF <- contrast(mod_em, list(Baseline = c(-1, 1, 0, 0, 0, 0, 0, 0, 0, 0), `1 month` = c(0, 0, -1, 1, 0, 0, 0, 0, 0, 0) , `7 months` = c(0, 0, 0, 0, -1, 1, 0, 0, 0, 0), `13 months` = c(0, 0, 0, 0, 0, 0, -1, 1, 0, 0), `24 months` = c(0, 0, 0, 0, 0, 0, 0, 0, -1, 1))))

 contrast  estimate   SE  df z.ratio p.value
 Baseline      6.17 3.32 Inf    1.86  0.0629
 1 month       6.33 3.36 Inf    1.89  0.0592
 7 months      7.27 3.68 Inf    1.98  0.0482
 13 months     8.21 4.16 Inf    1.98  0.0483
 24 months    10.25 5.51 Inf    1.86  0.0629



> # Contrasts of contrasts
> pairs(LF)

 contrast              estimate    SE  df z.ratio p.value
 Baseline - 1 month      -0.157 0.142 Inf    -1.1  0.8046
 Baseline - 7 months     -1.098 0.994 Inf    -1.1  0.8046
 Baseline - 13 months    -2.038 1.847 Inf    -1.1  0.8046
 Baseline - 24 months    -4.077 3.693 Inf    -1.1  0.8046
 1 month - 7 months      -0.941 0.852 Inf    -1.1  0.8046
 1 month - 13 months     -1.882 1.704 Inf    -1.1  0.8046
 1 month - 24 months     -3.920 3.551 Inf    -1.1  0.8046
 7 months - 13 months    -0.941 0.852 Inf    -1.1  0.8046
 7 months - 24 months    -2.979 2.699 Inf    -1.1  0.8046
 13 months - 24 months   -2.038 1.847 Inf    -1.1  0.8046

P value adjustment: tukey method for comparing a family of 5 estimates 
LucaS
  • 887
  • 1
  • 9
  • 22
  • For starters, look at `vignette(“contrasts”, “emmeans”)` – Russ Lenth May 21 '18 at 03:02
  • Thanks - I have looked at the vignette, but it's still not clear to me from reading that. – LucaS May 21 '18 at 03:17
  • 1
    It appears you have fitted a model with a linear trend for time. Thus, comparing two different times is just testing the slope of that one trend line, regardless of which two times you pick. EMMs are based on a model, not directly on the data. – Russ Lenth May 21 '18 at 03:26
  • 1
    If time is indeed intended as a factor with levels 0, 1, 7, etc. then first fit a model using `factor(time)` as a predictor, rather than time as a numeric predictor. – Russ Lenth May 21 '18 at 03:29
  • Of course that makes sense when I think about it. Thank you very much. – LucaS May 21 '18 at 04:11
  • 1
    After that change, you should drop the `at` part from your `emmeans` call. And `contrast(mod_emm, interaction = “pairwise”)` should get you the desired results. – Russ Lenth May 21 '18 at 15:23

0 Answers0