[R] suggestions for nls error: false convergence

Christian Ritz ritz at bioassay.dk
Mon Dec 19 16:42:45 CET 2005

Hi Spencer.

When using 'optim' and the first try fails you could:

1) try some other methods: Nelder-Mead, BFGS, ...

2) increase the maximum number of iterations (argument maxit in the control list)

3) specify the argument parscale in the control list, in order to have all parameters of same magnitude during 
optimisation (this is useful if the parameters are suspected to be of different magnitudes).

Using the default method (Nelder-Mead) with maxit=1000 results in convergence, and essentially the same estimates are 
obtained if you use the method BFGS and set maxit=1000 and parscale=c(277, 100, 101, 10) (the initial starting values):

x <- 1:100

y <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

func2 <- function( par,y, x, rescale ) {
par <- rescale*par
a = par[1]
m = par[2]
n = par[3]
tau = par[4]
y. <- a * (1+m*exp(-x/tau)) / (1+n*exp(-x/tau))

est.no2 <- optim(c(277, 100, 101, 10), func2,  hessian=TRUE, y=y, x=x, rescale=1, control=list(maxit=1000))

est.no3 <- optim(c(277, 100, 101, 10), func2,  hessian=TRUE, method="BFGS", y=y, x=x, rescale=1, 
control=list(maxit=1000, parscale=c(277, 100, 101, 10)))

The optimisation in the package 'drc' uses BFGS with the maxit and parscale arguments specified.

Best wishes


More information about the R-help mailing list