1

I've tried to fit the following into a ADBUG model using the nls function in r, but the singular matrix error kept repeating and I don't really know how to proceed on doing this...

     nprice       nlv2
[1,] 0.6666667 1.91666667
[2,] 0.7500000 1.91666667
[3,] 0.8333333 1.91666667
[4,] 0.9166667 1.44444444
[5,] 1.0000000 1.00000000
[6,] 1.0833333 0.58333333
[7,] 1.1666667 0.22222222
[8,] 1.2500000 0.08333333
[9,] 1.3333333 0.02777778

code:

fit <- nls(f=nprice~a+b*nlv2^c/(nlv2^c+d),start=list(a=0.083,b=1.89,c=-10.95,d=0.94))

Error in nls(f = nprice ~ a + b * nlv2^c/(nlv2^c + d), start = list(a = 0.083, : singular gradient

barbsan
  • 3,418
  • 11
  • 21
  • 28
Joseph
  • 11
  • 1

1 Answers1

0

Package nlsr provides an updated version of nls through function nlxb that in most cases avoids the "singular gradient" error.

library(nlsr)
fit <- nlxb(f = nprice~a+b*nlv2^c/(nlv2^c+d),
       data = df,
       start = list(a=0.083,b=1.89,c=-10.95,d=0.94))
## vn:[1] "nprice" "a"      "b"      "nlv2"   "c"      "d"     
## no weights

fit$coefficients
##           a           b           c           d 
## -2.1207e+04  2.1208e+04 -7.4083e-01  1.6236e-05 

The fitted coefficients are far away from the starting values and quite big, indicating the problem is not well grounded.

Hans W.
  • 1,799
  • 9
  • 16