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

后端 未结 3 1467
别跟我提以往
别跟我提以往 2020-12-17 17:59

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 c

相关标签:
3条回答
  • 2020-12-17 18:35

    Try removing any row observations with zero, especially in the predictor variables and try the nls function. It worked for me.

    0 讨论(0)
  • 2020-12-17 18:43

    The problems are:

    • we need better initial values
    • according to a comment by the poster we need to constrain LCP to be positive.

    To do that we can use nls2 to get better starting values followed by using nls with the port algorithm to enforce a lower bound for LCP. Note that LCP hit the constraint boundary.

    library(nls2)
    
    # get starting value fit
    st <- data.frame(Am = c(1, 10), Rd = c(-10, 10), LCP = c(0.5, 10))
    fo <- photolrc ~ Am*(1-((1-(Rd/Am))^(1-(PARlrc/LCP))))
    fm2 <- nls2(fo, start = st, alg = "brute")
    
    # nls fit
    fm <- nls(fo, start = coef(fm2), lower = c(-Inf, -Inf, 0.1), algorithm = "port")
    

    giving:

    > fm
    Nonlinear regression model
      model: photolrc ~ Am * (1 - ((1 - (Rd/Am))^(1 - (PARlrc/LCP))))
       data: parent.frame()
           Am        Rd       LCP 
     7.919374 -0.007101  0.100000 
     residual sum-of-squares: 0.1858
    
    Algorithm "port", convergence message: relative convergence (4)
    
    0 讨论(0)
  • 2020-12-17 18:54

    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)))
    

    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?

    0 讨论(0)
提交回复
热议问题