Skip to content

nls works but not gnls

5 messages · Bill Simpson, Antonio Olinto, Douglas Bates +1 more

#
This works fine:
fit42<-nls(Vfs~SSlogis(Months,Asym.Int+Asym.Group*Groupdum,xmid,scal),
data=df,
start=c(Asym.Int=22,Asym.Group=5,xmid=2,scal=6),
na.action=na.omit)

But this, identical except using gnls, doesn't converge:
fit43<-gnls(Vfs~SSlogis(Months,Asym.Int+Asym.Group*Groupdum,xmid,scal),
data=df,
start=c(Asym.Int=22,Asym.Group=5,xmid=2,scal=6),
na.action=na.omit)

Error in gnls(Vfs ~ SSlogis(Months, Asym.Int + Asym.Group * Groupdum,  : 
        Step halving factor reduced below minimum in NLS step
I tried adding
,control=list(minScale=.0001))
But get the same lack-of-convergence message. Any ideas on how to fix this
and why gnls is finickier than nls?

I use a good starting point  about equal to the final param values nls
gives. The logistic function does indeed give a decent fit to the data.

I need gnls instead of nls because I eventually want to add
corr=corCAR1(form=~Months|Subject)

Suppose I have highly autocorrelated errors but ignore
that (as in nls fit). How much would you trust the nls estimates of the
fitted parameters? What does taking account of the autocorr buy me?
BTW I already tried nlme and had similar problems so I wound up fitting
lme quadratic model. I think I would be distorting reality less by
ignoring the autocorr &/or random effects (nls fit) than I am by
paying attention to autocorr & random effects but fitting a polynomial
that bears no relation to the mechanism generating the data (it clearly
will be a function that approaches an asymptote). The gnls fit would be
good because it pays attention to autocorr errors and allows me to fit
realistic nonlinear curve (although it ignores random effects).

Thanks for any help!

Bill Simpson

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hello,

I had a similar problem with using gnls with a three-column data.frame like
this (Li is a
back-calculated length at age for each fish):

 Fish      Age            Li
 1          1            110.17
 1          2            143.61
 1          3            180.47
 1          4            218.97
 1          5            257.12
 1          6            299.22
 1          7            328.16
 2          1            100.36
 2          2            131.09
 2          3            171.42
 2          4            213.08
 ..

Writing:

 vbmale <- gnls(Li ~ Linf*(1-exp(-K*(Age-t0))), data=male, params= Linf +K +
t0 ~ 1, start=list(Linf=1000,K=0.1,t0=0), control = list(returnObject = T),
corr = corAR1(form=~Age|Fish))

I got:

 Error in [<-.factor(*tmp*, , value = grpShrunk[revOrderShrunk]) : Argument
 "i" is missing, with no default
 In addition: Warning message:
 Step halving factor reduced below minimum in NLS step in: gnls(Li ~ Linf
 *(1 - exp(-K * (Age - t0))), data = male, params = Linf +

Using the same data in S-Plus, a colleague of mine had the output:

 vbmale
Generalized nonlinear least squares fit
   Model: Li ~ Linf * (1 - exp( - K * (Age - t0)))
   Data: male
   Log-likelihood: -7515.22

 Coefficients:
     Linf          K                    t0
 1412.352      0.04403359   -0.6916286

 Correlation Structure: AR(1)
  Formula:  ~ Age| Fish
  Parameter estimate(s):
        Phi
  0.9660297
 Degrees of freedom: 1803 total; 1800 residual
 Residual standard error: 54.37347

Is there a bug? I would like to hear comments too.

Ant?nio Olinto
Fisheries Researcher
Instituto de Pesca (Fisheries Institute)
Sao Paulo - BRAZIL
aolinto at bignet.com.br
www.institutopesca.sp.gov.br
-.-.-
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
"Antonio Olinto" <aolinto at bignet.com.br> writes:
Probably - but I just don't have time to debug it right now.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Thanks for your reply Dr. Bates.

Please let me know when this function is debuged.

Best regards,

Ant?nio Olinto
Fisheries Researcher
Instituto de Pesca (Fisheries Institute)
Sao Paulo - BRAZIL
aolinto at bignet.com.br
www.institutopesca.sp.gov.br

----- Original Message -----
From: "Douglas Bates" <bates at stat.wisc.edu>
To: "Antonio Olinto" <aolinto at bignet.com.br>
Cc: <r-help at stat.math.ethz.ch>
Sent: Friday, June 01, 2001 6:04 PM
Subject: Re: [R] nls works but not gnls
...
-.-.-
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
"Antonio Olinto" <aolinto at bignet.com.br> writes:
...
You'd make it much easier by providing an example that can be used to
reproduce the behaviour. Or even debug it some of the way yourself.

Remember that free software is a collective endeavour: If everyone
contributes a little, everyone receives a lot.