I'm running an LME model with the lme4
package and then following up with pairwise comparisons using the lsmeans
package.
Here is my code:
lmer_full <- lmer (VOT ~ Place*Laryngeal + (1+Place+Laryngeal|Sp),
data = LME,control=lmerControl(optCtrl=list(maxfun=50000)))
lsmeans (lmer_full, pairwise~Laryngeal|Place)
However, I get the following error message after running the lmer
:
fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
Warning messages:
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : unable to evaluate scaled gradient
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge: degenerate Hessian with 1 negative eigenvalues
Then another error after running lsmeans
:
Error in
base::chol2inv(x, ...) : 'a'
must be a numeric matrix
Here is the structure of my data:
I would really appreciate if someone can tell me what's wrong with the model.
tl;dr I can't exactly reproduce your error, but I can come pretty close. Your data set is most likely too small/noisy for the model you want to fit (you're getting a singular model); using the emmeans
package (which is the successor to lsmeans
) will help a bit, but you should probably simplify your model.
library(lme4)
library(emmeans)
dd <- expand.grid(Place=factor(1:3),Laryngeal=factor(1:3),
Sp=factor(1:10),rep=6)
set.seed(101)
dd$y <- rnorm(nrow(dd))
This works fine:
m1 <- lmer(y~Place*Laryngeal + (1+Place+Laryngeal|Sp), dd)
emmeans(m1,pairwise~Laryngeal|Place) ## lsmeans() also works
dd_missing <- subset(dd,!(Place=="2" & Laryngeal=="2"))
m2 <- update(m1, data=dd_missing)
emmeans(m2,pairwise~Laryngeal|Place) ## lsmeans() also works
lmer
to ignore some other issues with the data set (not enough samples for the number of random effects specified):set.seed(102)
dd_small <- dd_missing[sample(1:nrow(dd_missing),
size=round(nrow(dd_missing)*0.3),
replace=FALSE),]
m3 <- update(m1, data=dd_small,
control=lmerControl(check.nobs.vs.nlev="ignore",
check.nobs.vs.nRE="ignore",
optCtrl=list(maxfun=50000)))
emmeans(m3,pairwise~Laryngeal|Place) ## works (sort of)
lsmeans::lsmeans(m3,pairwise~Laryngeal|Place) ## fails
m4 <- update(m3, . ~ Place*Laryngeal + (1+Place|Sp))
emmeans(m4,pairwise~Laryngeal|Place)
lsmeans::lsmeans(m4,pairwise~Laryngeal|Place)