I have a data with 3 fixed effect factors G (two levels g1 and g2), V (two levels v1 and v2) and C (c1,c2,c3,c4,c5,c6,c7), and a random effect ID. I need to fit a linear mixed model or robust lmm with the 3-way interaction of the fixed effects and the random intercept (1|ID)
. The model returns a warning:
fixed-effect model matrix is rank deficient so dropping 6 columns / coefficients.
I already checked my data and understand that the issue comes from the fact that no data has been observed for the combination of v2c5, v2c6, and v2c7. I also understand I am unable to test the 6 associated fixed effects due to this.
However, my goal is to test some contrasts that don't involve the unobserved v2c5, v2c6, and v2c7. For example, I will test the difference between g1 and g2 in v1c5 or the difference in v2c2. But when using:
emmeans(model, ~G|V*C)
it returns:
Error in (function (object, at, cov.reduce = mean, cov.keep = get_emm_option("cov.keep"),: Something went wrong:
Non-conformable elements in reference grid.
Updates
Thank you all for the suggestions and response @LTyrone and @qdread. Below, I generated hypothetical data and provided the sample code. Thank you in advance for further help.
set.seed(123)
G_levels <- c("g1", "g2") # Two levels for G
V_levels <- c("v1", "v2") # Two levels for V
C_levels <- c("c1", "c2", "c3", "c4", "c5", "c6", "c7")
ID_levels <- paste0("ID", 1:12)
df <- as_tibble(expand.grid(G = G_levels, V = V_levels, C = C_levels, ID = ID_levels))
df$response <- rnorm(nrow(df), mean = 50, sd = 10)
df <- df[!(df$V == "v2" & df$C %in% c("c5", "c6", "c7")), ]
df$G <- factor(df$G, levels = G_levels) %>%
relevel(ref = "g1")
df$V <- factor(df$V, levels = V_levels) %>%
relevel(ref = "v1")
df$C <- factor(df$C, levels = C_levels) %>%
relevel(ref = "c1")
df$ID <- factor(df$ID, levels = ID_levels) %>%
relevel(ref = "ID1")
library(lmerTest)
library(robustlmm)
library(emmeans)
mymodel1<-lmer(response~ G*V*C+(1|ID),data=df)
mymodel2<-rlmer(response~ G*V*C+(1|ID),data=df)
Thanks to @qdread, I am able to get the contrast tests using lmer()
model with emmeans()
as below.
emm <- emmeans(mymodel1, ~ G | V*C, at = list(V =c('v1','v2'), C =c('c1','c2','c5')))
pairs(emm,by = c("V", "C"))
But for the robust model as below,
emm <- emmeans(mymodel2, ~ G | V*C, at = list(V =c('v1','v2'), C =c('c1','c2','c5')))
pairs(emm,by = c("V", "C"))
it still returns:
Error in (function (object, at, cov.reduce = mean, cov.keep = get_emm_option("cov.keep"), : Something went wrong: Non-conformable elements in reference grid.