用nls方程拟合方程的误差?

时间:2014-03-13 10:58:10

标签: r

x<-c(3,33,146,227,342,351,353,444,556,571,709,759,836,860,968,1056,1726,1846,1872,1986,2311,2366,2608,2676,3098,3278,3288,4434,5034,5049,5085,5089,5089,5097,5324,5389,5565,5623,6080,6380,6477,6740,7192,7447,7644,7837,7843,7922,8738,10089,10237,10258, 10491,10625,10982,11175,11411,11442,11811,12559,12559,12791,13121,13486,14708,15251,15261,15277,15806,16185,16229,16358,17168,17458,17758,18287,18568,18728,19556,20567,21012,21308,23063,24127,25910,26770,27753,28460,28493,     29361,30085,32408,35338,36799,37642,37654,37915,39715,40580,42015,42045,42188,42296,42296,45406,46653,47596,48296,49171,49416,50145,52042,52489,52875,53321,53443,54433,55381,56463,56485,56560,57042,62551,62651,62661,63732,64103,64893,       71043,74364,75409,76057,81542,82702,84566,88682)
y<-(1:136)
df=data.frame(x,y)
fit<-nls(y ~ (a/c)*(1-exp(-((c*x)/b)))^d, data=df,start=c( a=100,b=10000,c=0.5,d=0.5),algorithm="port",lower=c(a=100,b=1000,c=0.5,d=0.5),upper=c(a=200,b=100000,c=3,d=3))

我收到此错误

Error in nlsModel(formula, mf, start, wts, upper) : 
singular gradient matrix at initial parameter estimates

使用package:minpack.lm

library(minpack.lm)
fit<-nlsLM(y ~ (a/c)*(1-exp(-((c*x)/b)))^d, data=df,start=c( a=100,b=10000,c=0.5,d=0.5),algorithm="LM",lower=c(a=100,b=1000,c=0.5,d=0.5),upper=c(a=200,b=100000,c=3,d=3),weights=1/y^2)

我将r的输出与matlab(cftool)进行了比较..我发现matlab给出了准确的结果,并且两个结果之间有更多的偏差..!

为什么这样的nls()能否适用于任何algorithm-port / plinear / default?

我创建了一个应用程序,其中r在后端前端gui中运行java ..我无法调用minpack.lm,因为它需要安装..它没有附带R.其中nls( )已经存在于R中,所以我可以调用nls()并且它工作正常..

我无法用nls()来拟合这个非线性方程..有没有办法做到这一点..

提前感谢.. !!

1 个答案:

答案 0 :(得分:3)

模型参数无法识别。例如,如果我们将c加倍,则会将同一模型设为减半ab