使用nls产生奇异梯度

问题描述 投票:0回答:1

我想使用nls函数运行数据,但是会出现错误:

我的数据是:

y=c(0.3,1.5,4.1,10.1,21.9,39,4,58.2,77,89.6,95,98.3,100)

x=c(30,35,40,45,50,55,60,65,70,75,80,85,90)

我使用了以下功能:

fit<-nls(y~a/(1+exp(-b*(x-c))),start=list(a=1,b=0.5,c=25))

似乎一开始出现问题,但不确定。

r nls
1个回答
0
投票

需要更好的起始值。首先取双方的倒数,并使用"plinear"算法,该算法不需要线性参数的起始值,在这种情况下为a。然后将其用作适合您的起始值。

fit0 <- nls(1/y ~ 1 + exp(-b*(x-c)), start = list(b = .5, c = 25), alg = "plinear")
fit <- nls(y~1/(1+exp(-b*(x-c))),start=coef(fit0)[1:2], alg = "plinear")

plot(y ~ x)
lines(fitted(fit) ~ x)
fit

给予:

Nonlinear regression model
  model: y ~ 1/(1 + exp(-b * (x - c)))
   data: parent.frame()
       b        c     .lin 
  0.1355  64.9761 106.7095 
 residual sum-of-squares: 1516

Number of iterations to convergence: 13 
Achieved convergence tolerance: 6.85e-06

screenshot

© www.soinside.com 2019 - 2024. All rights reserved.