I have a data set with 20 users who were exposed to three levels and two variants (except the low level was only exposed to one variant). There are two measurements for each combination. Below are example data for one user:
I know the two measurements are correlated for the same user, level and variant (not in this example data) so I'm imposing an AR1 structure. Below is the lme
model and estimation of interactions I'm interested in using the emmeans
package.
Two questions:
- Am I specifying the correlation structure correctly given I expect scores within user, level, and variant to be correlated?
- How does the
emmeans
function produce an estimate forlevel = low
andvariant = B
when that combination is not even in the data.
Full code for reproducibility:
library(tidyverse)
library(nlme)
library(emmeans)
NUM_USERS=20
save_list=list()
for(i in 1:NUM_USERS){
user=paste0("ID_",i)
save_list[[i]]=tibble(user,level=c(rep("high",4),rep('med',4),rep("low",2)),
variant=c(rep(c("A","B"),times=2,each=2),"A","A"),
score_num=rep(c("one","two"),5),score=rnorm(10,20,5))
}
a1 = bind_rows(save_list)
fit=lme(score~score_num*level+variant*score_num,random=~1|user,
correlation=corAR1(form=~1|user/level/variant),data=a1)
emmeans(fit,pairwise~score_num|variant*level)