1

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:

data.structure

I would really appreciate if someone can tell me what's wrong with the model.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
candle786
  • 41
  • 7
  • can you show us the results of `str(LME)` instead of the screenshot? – Ben Bolker Apr 02 '18 at 22:49
  • It would also be good to see `with(LME,table(Place,Laryngeal))` and `with(LME,table(Place,Laryngeal,Sp))` – Ben Bolker Apr 02 '18 at 22:56
  • Thanks Ben! Here is some more information about the data: str(LME) 'data.frame': 599 obs. of 5 variables: $ Sp : Factor w/ 5 levels $ Place : Factor w/ 5 levels $ Laryngeal: Factor w/ 5 levels $ Rep : Factor w/ 5 levels $ VOT : int 9 15 10 11 11 str(LME,table(Place,Laryngeal)) 'data.frame': 599 obs. of 5 variables: Error in table(Place, Laryngeal) : object 'Place' not found – candle786 Apr 04 '18 at 03:09
  • And also with Sp: str(LME,table(Place,Laryngeal,Sp)) 'data.frame': 599 obs. of 5 variables: Error in table(Place, Laryngeal, Sp) : object 'Place' not found – candle786 Apr 04 '18 at 03:15
  • I am not sure why it says the object 'Place' not found. This error is not only restricted to this data. I get the same error if I run str(LME,table(Place,Laryngeal,Sp)) on a different data. – candle786 Apr 04 '18 at 03:32
  • you need the `with(...)` part ... – Ben Bolker Apr 04 '18 at 13:24

1 Answers1

2

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.

  1. Starting with a large, fully crossed data set:
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
  1. Reducing the data set (to drop one combination of levels) causes the "fixed-effect model matrix is rank deficient" message, but everything works otherwise:
dd_missing <- subset(dd,!(Place=="2" & Laryngeal=="2"))
m2 <- update(m1, data=dd_missing)
emmeans(m2,pairwise~Laryngeal|Place) ## lsmeans() also works
  1. If we randomly subsample a small fraction of the data we can get the error, although I couldn't do it with my data without also telling 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
  1. Finally, simplifying the model makes things a little better:
m4 <- update(m3, . ~ Place*Laryngeal + (1+Place|Sp))
emmeans(m4,pairwise~Laryngeal|Place)
lsmeans::lsmeans(m4,pairwise~Laryngeal|Place)
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • emmeans solved the issue! I get the error after running your m1 but emmeans still handles the error and produces the pairwise comparisons. I think there is something wrong with the factor of Place in my data. There are five levels of Place, and each level of Place has five levels of Laryngeal, but level 2 of the Place has only four levels of Laryngeal. So my data are actually imbalanced. – candle786 Apr 04 '18 at 03:25