R:nls奇异梯度,但当收敛时,则奇怪总结
我试图用nls拟合指数衰减模型。对于一些数据集,对于另一些数据集,我确实有奇异梯度问题。我玩了最初的猜测,然后它收敛了:R:nls奇异梯度,但当收敛时,则奇怪总结,r,R,我试图用nls拟合指数衰减模型。对于一些数据集,对于另一些数据集,我确实有奇异梯度问题。我玩了最初的猜测,然后它收敛了: al<- c(1.000000000, -0.191323992, 0.033160155, 0.098588015, 0.091868322, 0.093882227, -0.008586943, 0.111179350, 0.114696305, -0.219874647, -0.058803866, 0.064467078,
al<- c(1.000000000, -0.191323992, 0.033160155, 0.098588015, 0.091868322,
0.093882227, -0.008586943, 0.111179350, 0.114696305, -0.219874647,
-0.058803866, 0.064467078, 0.012330649, -0.121760137, -0.028633566,
-0.166431701, -0.129571514, -0.227254377, 0.189324908, 0.158551556,
0.035583227, 0.068326222, -0.019393207, -0.058901557, 0.278201324,
-0.186608434, -0.065429683, -0.149088734, 0.125509557, 0.057595929,
0.151851443, 0.163017250, 0.296895691, 0.161603269, 0.106648901,
0.008832903)
dist<-c(0.00000, 21.70568, 106.26789, 207.77424, 272.99427, 344.35261,
413.31444, 458.64773, 505.02554, 543.35691, 569.11492, 604.81217,
650.79766, 694.61326, 732.70419, 770.36200, 815.77073, 866.19371,
916.37255, 958.81687, 997.11661, 1040.33902, 1093.52611, 1153.57151,
1210.58217, 1265.61952, 1334.84359, 1413.56687, 1495.18853, 1580.78396,
1662.75520, 1767.75038, 1887.74513, 2009.35511, 2184.02066, 2888.08612)
nl<-nls(al~1*(exp(-dist/(ti))),data=ndat,start=list(ti=10),
lower=0.1,upper=10000,algorithm="port",control=list(warnOnly = TRUE),trace=T)
0: 0.35937482: 10.0000
1: 0.33103226: 0.100000
2: 0.33103226: 0.100000
现在检查置信区间:
confint(nl)
Waiting for profiling to be done...
2.5% 97.5%
NA 532.2994
性病错误发生了什么?我猜由于p和t值,估计参数是完全不重要的?ti是否应该实际为0?它如何在95%置信度范围内估计ti的范围?不应该是ti+-1.96*std错误吗?您的数据不支持此模型。从图上看,
nl
对于dist
的所有值都或多或少地随机分布在0附近,而不是0,其中它是1。因此,期望拟合指数衰减模型是不现实的nls(…)
根据您的规范生成最佳估计值:ti根据您在lower=…
中的规范设置为可能的最低值
ndat <- data.frame(al,dist)
nl<-nls(al~1*(exp(-dist/(ti))),data=ndat,start=list(ti=10),
lower=0.1,upper=10000,algorithm="port",
control=list(warnOnly = TRUE),trace=T)
plot(ndat$dist,ndat$al)
lines(ndat$dist,predict(nl), col="red",lty=2)
谢谢您的快速回复。我首先想到的是,这个模型根本无法安装。但我仍然希望我能得到一个指数衰减和一个巨大的衰减。如果没有下限,奇异梯度会再次抱怨,那么初始猜测就无关紧要了。它确实有一个“巨大的衰减”。衰减系数为1/ti或100,如果将ti的下限设置为0.1,则衰减系数将尽可能大。
ndat <- data.frame(al,dist)
nl<-nls(al~1*(exp(-dist/(ti))),data=ndat,start=list(ti=10),
lower=0.1,upper=10000,algorithm="port",
control=list(warnOnly = TRUE),trace=T)
plot(ndat$dist,ndat$al)
lines(ndat$dist,predict(nl), col="red",lty=2)