初始参数估计中nls奇异梯度矩阵的误差

时间:2015-11-29 00:23:53

标签: r matrix gradient nls

我正在尝试使用R中的 NodeList nList = doc.getElementsByTagName("jbeil"); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; NodeList nList2 = eElement.getElementsByTagName("restaurant"); for (int n = 0; n < nList.getLength(); n++) { Node nNode2 = nList2.item(n); if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement2 = (Element) nNode; System.out.println(eElement2.getElementsByTagName("name").item(0).getTextContent()); } } } } 拟合矩形双曲线。

nls

出现一条狂野消息:

curve.nlslrc = nls(photolrc ~ (1/(2*theta))*(AQY*PARlrc+Am-sqrt((AQY*PARlrc+Am)^2-4*AQY*theta*Am*PARlrc))-Rd, start=list(Am=(max(photolrc)-min(photolrc)),AQY=0.05,Rd=-min(photolrc),theta=1))

有关如何解决此问题的任何想法?

数据:

Error in nlsModel(formula, mf, start, wts) : 
  singular gradient matrix at initial parameter estimates

1 个答案:

答案 0 :(得分:2)

尝试nlsLM

library(minpack.lm)

curve.nlslrc = with(DF, 
  nlsLM(photolrc ~ 
          (1/(2*theta))*(AQY*PARlrc+Am-sqrt((AQY*PARlrc+Am)^2-4*AQY*theta*Am*PARlrc))-Rd, 
     start = list(Am=(max(photolrc)-min(photolrc)), AQY=0.05,  Rd=-min(photolrc), theta=1))
)

,并提供:

> curve.nlslrc
Nonlinear regression model
  model: photolrc ~ (1/(2 * theta)) * (AQY * PARlrc + Am - sqrt((AQY *     PARlrc + Am)^2 - 4 * AQY * theta * Am * PARlrc)) - Rd
   data: parent.frame()
       Am       AQY        Rd     theta 
 3.957527  0.002529 -0.340865  1.000022 
 residual sum-of-squares: 6.94

Number of iterations to convergence: 35 
Achieved convergence tolerance: 1.49e-08

(图表后继续)

screenshot

注1:请注意,参数较少的简单模型(3对4)具有较低的残差平方和(6.7对6.9):

fm.lm <- lm(photolrc ~ PARlrc, DF)
fm2 <- nls(photolrc ~ pmin(a, b * PARlrc + c), DF,
  start = list(a = mean(DF$photolrc), b = coef(fm.lm)[2], c = 0))

giuving:

> fm2
Nonlinear regression model
  model: photolrc ~ pmin(a, b * PARlrc + c)
   data: DF
       a        b        c 
4.159377 0.002434 0.420329 
 residual sum-of-squares: 6.739

Number of iterations to convergence: 5 
Achieved convergence tolerance: 9.197e-09

注2:这用作DF

Lines <- "PARlrc photolrc
50 -0.04
100 1.130000
150 0.580000
200 0.850000
250 1.370000
300 1.370000
350 1.230000
400 2.040000
450 1.670000
500 1.790000
550 1.820000
600 1.768494
650 2.083641
700 1.998950
750 2.399018
800 2.289517
850 2.223104
900 2.329006
950 2.700987
1000 2.694792
1050 2.684530
1100 2.594925
1150 2.662429
1200 2.590890
1250 3.043056
1300 3.795076
1350 4.003595
1400 4.401325
1450 4.786757
1500 4.338971
1550 4.701821
1600 4.431703
1650 4.392877
1700 4.642945
1750 4.429018
1800 3.638166
1850 2.879107"
DF <- read.table(text = Lines, header = TRUE)