I have a model with factors of the form mod <- lmer(value ~ time + study + (1|participant))
where I am not really interested in the study coefficient but want to keep it as fixed for a various reasons. But I want to make predictions from mod
without the effect of the study coefficient. I have sum-coded the study factor so that I really just need a way to remove the study coefficient.
It seems a bit cumbersome to calculate the predictions from the coefficients manually. I guess one alternative is to replace the study coefficient with zeros (Replace lmer coefficients in R)
Any better ideas?
A minimal example:
library("lme4")
df <- data.frame(
participant = as.factor(c(1,1,1,2,2,2,3,3,3,4,4,4)),
time = as.factor(c(1,2,3,1,2,3,1,2,3,1,2,3)),
study = as.factor(c("A", "A", "A", "B", "B", "B", "A","A", "A", "C", "C", "C")),
value = c(1,2,3,3,4,1,3,5,3,1,7,2)
)
contrasts(df$study) = contr.sum(length(unique(df$study)))
mod <- lmer(value ~ time + study + (1|participant), data = df)
predict(mod, newdata = data.frame(time = as.factor(c(1,2,3))), re.form=NA)