0

I have found similar posts but the solutions did not work for me. I want to fit a curve to some data. I expect the curve to be defined by a function similar to: y = -10*(x-0.3)^2 +1

When I use nls as follows:

fit.2<-nls(co2 ~ F * (mvol+G)^k + C, data=soildata, start=list(F=-1, G=-0.25, C = 1, k=2))
lines(newdat$mvol, predict(fit.2, newdata = newdat), col="red", lwd=2)

I get the error:

> fit.2<-nls(co2 ~ F * (mvol+G)^k + C, data=soildata, start=list(F=-1, G=-0.25, C = 1, k=2))
Error in numericDeriv(form[[3L]], names(ind), env) : 
  Missing value or an infinity produced when evaluating the model

I've tried adjusting the starting points but doesnt seem to help. I'm new to R but have some experience with matlab.

Let me know if you see whats wrong.

Here's what my data looks like.

enter image description here

r2evans
  • 141,215
  • 6
  • 77
  • 149
dlight
  • 29
  • 3
  • 1
    So your eqn is `y = F * (mvol + G)^k + C` and you are fitting `F`, `G`, `k`, and `C` as parameters? It seems strange to me that you are fitting `k` as a parameter--your text suggests maybe just fixing `k = 2`, which seems reasonable. Powers have **strong** effects, so it's common to log everything if you're not sure what the power is, which will make the estimation a little more robust. – Gregor Thomas May 12 '20 at 17:30
  • This is great. You're right I should just fix the exponent at 2. – dlight May 12 '20 at 18:06

0 Answers0