gpt4 book ai didi

r - 解决错误消息 "step halving factor reduced below minimum in NLS step": adjusting nlsTols not working

转载 作者:行者123 更新时间:2023-12-03 15:46:49 25 4
gpt4 key购买 nike

我正在尝试使用gnls函数将逻辑增长曲线拟合到一些数据。

数据:

structure(list(Nest = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 16L, 10L, 4L, 5L, 7L, 12L, 4L, 6L, 20L, 8L, 14L, 16L, 3L, 9L, 15L, 19L, 6L, 7L, 17L, 18L, 12L, 13L, 10L, 20L, 5L, 8L, 11L, 16L, 6L, 12L, 1L, 2L, 4L, 6L, 9L, 18L, 21L, 16L, 3L, 20L),
.Label = c("WTSN01", "WTSN02", "WTSN04", "WTSN05", "WTSN06", "WTSN07", "WTSN08", "WTSN09", "WTSN10", "WTSN12", "WTSN13", "WTSN14", "WTSN16", "WTSN18", "WTSN20", "WTSN21", "WTSN23", "WTSN24", "WTSN25", "WTSN26", "WTSN28", "WTSN29"), class = "factor"),
Hatch = structure(c(16177, 16177, 16177, 16165, 16185, 16189, 16188, 16193, 16181, 16181, 16177, 16181, 16180, 16195, 16200, 16177, 16182, 16176, 16173, 16189, 16181, 16178, 16177, 16181, 16165, 16185, 16188, 16181, 16165, 16189, 16189, 16193, 16195, 16177, 16177, 16181, 16200, 16173, 16189, 16188, 16182, 16176, 16181, 16180, 16181, 16189, 16185, 16193, 16177, 16177, 16189, 16181, 16177, 16177, 16165, 16189, 16181, 16176, 16181, 16177, 16177, 16189),
class = "Date"),
Age = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 6, 7.5, 8, 8, 8, 8, 8.5, 8.5, 8.5, 9, 9, 9,
9.5, 9.5, 9.5, 9.5, 10, 10, 10, 10, 10.5, 10.5, 11, 11, 11.5,
11.5, 11.5, 11.5, 12, 12, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5,
12.5, 13, 13.5, 13.5), Weight = c(1.022, 1.022, 1.022, 1.022,
1.022, 1.022, 1.022, 1.022, 1.022, 1.022, 1.022, 1.022, 1.022,
1.022, 1.022, 1.022, 1.022, 1.022, 1.022, 1.022, 1.022, 1.022,
8.1, 8.5, 8.8, 8.8, 9.6, 8.6, 9.7, 11, 9.9, 11.1, 9.9, 12,
10.5, 10.5, 7, 11.2, 11.9, 11.4, 11, 11.9, 11.2, 11.7, 9.1,
12.3, 12.3, 13, 11.6, 13.4, 12.2, 11.1, 12.7, 11.3, 12.2,
12.4, 11.8, 12.9, 11.2, 13.2, 11, 14.1)),
.Names = c("Nest", "Hatch", "Age", "Weight"),
row.names = c(NA, 62L), class = "data.frame")

代码:
StartLogistic = c(Asym = 14.2, b = 0.07, K = 0.5)
Logistic_gnls = gnls(Weight ~ Asym/(1 + exp(b + K*Age)), data = WTS_gw,
start = StartLogistic)

这给出了错误信息:
Error in gnls(Weight ~ Asym/(1 + exp(b + K * Age)), data = WTS_w, start = StartLogistic):
step halving factor reduced below minimum in NLS step

我在一些地方阅读过,将 nlsTols增加到0.1应该可以解决此问题,但是我尝试将其以最大100个数量级的增量进行增加,并且给出了相同的错误。
Logistic_gnls = gnls(Weight ~ Asym/(1 + exp(b + K*Age)), data = WTS_w,
start = StartLogistic, control=list(nlsTols=100))

我也尝试增加 tolerance,但无济于事。
Logistic_gnls = gnls(Weight ~ Asym/(1 + exp(b + K*Age)), data = WTS_w,
start = StartLogistic, control=list(tolerance=100))

谁能看到解决方案?

最佳答案

您的数据覆盖范围很差,即逻辑功能的向上弯曲部分和一个有影响力的数据点中没有数据。在下文中,我将对逻辑函数使用不同的参数化。首先,让我们将nls与selfstarting函数配合起来:

plot(Weight ~ Age, data=DF)

fit <- nls(Weight ~ SSlogis(Age, Asym, xmid, scal), data=DF)
summary(fit)

curve(predict(fit, newdata = data.frame(Age=x)), add=TRUE)

现在,您可以使用系数并将其传递给 gnls:
library(nlme)
Logistic_gnls <- gnls(Weight ~ Asym/(1+exp((xmid-Age)/scal)), data = DF,
start = coef(fit))
coef(Logistic_gnls)
# Asym xmid scal
#12.908170 5.702021 2.365212

因此,您可以成功获得更好的起始值。

关于r - 解决错误消息 "step halving factor reduced below minimum in NLS step": adjusting nlsTols not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27547548/

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