[Rd] predict.gnls seems to break when 'newdata' specified (PR#10364)

jenny at stat.ubc.ca jenny at stat.ubc.ca
Mon Oct 22 20:00:15 CEST 2007


Full_Name: Jennifer Bryan
Version: 2.5.1
OS: Mac OS 10.4.10
Submission from: (NULL) (142.103.104.81)


The predict method for gnls seems to break when I provide 'newdata'.  It seems
to be the code that checks that the factors in newdata have the same contrasts
as the data provided for the original fit.  I illustrate below with an example
from Pinheiro and Bates.  I can't even use predict on the original data.frame
when I provide the original data as newdata.

## copied verbatim from Pinheiro & Bates 8.3.3
fm1Dial.gnls <-
  gnls(rate ~ SSasympOff(pressure, Asym, lrc, c0),
       data = Dialyzer, params = list(Asym + lrc ~ QB, c0 ~ 1),
       start = c(53.6, 8.6, 0.51, -0.26, 0.225))
## differs from P & B only due to different default contrasts
Dialyzer$QBcontr <- ifelse(Dialyzer$QB == 200, 0, 1)
fm1Dial.nls <-
  nls(rate ~ SSasympOff(pressure, Asym.Int + Asym.QB * QBcontr,
                        lrc.Int + lrc.QB * QBcontr, c0), data =
      Dialyzer, start = c(Asym.Int = 53.6, Asym.QB = 17,
                  lrc.Int = 0.51, lrc.QB = -0.5, c0 = 0.225))
## I get the same results from the above fits, they differ from those
## in the book due to different contrasts
predict(fm1Dial.gnls)                     # works
predict(fm1Dial.gnls, newdata = Dialyzer) # fails, factor levels complaint
predict(fm1Dial.nls, newdata = Dialyzer)  # works



More information about the R-devel mailing list