From: Chris Knight <chris.knight_at_manchester.ac.uk>

Date: Tue 28 Jun 2005 - 02:33:44 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 28 02:42:57 2005

Date: Tue 28 Jun 2005 - 02:33:44 EST

Hi, I think this is a problem solved but I would be interested to know
if there is some good reason why SSlogis() behaves like this (apologies
if this has been noticed before- I'm not confident my archive searches
were effective):

I have been fitting large numbers of regressions using nls with a self-starting 3 parameter logistic model (SSlogis()). I got a series of unexpected errors of the sort:

model<-nls(y~SSlogis(x, Asym, xmid, scal)) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :

NA/NaN/Inf in foreign function call (arg 1)

Investigation seemed to suggest that this occurs for versions of y where the minimum value of y was precisely zero. and sure enough, the following produces that error:

x<-c(1,2,3,4,5,6,7)

y<-c(0,0,1,2,3,4,4)

model<-nls(y~SSlogis(x, Asym, xmid, scal))

whereas the following succeed:

model<-nls(y-0.01~SSlogis(x, Asym, xmid, scal)) model<-nls(y+0.01~SSlogis(x, Asym, xmid, scal))

I don't claim to understand the source code, but it does contain the lines

if (min(z) <= 0) {

z <- z - 1.05 * min(z)

* }
*

z <- z/(1.05 * max(z))

xy[["z"]] <- log(z/(1 - z))

aux <- coef(lm(x ~ z, xy))

Which would seem to explain it given that if the minimum of z is precisely zero it will remain the same after z <- z - 1.05 * min(z) so produce a -Inf for log(z/(1 - z)) going into the lm call and producing the error. Changing the beginning of the above to:

if (min(z) < 0) {

z <- z - 1.05 * min(z)

* }
*

if (min(z) == 0) {

z <- z + 0.01 * (max(z)-min(z))

* }
*

Seems to produce a function that does what I'm after, so I'm now happy, though I haven't gone through to check other self-starting functions.

Chris

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 28 02:42:57 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:33:03 EST
*