Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
944 views
in Technique[技术] by (71.8m points)

r - nls troubles: Missing value or an infinity produced when evaluating the model

I am an R newbie trying to fit plant photosynthetic light response curves (saturating, curvilinear) to a particular model accepted by experts. The goal is to get estimated coefficient values for Am, Rd, and LCP. Here is the error I keep getting:

Error in numericDeriv(form[[3L]], names(ind), env) : 
  Missing value or an infinity produced when evaluating the model

I have switched around the starting values a number of times, but still no luck. Help? Thanks you in advance. Example dataset below.

photolrc= c(3.089753, 6.336478, 7.737142, 8.004812, 8.031599)
PARlrc= c(48.69624, 200.08539, 499.29840, 749.59222, 1250.09363)
curvelrc<-data.frame(PARlrc,photolrc)
curve.nlslrc = nls(photolrc ~ Am*(1-((1-(Rd/Am))^(1-(PARlrc/LCP)))),start=list(Am=(max(photolrc)-min(photolrc)),Rd=-min(photolrc),LCP= (max(photolrc)-1)))
coef(curve.nlslrc)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

minpack.lm to the rescue:

library(minpack.lm)
curve.nlslrc = nlsLM(photolrc ~ Am*(1-((1-(Rd/Am))^(1-(PARlrc/LCP)))),
                   start=list(Am=(max(photolrc)-min(photolrc)),
                              Rd=-min(photolrc),
                              LCP= (max(photolrc)-1)),
                   data = curvelrc)
coef(curve.nlslrc)
  #      Am         Rd        LCP 
  #8.011311   1.087484 -20.752957

plot(photolrc ~ PARlrc, data = curvelrc)
lines(0:1300, 
      predict(curve.nlslrc, 
              newdata = data.frame(PARlrc = 0:1300)))

resulting plot

If you pass start = list(Am = 8, Rd = 1, LCP = -20) to nls you also get a successful fit.

I don't know if the parameter values are sensible estimates considering the science behind this. Can LCP be negative?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...