2

I have been working through Mixed-Effects Models in S and S-Plus by Pinhiero and Bates and am discovering a lot of problems making the models in the book work.

The latest is this, using a constant plus power function to model heteroscedastic within-group error in the Theo dataset, (p.393). The error comes at the end of a model-building exercise. The first three models work in R but the last does not

library(nlme)
fm1Theo.nlme <- nlme( model = conc ~ SSfol(Dose, Time, lKe, lKa, lCl), 
                      data = Theoph,
                      fixed = lKe + lKa + lCl ~ 1,
                      random = lKe + lKa + lCl ~ 1)
fm2Theo.nlme <- update(fm1Theo.nlme, random = pdDiag(list(lKe ~ 1, lKa ~ 1, lCl ~ 1)))
fm3Theo.nlme <- update(fm2Theo.nlme, random = pdDiag(list(lKa ~ 1, lCl ~ 1)))
fm4Theo.nlme <- update(fm3Theo.nlme, weights = varConstPower(power=0.1))

...yielding the error message

Error in eigen(val, only.values = TRUE) : 
  infinite or missing values in 'x'
In addition: Warning messages:
1: In nlminb(c(coef(nlmeSt)), function(nlmePars) -logLik(nlmeSt, nlmePars),  :
  NA/NaN function evaluation
2: In nlminb(c(coef(nlmeSt)), function(nlmePars) -logLik(nlmeSt, nlmePars),  :
  NA/NaN function evaluation
3: In nlminb(c(coef(nlmeSt)), function(nlmePars) -logLik(nlmeSt, nlmePars),  :
  NA/NaN function evaluation
4: In nlminb(c(coef(nlmeSt)), function(nlmePars) -logLik(nlmeSt, nlmePars),  :
  NA/NaN function evaluation

Can anyone shed some light on this message, and how I might make it work?

llewmills
  • 2,959
  • 3
  • 31
  • 58

1 Answers1

1

It looks like something that is supposed to be positive became negative during the optimization: functions such as sqrt and log when applied to negative numbers return NaN. Without digging deeper I tried to look into the variance model, which is supposed to return positive values. Setting higher initial value for const solves the issue:

fm4Theo.nlme <- update(fm3Theo.nlme, weights = varConstPower(const = 0.5, power = 0.1))
Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
  • thank you once again @Julius Vainora. It seems like there is much more tweaking involved in nonlinear models than in linear. Where did you learn all this? by the way I have posted another model from the same book just now that also failed to converge. – llewmills Dec 26 '18 at 23:00
  • @llewmills, nowhere specific really, my background is econometrics/stats, so I guess it's a little of everything. Certainly there is often quite a bit of trial and error. In your case, `fm4Theo.nlme` in comparison to `fm3Theo.nlme` only adds this variance model (hence the main suspect), which has parameters and has to return positive values.. Then I found another parameter in `varConstPower`.. So, one thing led to another. – Julius Vainora Dec 26 '18 at 23:53
  • Well hopefully your solutions will help other people working through the book in R – llewmills Dec 26 '18 at 23:57