Skip to content
Prev 275267 / 398503 Next

Exponential fit of form y=exp(a*x) and not of form y=l*e

On 23-Oct-11 19:03:05, Carl Witthoft wrote:
Of course fitting y2 ~ 1.0*exp(A*x) to datatiplicativel generated by

  y2 <- 5*exp(x/20) + runif(101)/100

will result in a bad fit! Henri's original query stated
that he wanted to fit y ~ exp(A*x), and I presume he had
a reason for not including a multiplicative constant as in
your y2 ~ B*exp(A*x). It may well be that he knows, for
some reason, that, in  B*exp(A*x), B must be 1, though
he was certainly not explicit about this !

Generating the data with 1.0*exp(x/20) and then using nls
in the form nls(y2 ~ exp(A*x) works perfectly:

  x  <- 1:101
  y2 <- 1.0*exp(x/20) + runif(101)/100

  nls(y2 ~ exp(A*x), start=list(A=.1))

  # Nonlinear regression model
  #   model:  y2 ~ exp(A * x) 
  #    data:  parent.frame() 
  #    A 
  # 0.05 
  #  residual sum-of-squares: 0.002608
  #
  # Number of iterations to convergence: 9 
  # Achieved convergence tolerance: 5.962e-08

So I would not say he was "misusing nls", since we do not have
information about his data. Throwing up a counter-eaxample
where the data are deliberately generated so as to be impossible
to fit with the formula he wants to use (for whatever reason)
is not a good argument!

Hoping this helps,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 23-Oct-11                                       Time: 21:22:53
------------------------------ XFMail ------------------------------