I am trying to fit a linear mixed model to my data in R using lme4, but I’m new to lmer / mixed models in general and have trouble with the output.
There are two issues:
- two-level factor variable has coefficients for both levels (instead of one dummy variable)
- input order changes anova output
Background info
There is a multivariate DV, but since I didn’t encounter a frequentist solution for multivariate LMM I am trying to follow this tutorial, which suggests a melted dataframe: https://mac-theobio.github.io/QMEE/lectures/MultivariateMixed.notes.html#a-trick-to-do-multivariate-mixed-models-using-lme4
My actual dataset is much longer, but I will try to provide a reproducible example that has the same variables and structure:
data <- data.frame(participants = as.factor(rep(c("AB12", "CD34", "EF56", "GH78", "IJ90"), each = 4*10)),
time = as.factor(rep(c("t1", "t2", "t3", "t4"), each = 10, n = 5)),
group = as.factor(rep(c("experimental", "control", "experimental", "control", "experimental"), each = 4*10)),
mass = as.factor(rep(c("23", "30", "37", "45", "53", "62", "70", "73", "89", "99"), n = 5)),
conc = abs(rnorm(200)))
There are ions (given in masses) recorded at four timepoints for the participants which are split into two groups. The question is whether the group, the timepoint, or a combination of these influences the concentration.
What I tried
I looked at the output of the following model:
lmm1 <- lmer(conc ~ 0 + mass:(group*time) + (1|participants), data = data)
summary(lmm1)
includes coefficients for both the experimental group and control group, but only for timepoints t2, t3, t4 see picture- I would have expected there only being one factor level, as a dummy variable.
Now, comparatively, for:
lmm2 <- lmer(conc ~ 0 + mass:(time*group) + (1|participants), data = data)
summary(lmm2)
… there are coefficients for t1, t2, t3, t4, but only one level of the group variable. Additionally, looking at the anova outputs see picture the F-value of the first fixed effect (be it group or time) is always much bigger.
These two issues (more dummy variables than expected, inconsistent anova results) persist when adding an intercept to the model also.
I believe that this is due to the interaction with the mass variable, but I don’t know how to proceed from here.
Questions
Any advice on why these issues come up and how to fix them, or suggestions for a different analysis approach?
The tutorial I used suggests using (mass-1|participants)
as a random effect, but this is too computationally intensive for my actual dataset.
I can add more information to clarify, but don’t want to overcomplicate the question.
Thanks in advance.
Leonie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.