2011-07-27 70 views
0

我有R/S /非线性回归相关问题,我不是R程序员,所以我需要帮助。R/S中的非线性回归

我有两个数组 - tt和td。

我需要找到参数a,b和c等等最小二乘和最小的非线性函数:

td/tt - a * exp(b * tt) + c 

我不知道如何做到这一点。我试过nls()函数,nls2() nad没有运气...

在此先感谢。

编辑:

我的数据:

td <-as.array(0.2, 0.4, 0.8, 1.5, 3); 

tt <-as.array(0.016, 0.036, 0.0777, 0.171, 0.294); 

从下面的答案的方法,我得到的随机数据确定值,但是我使用返回缺少值的数据或无穷大制作评估模型消息时。

抱歉不提前提供数据。

+2

问题比较容易回答,如果你给我们说你已经尝试样本数据和示例代码。 –

+1

请修改您的问题并重新生产。谢谢,欢迎来到SO。 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –

回答

4

您的数据:

n <- 100 
td <- runif(n) 
tt <- runif(n) 
data <- data.frame(td = td, tt = tt) 

一个组成的函数结果

a <- 0.5 
b <- 2 
c <- 5 
y <- jitter(td/tt - a * exp(b * tt) + c) 

(在实践中,你不会知道什么,b和c,直到后来在这里我们使用它们与答案进行比较)

配件:

nls(
    y ~ td/tt - a * exp(b * tt) + c, 
    data = data, 
    start = list(a = 1, b = 1, c = 1) 
) 

答案:

Nonlinear regression model 
    model: y ~ td/tt - a * exp(b * tt) + c 
    data: data 
    a  b  c 
0.4996 2.0008 4.9994 
residual sum-of-squares: 0.0001375 

Number of iterations to convergence: 7 
Achieved convergence tolerance: 1.604e-06 
+0

非常非常感谢你! – Nemanja

+0

我很抱歉,但一旦我用随机数据替换前三行: ñ< - 100 TD < - runif(N) TT < - runif(N) 与我的数据: TD < - 作为数组(0.2,0.4,0.8,1.5,3); tt <-asarray(0.016,0.036,0.0777,0.117,0.294); 我numericDeriv(形式[3L],名称(IND),ENV)得到一个消息 错误: 缺少值或评估模型 我要去哪里错了,当一个无边产生的? – Nemanja

+2

将3参数非线性模型拟合到5个数据点总是会让人感到痛苦。你需要很好的初始值。 –