开发者

Nonlinear regression in R / S

I have a R / S / Nonlinear regression related issue and i am not a R programmer, so i kinda need help.

I have two arrays - tt and td.

I need to find the parameters a,b and c so the sum of least squares is minimal for a non linear function:

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

I have no idea how to do this. I tried nls() function, nls2() nad had no luck...

Thanks in advance.

EDIT:

My data:

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);

With the method from the answer below, i get ok values for开发者_Python百科 random data, but the data i am using returns the Missing value or an infinity produced when evaluating the model message.

Sorry for not providing data sooner.


Your data:

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

A made up result of function

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

(In practice, you won't know what a, b and c are until afterwards. Here we use them to compare with the answer.)

The fitting:

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

The answer:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜