1

I am having trouble getting the pairs() function to work in nlme. Take this example from Pinhiero and Bates Mixed-Effects Models in S and S-Plus.

The model itself runs just fine

fm1Theo.lis <- nlsList(conc ~ SSfol(Dose, Time, lKe, lKa, lCl), data = Theoph)

But the pairs plot...

pairs(fm1Theo.lis, id = 0.1)

...returns this error

Error in as.data.frame.default(x) : 
  cannot coerce class "c("nlsList", "lmList")" to a data.frame

I also tried

pairs(fm1Theo.lis, ~ ranef(., level = 2), id = 0.1)

But get the same error. Any ideas?

llewmills
  • 2,959
  • 3
  • 31
  • 58
  • 3
    I can't reproduce the error. What you get is the same as running `pairs.default(fm1Theo.lis, id = 0.1)`, which would suggest that `nlme` isn't loaded, but then it's not clear how `fm1Theo.lis` works. What about `nlme:::pairs.lmList(fm1Theo.lis, id = 0.1)`? – Julius Vainora Jan 02 '19 at 21:31
  • Thanks @Julius Vainora. I think it was some sort of `nlme` loading error, because all the pairs plots in my scripts worked before. I should have remembered the advice from Roy in the IT crowd and turned my computer (or RStudio in this case) off and on again. Because now it is working. Still don't know what happened but it seems to be working now, the `pairs` plots are running. – llewmills Jan 02 '19 at 21:44
  • While the fix is clear, in my answer I tried to explain the process of how one can resolve this kind of problems. – Julius Vainora Jan 02 '19 at 21:52

1 Answers1

1

Here's how one may think in this case. The error

Error in as.data.frame.default(x) : 
  cannot coerce class ‘c("nlsList", "lmList")’ to a data.frame

says that some object of class c("nlsList", "lmList") is being coerced to a data frame. Now since fm1Theo.lis is the result of using nlsList, it seems that the object in the error is indeed nlsList. That means that pairs does not know what to do with objects of such class. To confirm this, we can run

pairs.default(fm1Theo.lis, id = 0.1)

which is what is going to happen when no specific method for fm1Theo.lis is found. Indeed the error is the same. In one way or another confirming that nlsList and comes from nlme, it becomes clear that the issue is with loading the nlme package. Loading it or restarting the session then is almost surely going to help.

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