[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,
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)
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))
sum((y-y.)2)
}
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
Christian
More information about the R-help
mailing list