[R] nls, reach limit bounds
spencerg
spencer.graves at prodsyse.com
Sun Jul 12 03:49:39 CEST 2009
Have you plotted the data? There are two standard sources of
non-convergence problems like this: First, there may not be enough
information in your data to estimate all four parameters. Second, if
that's not the case, then your starting values are not appropriate.
I routinely use "optim" or "nlminb" to find a sensible solution,
because these general purpose optimizers are more likely to converge
than "nls". To do this, I write a function with a name like
"SSElogistic" to compute the sum of squares of residuals for your
model. I like to use "optim" with "hessian=TRUE". Then I compute
"eigen(fit$hessian, symmetric=TRUE)", with "fit" = the object returned
by "optim". If the smallest eigenvalue is negative, it says that optim
found a saddle point. If the smallest eigenvalue is less than, e.g.,
1e-8 times the largest, it says that the smallest eigenvector is very
poorly estimated. Round those numbers off grossly to 1 significant
digit, and they will likely suggest which parameter you can fix and drop
from the model.
Hope this helps.
Spencer Graves
UyenThao Nguyen wrote:
> Hi,
>
> I am trying to fit a 4p logistic to this data, using nls function. The function didn't freely converge; however, it converged if I put a lower and an upper bound (in algorithm port). Also, the b1.A parameter always takes value of the upper bound, which is very strange. Has anyone experienced about non-convergent of nls and how to deal with this kind of problem?
>
> Thank you very much.
>
>
>
> ########################################################################3
> y x
> 1 0.8924619 -0.31875876
> 2 1.1814749 -0.21467016
> 3 1.6148266 0.06069784
> 4 2.2091363 0.54032947
> 5 2.7019079 1.04921802
> 6 3.0679585 1.60745502
> 9 0.9436973 -0.31875876
> 10 1.2201133 -0.21467016
> 11 1.6470043 0.06069784
> 12 2.2090048 0.54032947
> 13 2.6864857 1.04921802
> 14 3.0673523 1.60745502
>
> new.cont=nls.control(maxiter = 10000, tol = 1e-05, minFactor = 1e-08,
> printEval = FALSE, warnOnly = FALSE)
>
>
> b0.A=.9*min(DAT$y)
> b1.A=1.1*max(DAT$y)-b0.A
> b2.A=-1*mean(DAT$x)
> b3.A=1
>
>
> b0.A
> b1.A
> b2.A
> b3.A
>
> nls.mdl.A=nls(y~b0 + b1/(1+exp(-b2-b3*x)),data=DAT,start = list(b0=b0.A, b1=b1.A, b2=b2.A, b3=b3.A), lower=-10, upper=10, algorithm="port",trace=T,control=new.cont)
>
> ##################################
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
More information about the R-help
mailing list