gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:16:30 25 4
gpt4 key购买 nike

我正在尝试使用 R 中的 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

关于如何解决这个问题有什么想法吗?

数据:

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

最佳答案

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

给予:

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

关于r - 初始参数估计时 nls 奇异梯度矩阵的误差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33978012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com