Henri Mone
2011-Oct-23 16:50 UTC
[R] Exponential fit of form y=exp(a*x) and not of form y=l*exp(a*x)
Dear R Users, Beginners and Experts, I want to fit to my data an exponential function with following functional form: y=exp(a*x) I used the function "nls" but this gives me exponential fits with following functional form: y=l*exp(a*x) With "l" being an scaling factor. What do I need to change in my R code? t.dataFitModel=nls(t.dataForFitY ~exp(a*t.dataForFitX), data=t.dataForFit, start=list(a = 0.01242922), trace=TRUE, algorithm "plinear") Thanks in advance and a nice weekend, Henri
Ben Bolker
2011-Oct-23 17:02 UTC
[R] Exponential fit of form y=exp(a*x) and not of form y=l*exp(a*x)
Henri Mone <henriMone <at> gmail.com> writes:> I want to fit to my data an exponential function with following > functional form: > y=exp(a*x) > > I used the function "nls" but this gives me exponential fits with > following functional form: > y=l*exp(a*x) > > With "l" being an scaling factor. What do I need to change in my R code? > > t.dataFitModel=nls(t.dataForFitY ~exp(a*t.dataForFitX), > data=t.dataForFit, start=list(a = 0.01242922), trace=TRUE, algorithm > "plinear")Use an algorithm other than "plinear", I think (admittedly this is not at all clear from ?nls -- you would really have to go to the references to find out).
Carl Witthoft
2011-Oct-23 19:03 UTC
[R] Exponential fit of form y=exp(a*x) and not of form y=l*exp(a*x)
You misused nls(). Observe:
x<- 1:101
y2 <- 5*exp(x/20) + runif(101)/100 # nls will NOT converge for perfect data.
nls(y2 ~ exp(A*x), start=list(A=.1))
Nonlinear regression model
model: y2 ~ exp(A * x)
data: parent.frame()
A
0.06709
residual sum-of-squares: 136703
Number of iterations to convergence: 7
Achieved convergence tolerance: 2.694e-06
Which is a lousy fit. Compare with
nls(y2~B*exp(A*x), start=list(A=.1,B=.3))
Nonlinear regression model
model: y2 ~ B * exp(A * x)
data: parent.frame()
A B
0.050 5.001
residual sum-of-squares: 0.001398
Number of iterations to convergence: 13
Achieved convergence tolerance: 5.073e-08
So either form works, but only one will give you a result that fits your
original data.
<quote>
Henri Mone <henriMone <at> gmail.com> writes:
> I want to fit to my data an exponential function with following
> functional form:
> y=exp(a*x)
>
> I used the function "nls" but this gives me exponential fits
with
> following functional form:
> y=l*exp(a*x)
>
> With "l" being an scaling factor. What do I need to change in my
R code?
>
> t.dataFitModel=nls(t.dataForFitY ~exp(a*t.dataForFitX),
> data=t.dataForFit, start=list(a = 0.01242922), trace=TRUE, algorithm >
"plinear")
Use an algorithm other than "plinear", I think (admittedly this is
not at all clear from ?nls -- you would really have to go to the
references to find out).
--
Sent from my Cray XK6
"Pendeo-navem mei anguillae plena est."