1

I want to do a nonlinear regression with nls() in R, but I always get the following error code:

Warning: Error in nlsModel: singular gradient matric at initial parameter estimates

My nls() function looks like this:

nlr <- nls(formula = valuerange1 ~ A*exp(m1*temp), data = list(temp,valuerange1), start= list(A=4000, m1=0.001))

Without the parameter A the nls() works and I get a result for m1:

nlr <- nls(formula = valuerange1 ~ exp(m1*temp), data = list(temp,valuerange1), start= list(m1=0.001))

who can help me?

DesertFox
  • 11
  • 1
  • Try `nls(valuerange1 ~ exp(m1*temp), algorithm = "plinear", data = list(temp,valuerange1), start = list(m1 = 0.001))`. – Roland Mar 04 '19 at 07:40
  • Unfortunately I still get the error: singular gradient... when I add the parameter A to the list – DesertFox Mar 04 '19 at 08:00
  • Please try my code suggestion as provided. The linear coefficient is included automatically in the model. – Roland Mar 04 '19 at 08:02
  • Warning in .swts * ddot(attr(rhs, "gradient"), lin) : Recycling array of length 1 in vector-array arithmetic is deprecated. Use c() or as.vector() instead. Warning in .swts * attr(rhs, "gradient") : Recycling array of length 1 in vector-array arithmetic is deprecated. Use c() or as.vector() instead. Warning: Error in <-: incorrect number of subscripts on matrix – DesertFox Mar 04 '19 at 08:10
  • I think you need to provide your data. – Roland Mar 04 '19 at 08:15
  • temp = 900, valuerange1 = 120 values, all between 50 and 150 (without outliers) – DesertFox Mar 04 '19 at 08:28
  • I'm sorry, but are you saying you only have one temp value? If so, you simply cannot fit a two-parameter model to this data. Your information is confusing and not sufficient to reproduce the data (and your issue). – Roland Mar 04 '19 at 08:30
  • Yes I have only one value for temp, so theoretically I can write it directly into the formula as a number. My problem is that it doesn't work with the parameter A. You said that it is already passed automatically, so how can I display it? – DesertFox Mar 04 '19 at 08:38
  • I can only reiterate, you **cannot** fit a model with two parameters if you only have one x value. That's not a programming issue, it's purely a mathematical fact. – Roland Mar 04 '19 at 08:41
  • Yes you're right with a parameter as x value it doesn't work. But if I add another parameter with 120 values between 0.01 and 1.2, I still get the error of the singular gradient. – DesertFox Mar 04 '19 at 08:50
  • `nlr <- nls(formula = valuerange1 ~ A*exp(m1*temp)*valuerange2^m2, data = list(temp,valuerange1,valuerange2), start= list(A=4000, m1=0.001, m2=0.001))` – DesertFox Mar 04 '19 at 08:51
  • Yes, that doesn't surprise me. You need to go back and collect better data (vary temp in your experiment) if you want to fit this model. – Roland Mar 04 '19 at 08:56

0 Answers0