I have two fixed effects in a nonlinear mixed effect model. One is nested in the other, as the case here: "Specie" is nested in 'category'.

exp_decay <- function(a, b, x){

specie <- rep(c("A", "B", "C", "D", "E", "F"), each=6)
line <- paste(specie, rep(c(1,1,1,2,2,2), 6), sep="-")
category <- rep(c("Big", "Small"), each=18)
x <- rnorm(36, 0, 1)
y <- exp_decay(1, 0.2, x)
da <- data.frame(y,x,specie=as.factor(specie), category=as.factor(category), line=as.factor(line) )

a.nlme <- nlme(y~exp_decay(a, b, x), 
                fixed=list(a~category+category:specie, b~category+category:specie), 
                random = list(line=pdDiag(a+b~1)), 
                start = c(1,rep(0,11),0.2,rep(0,11)),
                control = nlmeControl(pnlsTol = 0.001, msVerbose = TRUE))

But the nlme failed to run. It gives the error: "Error in MEEM(object, conLin, control$niterEM) : Singularity in backsolve at level 0, block 1".

I think the singularity comes from the nested design. Because "Specie" is nested in "category", 'category:specie' is not full rank. If we use "lm" to run a linear model, it will just give "NA" to the non-existed combinations of "category" and "specie".

So, how to deal with this nested fixed effect in 'nlme'?

  • $\begingroup$ Does it run if you convert it to a single variable, say G=interaction(category, specie)? $\endgroup$ – Aaron - Reinstate Monica Oct 4 at 21:07
  • $\begingroup$ It's actually only nested conceptually, not in the coding, so you don't need the interaction I asked about; instead, does it run with just specie? That is, specie is already unique for each category, so category:specie and just specie have the same information. $\endgroup$ – Aaron - Reinstate Monica Oct 4 at 21:22
  • $\begingroup$ Hi Aaron, it does run with just specie. I hope to get the overall category effect. It seems that nlme cannot deal with singular fixed effect matrix. So, I did run the model with just specie effect and conduct the F-test for category by manual defining the contrasts. $\endgroup$ – kickshark Oct 9 at 17:22
  • $\begingroup$ Yes, that's the thing to do. I don't think lm would deal with this either, that is, it'll fit but not do the contrasts you want unless you change how the contrasts are defined. $\endgroup$ – Aaron - Reinstate Monica Oct 9 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.