3

I am working through Mixed Effects Models in S and S-Plus in R but some of the code does not produce the results in-text. In Chapter 6 one of the examples fails to converge with the code supplied.

The example is a non-linear mixed effects model performed on the Phenobarb dataset supplied with the nlme package.

library(nlme)

fm1Pheno.nlme <- nlme(model = conc ~ phenoModel(Subject, time, dose, lCl, lV),
                      data = Phenobarb,
                      fixed = lCl + lV ~ 1,
                      random = pdDiag(lCl + lV ~ 1),
                      start = c(-5,0),
                      na.action = na.pass, 
                      naPattern = ~ !is.na(conc))

fm1Pheno.nlme

This first model runs fine, but the second model, based on the first

fm2Pheno.nlme <- update( fm1Pheno.nlme,
                         fixed = list(lCl ~ Wt, lV ~ Wt + ApgarInd),
                         start = c(-5.0935, 0, 0.34259, 0, 0),
                         control = list(pnlsTol = 1e-6) )

..returns the error

Error in nlme.formula(model = conc ~ phenoModel(Subject, time, dose, lCl,  : 
  maximum number of iterations (maxIter = 50) reached without convergence

This second model apparently work in S but not in R. Can anyone suggest a solution? Is the error due to some difference between S and R?

llewmills
  • 2,959
  • 3
  • 31
  • 58
  • 1
    I've tried a few things (using `opt="nlm"` and/or `maxIter=2000` in `control()`, changing `pnlsTol` back to the default 1e-3), but no luck so far. – Ben Bolker Oct 19 '18 at 01:09
  • Thanks for trying @Ben Bolker. Not the end of the world. Almost everything else in the book translates just fine. – llewmills Oct 19 '18 at 07:19

1 Answers1

1

We may deal with this by adjusting the pnlsTol parameter:

fm2Pheno.nlme <- update(fm1Pheno.nlme,
                        fixed = list(lCl ~ Wt, lV ~ Wt + ApgarInd),
                        start = c(-5.0935, 0, 0.34259, 0, 0),
                        control = list(pnlsTol = 0.019))

To see why it makes sense, try adding msVerbose = TRUE to control and see how the values keep jumping around if the tolerance parameter is low. Increasing pnlsTol is a pretty common way to deal with such convergence issues, see, e.g.,

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102