# [R] nls works but not gnls

Bill Simpson wsi at gcal.ac.uk
Fri Jun 1 11:14:24 CEST 2001

```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
,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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```