# suggestions for nls error: false convergence

6 messages
Open this post in threaded view
|

## suggestions for nls error: false convergence

 Hi,   I'm trying to fit some data using a logistic function defined as y ~ a * (1+m*exp(-x/tau)) / (1+n*exp(-x/tau) My data is below: x <- 1:100 y <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,1,1,1,2,2,2,2,2,3,4,4,4,5, 5,5,5,6,6,6,6,6,8,8,9,9,10,13,14,16,19,21, 24,28,33,40,42,44,50,54,69,70,93,96,110,127,127,141,157,169, 178,187,206,216,227,236,238,244,246,250,255,255,257,260,261,262,266,268, 268,270,272,272,272,273,275,275,275,276) My first attempt was to use nls as below:     d <- data.frame(x=x, y=y)     model <- nls(y ~ a * (1+m*exp(-x/tau)) / (1+n*exp(-x/tau)), data=d,     start=list(a=277,m=100,n=101,tau=10),     algorithm='port', trace=TRUE,     control=nls.control(maxiter=5000, minFactor=1/2048)) Running the above code I get the following error message: Convergence failure: function evaluation limit reached without convergence (9). To investigate this further I used nlminb() to get a set of starting parameters. Thus I did: func <- function( par ) {     a = par[1]     m = par[2]     n = par[3]     tau = par[4]     a * (1+m*exp(-x/tau)) / (1+n*exp(-x/tau)) } est <- nlminb( c(277, 100,101, 10), objective=func, control=list(eval.max=400, iter.max=1000)) I get absolute convergence and a set of parameter values. Plugging these into the nls call and trying again still gives me  Convergence failure: function evaluation limit reached without convergence (9) I have tried a number of different starting values for the nls() call but I usually end up getting the following error: Convergence failure: false convergence (8) After reading the PORT library docs, I see that this error can mean 1) gradient is calculated incorrectly 2) stopping tolerances are too tight 3) gradient is discontinous near some iterate However, since nls() usually reports the above error after 30 to 40 iterations, the PORT docs suggest that it is not problem 1. I'm not sure about (3) - I have other data which are somewhat similar to the above data, but they lead to a straightforward fit. In the end I tried a different starting value and lowered the tolerances a little, and I got a valid fit My questions are: 1) Why would the parameters that lead nlminb() to converge to work in nls() (since I'm using the PORT algorithm in both cases)? 2) Is there a strategy to obtain starting values? In my case I know that a should be around 277, but for the others I'm not sure. 3) Is there a quick way to check whether the gradient is discontinous at a point, numerically (rather than calculating the analytical derivatives)? I did plot(diff(y)) and it certainly looks messy, but I also have other y vectors which look equally jagged (though the jaggedness occurs at lower x) Any suggestions would be appreciated. Thanks, ------------------------------------------------------------------- Rajarshi Guha <[hidden email]> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- After a number of decimal places, nobody gives a damn. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|

## Re: suggestions for nls error: false convergence

Open this post in threaded view
|

## Re: suggestions for nls error: false convergence

 In reply to this post by Rajarshi Guha Hi. An alternative is to use the package 'drc' on CRAN to fit your data! x <- 1:100 y <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,1,1,1,2,2,2,2,2,3,4,4,4,5, 5,5,5,6,6,6,6,6,8,8,9,9,10,13,14,16,19,21, 24,28,33,40,42,44,50,54,69,70,93,96,110,127,127,141,157,169, 178,187,206,216,227,236,238,244,246,250,255,255,257,260,261,262,266,268, 268,270,272,272,272,273,275,275,275,276) ## Defining the function (in a bit different notation) logi <- function(dose, parm){parm[, 1] * (1+parm[, 2]*exp(-dose/parm[, 3])) / (1+parm[, 4]*exp(-dose/parm[, 3]))} ## Fitting the function to the data (see ?multdrc for details) library(drc) model <- multdrc(y~x, fct = list(logi, NULL, c("a", "m", "tau", "n")), startVal=c(277, 100, 10, 101)) summary(model) plot(model, log="") Hope this helps? Christian ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|