R / S中的非线性回归

时间:2011-07-27 13:15:28

标签: r statistics nonlinear-optimization s

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

我有两个数组 - 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);

使用下面的答案中的方法,我得到随机数据的正确值,但我正在使用的数据返回在评估模型消息时产生的缺失值或无穷大。

很抱歉没有尽快提供数据。

1 个答案:

答案 0 :(得分: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)

(实际上,在此之前你不会知道a,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