使用R拟合S形曲线 [英] Using R to fit a Sigmoidal Curve

查看:360
本文介绍了使用R拟合S形曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一篇文章(R中的S曲线拟合)。它被标记为重复,但看不到与这些帖子相关的任何内容。而且,这些职位的答案还不够。

I have read a post ( Sigmoidal Curve Fit in R ). It was labeled duplicated, but I can't see anything related with the posts. And the answer given for the posts was not enough.

我读了网页

与其他人类似,他使用此格式来适应这一行:

Similar to the others, he uses this format to fit the line:

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

问题是a,b,c在在大多数情况下,我不知道应将哪一组a,b,c用于数据集。有人可以给我一些有关如何获取参数的建议吗?

The problem is that, a,b,c were given in most of the cases and I have no clues which set of a,b,c should I use for my set of data. Could someone give me some advice on how to obtain the parameters?

这是我的一组数字:

x <- c(3.9637878,3.486667,3.0095444,2.5324231,2.0553019,1.5781806,1.1010594,0.6242821)
y <- c(6491.314,6190.092,2664.021,2686.414,724.707,791.243,1809.586,541.243)


推荐答案

幸运的R提供了自我启动逻辑模型的模型。它使用了稍微的重新参数化,但实际上与您的模型相同: Asym /(1 + exp((xmid-input)/ scal))

Luckily R offers a selfstarting model for the logistic model. It uses a slight reparametrization, but is really the same model as yours: Asym/(1+exp((xmid-input)/scal))

自启动模型可以为您估算良好的起始值,因此您不必指定它们。

A selfstarting model can estimate good starting values for you, so you don't have to specify them.

plot(y ~ x)
fit <- nls(y ~ SSlogis(x, Asym, xmid, scal), data = data.frame(x, y))

summary(fit)
#Formula: y ~ SSlogis(x, Asym, xmid, scal)
#
#Parameters:
#      Estimate Std. Error t value Pr(>|t|)
#Asym 1.473e+04  2.309e+04   0.638    0.551
#xmid 4.094e+00  2.739e+00   1.495    0.195
#scal 9.487e-01  5.851e-01   1.622    0.166
#
#Residual standard error: 941.9 on 5 degrees of freedom
#
#Number of iterations to convergence: 0 
#Achieved convergence tolerance: 4.928e-06

lines(seq(0.5, 4, length.out = 100), 
      predict(fit, newdata = data.frame(x = seq(0.5, 4, length.out = 100))))

当然,您的数据并不真正支持该模型。估计的中点恰好在数据范围的正确极限处,因此参数估计(尤其是对于渐近线)非常不确定。

Of course your data doesn't really support the model. The estimated mid point is just at the right limit of your data range and thus the parameter estimates (in particular for the asymptote) are very uncertain.

这篇关于使用R拟合S形曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆