2
$\begingroup$

This analysis is based on data from https://stats.idre.ucla.edu/r/seminars/repeated-measures-analysis-with-r/ with some modifications.

Pulse measurements were made at 3 time points (1,2,3) for study participants randomized into 3 groups (A, B, C).

id <- c( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12)
group <- c( "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C")
pulse <- c( 35, 25, 12, 34, 22, 13, 36, 21, 18, 35, 23, 15, 31, 43, 57, 35, 46, 58, 37, 48, 51, 32, 45, 53, 29, 40, 59, 33, 43, 60, 35, 45, 53, 30, 42, 55)
time <- c( 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)
demo <- data.frame(id, group, time, pulse)
demo$id <- factor(demo$id)
demo$time <- factor(demo$time)

I have a repeated measures model with heterogeneous autoregressive covariance structure

library(nlme)
library(emmeans)

fit.arhx <- with(demo, lme(pulse ~ group*time, random = ~1|id, 
                                     cor=corAR1(), weight = varIdent(form = ~ 1|time)))


anova(fit.arhx)
            numDF denDF  F-value p-value
(Intercept)     1    18 4794.655  <.0001
group           2     9  106.818  <.0001
time            2    18   59.348  <.0001
group:time      4    18  249.381  <.0001

I got the marginal means as follows:

fit.emm <- emmeans(fit.arhx, ~group*time)
fit.emm.s <- update(fit.emm, infer = c(TRUE, TRUE))
fit.emm.s

 group time emmean    SE df lower.CL upper.CL t.ratio p.value
 A     1      35.0 1.051 11    32.69     37.3 33.300  <.0001 
 B     1      33.8 1.051  9    31.37     36.1 32.111  <.0001 
 C     1      31.8 1.051  9    29.37     34.1 30.208  <.0001 
 A     2      22.8 0.938 11    20.69     24.8 24.254  <.0001 
 B     2      45.5 0.938  9    43.38     47.6 48.509  <.0001 
 C     2      42.5 0.938  9    40.38     44.6 45.310  <.0001 
 A     3      14.5 2.268 11     9.51     19.5  6.394  0.0001 
 B     3      54.8 2.268  9    49.62     59.9 24.142  <.0001 
 C     3      56.8 2.268  9    51.62     61.9 25.024  <.0001 

Degrees-of-freedom method: containment 
Confidence level used: 0.95 

I am wondering if there is a way to compare the three groups at each time point based on the specified model without having to perform ANOVA at each time point. I'm not interested in pairwise comparisons as provided by the contrast method at this stage.

$\endgroup$
  • $\begingroup$ Are you sure you don’t want contrast(fit.emm.s, “consec”, by = “time”)? Or same with some other comparison method? I’m confused about wanting to compare groups without “omparing them. $\endgroup$ – Russ Lenth Mar 14 '19 at 0:14
  • 1
    $\begingroup$ Oh. Or maybe joint_tests(fit.emm.s, by = “time”) $\endgroup$ – Russ Lenth Mar 14 '19 at 0:16
  • $\begingroup$ joint_tests(fit.emm.s, by = “time”) works perfectly! Thank you @rvl $\endgroup$ – AMS Mar 14 '19 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.