[R] Finding starting values for the parameters using nls() or nls2()
Pinglei Gao
gaopinglei at 163.com
Sun Oct 9 13:21:16 CEST 2016
Hi,
I have some data that i'm trying to fit a double exponential model: data.
Frame (Area=c (521.5, 689.78, 1284.71, 2018.8, 2560.46, 524.91, 989.05,
1646.32, 2239.65, 2972.96, 478.54, 875.52, 1432.5, 2144.74, 2629.2),
Retention=c (95.3, 87.18, 44.94, 26.36, 18.12, 84.68, 37.24, 33.04, 23.46,
9.72, 97.92, 71.44, 44.52, 24.44, 15.26) ) and the formula of the double
exponential is: exp (b0*exp (b1*x^th)).
I failed to guess the initial parameter values and then I learned a measure
to find starting values from Nonlinear Regression with R (pp. 25-27):
> cl<-data.frame(Area =c(521.5, 689.78, 1284.71, 2018.8, 2560.46, 524.91,
989.05, 1646.32, 2239.65, 2972.96, 478.54, 875.52, 1432.5, 2144.74, 2629.2),
+ Retention =c(95.3, 87.18, 44.94, 26.36, 18.12, 84.68, 37.24, 33.04, 23.46,
9.72, 97.92, 71.44, 44.52, 24.44, 15.26) )
> expFct <- function(Area, b0, b1,th) {exp(b0*exp(b1*Area^th))}
> grid.Disperse <- expand.grid(list(b0 = seq(0.01,4, by = 0.01), th =
c(0.02),b1 = seq(0.01, 4, by = 0.01)))
> Disperse.m2a <- nls2(Retention ~expFct(Area, b0, b1,th), data = cl, start
= grid.Disperse, algorithm = "brute-force")
> Disperse.m2a
Nonlinear regression model
model: Retention ~ expFct(Area, b0, th, b1)
data: cl
b0 th b1
3.82 0.02 0.01
residual sum-of-squares: 13596
Number of iterations to convergence: 160000
Achieved convergence tolerance: NA
I got no error then I use the output as starting values to nls2 ():
> nls.m2<- nls2(Retention ~ expFct(Area, b0, b1, th), data = cl, start =
list(b0 = 3.82, b1 = 0.02, th = 0.01))
Error in (function (formula, data = parent.frame(), start, control =
nls.control(), :
Singular gradient
Why? Did I do something wrong or misunderstand something?
Later, I found another measure from Modern Applied Statistics with S (pp.
216-217):
> negexp <- selfStart(model = ~ exp(b0*exp(b1*x^th)),initial =
negexp.SSival, parameters = c("b0", "b1", "th"),
+ template = function(x, b0, b1, th) {})
> Disperse.ss <- nls(Retention ~ negexp(Area, b0, b1, th),data = cl, trace =
T)
b0 b1 th
4.208763 144.205455 1035.324595
Error in qr.default(.swts * attr(rhs, "gradient")) :
NA/NaN/Inf (arg1) can not be called when the external function is called.
Error happened again. How can I fix it? I am desperate.
Best regards,
Pinglei Gao
[[alternative HTML version deleted]]
More information about the R-help
mailing list