R:nls奇异渐变但是当收敛然后奇怪的总结

时间:2014-05-16 14:13:21

标签: 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,  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

如果初始ti = 100则没有,但如果我把ti = 1000那么它确实!! (第一次异常活动..)

让我们检查摘要(使用ti = 10的“收敛”情况):

summary(nl)

Formula: al ~ 1 * (exp(-dist/(ti)))

Parameters:
    Estimate Std. Error t value Pr(>|t|) 
ti 1.000e-01  1.171e+90       0        1

Residual standard error: 0.1375 on 35 degrees of freedom Algorithm
"port", convergence message: both X-convergence and relative
convergence (5)

现在检查置信区间:

confint(nl) 
Waiting for profiling to be done...
    2.5%    97.5% 
      NA 532.2994

Std发生了什么事。错误?我想由于p和t值,估计的参数是完全无关紧要的?应该ti = 0吗?
它如何估计ti的范围在95%的置信度内?不应该是ti + - 1.96 *标准错误?

1 个答案:

答案 0 :(得分:1)

您的数据不支持此模型。看一下情节,nl或多或少随机分布在0左右,除了0之外的dist的所有值,其中它是1.所以期望拟合指数衰减模型是不现实的。 nls(...)根据您的规范生成最佳估算值:t i 根据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)

t i 中的标准误差是如此之大,因为估计非常差。