I was wondering what is the most elegant way to investigate group differences in change scores? Here's what I'm trying to do. Imagine there are three groups (a,b,c) where each participant is measured on some dependent variable DV at two points in time t1 and t2. So I have within-subjects factor time (t1, t2) and between-subjects factor group (a,b,c). Imagine I find an interaction, and I want to know which groups differ in their change scores (t2-t1)?
Here's some sample data in R:
library('tidyr')
library('dplyr')
set.seed(878273)
n <- 5
dat <- rbind(
data.frame(group='a',t1=rnorm(n,10,1),t2=rnorm(n,9,1)),
data.frame(group='b',t1=rnorm(n,10,1),t2=rnorm(n,9,1)),
data.frame(group='c',t1=rnorm(n,10,1),t2=rnorm(n,6,1))
) %>%
mutate(id=1:(3*n)) %>%
pivot_longer(cols=c(t1,t2),names_to='time',values_to='dv')
a <- afex::aov_ez(data=dat,id='id',dv='dv',within='time',between='group')
afex::nice(a)
So the interaction time x group tells me that the time difference varies according to group. But what if I want to know which pairs of groups show different change scores?
I know how to unpack the ANOVA result into simple effects (i.e. effects of time within group or the other way around), but I'm lacking a straightforward way to compare which groups' change scores are different. What I would currently do is create a completely new ANOVA where I enter just the change scores as DV and have a single factor group.
However I was wondering if there is a way to do this directly from the repeated-measures ANOVA.
Thanks for reading this far and for any thoughts you are willing to share!
In case this is relevant, here below is my (I think clunky) way. What I think is clunky is that I fit an entirely new ANOVA instead of using the original one from above and needing to go through the wider data format.
wide <-
dat %>%
pivot_wider(id_cols=c(id,group),names_from='time',values_from='dv') %>%
mutate(tdiff=t2-t1)
a <- afex::aov_ez(data=wide,dv='tdiff',id='id',between='group')
afex::nice(a)
pairs(emmeans::emmeans(a,~group))
acould be one of two models. This creates confusion. – Russ Lenth Apr 02 '21 at 00:54a:EMM = emmeans(a , ~ time * group); contrast(EMM, interaction = c("consec", "pairwise")). This does pairwise comparisons of the changes over the two consecutive times. – Russ Lenth Apr 02 '21 at 00:58model = "mult"to the call forEMMin my last comment, so as to use the multivariate model instead of the univariatebone. – Russ Lenth Apr 02 '21 at 01:01