[R] error using nls with logistic derivative

Gabor Grothendieck ggrothendieck at gmail.com
Tue Apr 17 12:48:40 CEST 2012


On Tue, Apr 17, 2012 at 12:23 AM, Francisco Mora Ardila
<fmora at oikos.unam.mx> wrote:
> Hi
>
> I´m trying to fit a nonlinear model to a derivative of the logistic function
>
> y = a/(1+exp((b-x)/c)) (this is the parametrization for the SSlogis function with nls)
>
> The derivative calculated with D function is:
>
>> logis<- expression(a/(1+exp((b-x)/c)))
>> D(logis, "x")
> a * (exp((b - x)/c) * (1/c))/(1 + exp((b - x)/c))^2
>
> So I enter this expression in the nls function:
>
> ratelogis <- nls(Y ~ a*(exp((b-X)/c)*(1/c))/(1 + exp((b-X)/c))^2,
> start=list(a = 21.16322, b = 8.83669, c = 2.957765),
> )
>
> The data is:
>
>> Y
>  [1]  5.5199668  1.5234525  3.3557000  6.7211704  7.4237955  1.9703127
>  [7]  4.3939336 -1.4380091  3.2650180  3.5760906  0.2947972  1.0569417
>> X
>  [1]   1   0   0   4   3   5  12  10  12 100 100 100
>
> The problem is that I got the next error:
>
> Error en nls(Y ~ a * (exp((b - X)/c) * (1/c))/(1 + exp((b - X)/c))^2,  :
>  step factor 0.000488281 reduced below 'minFactor' of 0.000976563
>

Try alg = "plinear" noting that we must drop the linear coefficient a
from the formula and starting values and .lin in the output represents
 a:

ratelogis <- nls(Y ~ (exp((b-X)/c)*(1/c))/(1 + exp((b-X)/c))^2,
  start=list(b = 8.83669, c = 2.957765), alg = "plinear"
)

ratelogis
plot(X,Y)
o <- order(X)
lines(X[o], fitted(ratelogis)[o], col = "red")

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list