Steffen44
Steffen44

Reputation: 11

R nls singular gradient starting value

I am having a problem while fitting a fucntion via nls

This is the Data:

size<-c(0.0020,0.0063,0.0200,0.0630,0.1250,0.2000,0.6300,2.0000)
cum<-c(6.4,7.1,7.6,37.5,83.0,94.5,99.9,100.0)

I want to fit Gompertz model to it. Therefor i tried:

start<-c(alpha =100, beta = 10, k = 0.03)
fit<-nls(cum~ alpha*exp(-beta*exp(-k*size)),start=start)

The Error says: Singulat gradient.

Some post suggest to choose better starting values.

Can you help me with this problem?

Upvotes: 1

Views: 460

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 269441

The starting values are too far away from the optimal ones. First take logs of both sides in which case there is only one non-linear parameter, k. Only that needs a starting value if we use the plinear algorithm. Using k from that fit as the k starting value refit using original formula.

fit.log <- nls(log(cum) ~ cbind(1, exp(-k*size)), alg = "plinear", start = c(k = 0.03))

start <- list(alpha = 100, beta = 10, k = coef(fit.log)[["k"]])
fit <- nls(cum ~ alpha*exp(-beta*exp(-k*size)), start = start)
fit

giving:

Nonlinear regression model
  model: cum ~ alpha * exp(-beta * exp(-k * size))
   data: parent.frame()
  alpha    beta       k 
100.116   3.734  22.340 
 residual sum-of-squares: 45.87

Number of iterations to convergence: 11 
Achieved convergence tolerance: 3.351e-06

We can show the fit on a graph

plot(cum ~ size, pch = 20)
lines(fitted(fit) ~ size, col = "red")

giving:

screenshot

Upvotes: 2

Related Questions