# Mixed effects model with random and nested effects in lmer

I want to run a linear mixed effects model with nested and random effects using lmer in R, but continue getting errors. Two questions: what is causing the errors and how can I fix my model to run the appropriate analyses? Thanks so much!

Experimental design: Four sites- each site has 2 plant species and 3 accessions for each plant species (6 accessions total). At each site, there are two treatments: plants given nitrogen enriched fertilizer and plants given nitrogen free fertilizer. I collected data on plant growth and root traits and log-transformed variables as needed. I also set Accession (coded 1 - 6), Site (coded 1 - 4), and SoilN treatment (coded 1 and 2) as factors. All response variables are continuous.

Data structure:

Model: I want to test the effects of treatment (SoilN), Species, and Accession on plant growth and root traits. I have been running two models- one for species and one for accession. I would like to test an interaction between species or accession and soil N, include site as a random effect, and nest accession within species. I wrote the following models:

lf  <- lmer(LogLeaf ~ SoilN * Species   + (1|Species/Accession) + (1|Site), data=a)
lf2 <- lmer(LogLeaf ~ SoilN * Accession + (1|Species/Accession) + (1|Site), data=a)


Output:

For the accession model (lf2), I get the following warnings:

> lf2 <- lmer(LogLeaf ~ SoilN * Accession + (1|Species/Accession) +
(1|Site), data = a)
Warning messages:
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
Model failed to converge: degenerate  Hessian with 1 negative eigenvalues

> summary(lf2)
Error in calculation of the Satterthwaite's approximation. The output of
lme4 package is returned
summary from lme4 is returned
some computational error has occurred in lmerTest

> anova(lf2)
Error in calculation of the Satterthwaite's approximation.
The output of lme4 package is returned
anova from lme4 is returned
some computational error has occurred in lmerTest
Analysis of Variance Table
Df  Sum Sq Mean Sq  F value
SoilN            1 13.4357 13.4357 121.8414
Accession        5  0.3728  0.0746   0.6761
SoilN:Accession  5  0.8892  0.1778   1.6127
Warning messages:
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
Model failed to converge: degenerate  Hessian with 1 negative eigenvalues


Other notes:

1. The model runs if I nest Accession within Species within Site, although I'm not sure that's a correct way to analyze the data.
2. It also runs if I don't nest Accession within Species, but still include Site and Accession as random effects.
3. I do have some zeros in my data set because some of the plant died. I added data to determine whether the zeros were causing the issue, but continued to get errors.
• You cannot have Species as both a fixed effect and a random effect. Try LogLeaf ~ SoilN * Species + (1|Site/Accession). – amoeba says Reinstate Monica May 26 '17 at 15:14
• But I also don't quite understand what "Accession" is. You said you want to test it -- so it should be a fixed factor probably, not a random one? What does "Accession" mean? Does it have 3 meaningful levels or 6? – amoeba says Reinstate Monica May 26 '17 at 15:16
• Wait, I googled it and it seems that "accession" is something like a subspecies. Then you can have LogLeaf ~ SoilN * Species + (1|Site) or LogLeaf ~ SoilN * Accession + (1|Site). Only Site is random. – amoeba says Reinstate Monica May 26 '17 at 15:20
• Working on this currently. First, just making everything is coded directly. A few questions: What are "accessions"? Are the same 2 species found at every single plot? Are the "accessions" within species unique to that species? – Mark White May 26 '17 at 15:31
• @amoeba it isn't the case that a fixed effect can't also be random. An effect can be split into the fixed part (i.e., the average coefficient) and the random part (i.e., the variance around that average coefficient). The problem here is that OP is using a cluster variable also as an independent variable. We also want to make sure that the effect of accession and treatment differ by site, so I would specify this model: LogLeaf ~ SoilN * Accession + (1 + SoilN + Accession|Site) – Mark White May 26 '17 at 15:35