我试图用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
发布于 2015-11-29 00:40:37
试试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
(图表后继续)
注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)
https://stackoverflow.com/questions/33978012
复制相似问题