0

nls((mortalityof2018)~(i+g*h^age),start = list(g=1,h=1,i=1))

Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates

Everytime i enter the above code i get an error saying singular gradient matrix at initial parameter estimates.please help. for reference both mortalityof2018 and age is a vector containing 111 values

PS= im trying to fit makeham model(A+B*c^x) to mortalityof2018 and therefore trying to estimate the parameters using nls

AEx12
  • 1
  • Well, you need better starting values. A starting value h = 1 seems a bad choice. – Roland Oct 05 '20 at 11:27
  • > nls((mortalityof2018)~(i+g*(h^age)),start = list(g=0.1,h=0.1,i=1)) Error in nls((mortalityof2018) ~ (i + g * (h^age)), start = list(g = 0.1, : step factor 0.000488281 reduced below 'minFactor' of 0.000976562. i tried using different value and getting a different error – AEx12 Oct 05 '20 at 11:50
  • Yes, you should spend more effort on finding good starting values. I would look at a plot of the data to get a decent starting value for `i`. Then I would use `lm` to fit `log(y - i) = log(g) + log(h) * age`. The coefficients of the `lm` fit should (after exponentiation) be decent starting values for `g` and `h`. – Roland Oct 05 '20 at 12:04
  • Use `plinear` to avoid having to provide starting values for the linear parameters: `nls(mortalityof2018 ~ cbind(1, h^age), algorithm = "plinear", start = c(h = ...))` where ... is replaced with an estimate of h. Do that repeatedly for different values of h until you succeed. The nls2 package can help automate that. Note that you normally won't get any answers if you don't provide a complete reproducible example. No one can run the code in the question except you because the inputs are missing. – G. Grothendieck Oct 07 '20 at 18:13

0 Answers0