在 nls 中拟合模型时出错

Error fitting a model in nls

之前对类似问题的回答并没有帮助我解决问题。

我正在尝试拟合模型 y=a1*(1-exp(-a21*Age_WH40))^a3,其中 a21=ln(1/a3)/a2 和 Age_WH40 从 1 到 40。 我绘制了数据和一条线来了解起始值

plot(MOE_WH40 ~ Age_WH40)
lines(ts(8*(1-exp(log(1/3)/5*(1:40)))^3),col="red", lwd=2)

fit.nlm_MOE4A.WH <- nls(MOE_WH40 ~ a*(1-exp(log(1/c)/b*Age_WH40))^b, start=list(a=10, b=6, c=2))

但即使我限制数据以避免分散,我也只能得到

Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model

我不认为这是起始值的问题,我 运行 在 Excel 中从 1 到 40 的模型没有问题。知道发生了什么吗?这里有一个数据子集:

structure(list(ID = c(245L, 246L, 247L, 248L, 249L, 250L, 251L, 
252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 
263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 508L, 509L, 510L, 
511L), MOE_WH40 = c(7.9, 7.12, 4.369, 5.44, 8.97, 9.58, 8.07, 
7.9, 6.93, 5.63, 6, 6.17, 8.51, 8.79, 7.21, 6.64, 6.7, 7.88, 
7.97, 6.93, 5.64, 6.86, 9.36, 9.44, 10.04, 9.58, 4.337, 5.12, 
6.7, 7.86), Age_WH40 = c(23L, 29L, 4L, 8L, 13L, 20L, 24L, 29L, 
33L, 2L, 7L, 9L, 15L, 20L, 23L, 27L, 12L, 13L, 20L, 23L, 3L, 
9L, 16L, 22L, 26L, 30L, 2L, 8L, 11L, 15L)), .Names = c("ID", 
"MOE_WH40", "Age_WH40"), class = "data.frame", row.names = c(NA, 
-30L))

谢谢

您可以尝试使用 minpack.lm 包,它使用了 Levenberg-Marquardt 算法。为简洁起见,我将您的数据称为 "demo"。

nlsLM(data = demo, formula = MOE_WH40 ~ a*(1-exp(log(1/c)/b*Age_WH40))^b, start=list(a=10, b=6, c=2))
Nonlinear regression model
model: MOE_WH40 ~ a * (1 - exp(log(1/c)/b * Age_WH40))^b
data: demo
 a      b      c 
8.5573 0.3774 1.0347 
residual sum-of-squares: 32.89

Number of iterations to convergence: 24 
Achieved convergence tolerance: 1.49e-08
Warning messages:
1: In log(1/c) : NaNs produced
2: In log(1/c) : NaNs produced
3: In log(1/c) : NaNs produced

在 nls 中,它始终是起始值。