Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I was trying to fit a set of data onto a logistic equation, however it ended up telling me that the initial value when $t=0$ is greater than the maximum limit, thus I am led to believe that it isn't working.

My approach:

Here are the data points with the top row being day and the second row being height (cm)

$\begin{matrix}7&14&21&28&35&42&49&56&63&70&77&84\\17.93&36.36&67.76&98.1&131&169.5&205.5&228.3&247.1&250.5&253.8&254.5\end{matrix}$

I put them into mathematica by the following:

points={{7,17.93},{14,36.36},{21,67.76},{28,98.1},{35,131},{42,169.5},{49,205.5},{56,228.3},{63,247.1},{70,250.5},{77,253.8},{84,254.5}};

I need to fit this data into this equation

$\frac{C}{1+\frac{C-N_0}{N_0}e^{-rt}}$, where $C$ is defined as the maximum possible height, $N_0$ is the height when $t=0$, $r$ is some constant, $e$ is Euler's Constant and $t$ is time

Since $C$ and $N$ are already used by mathematica, i used $c$ and $n$

FindFit[points,c/(1+((c-n)/n)*E^(-r*t)),{c,n,r},t]

The output was:

{c->163.363, n->653566, r->236.408}

What have I done wrong to get these values? Also I am positive I have the correct equation as this is what the assignment tells us is the equation and all the other questions work. (Although they are a different style and we are given $N_0$ and $C$ in those ones)

My expected output for $C$ and $N_0$ I believe is around

{c->256, n->9}

However I am unsure about $r$ but believe it to be under $1$ and positive

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

This is quite common a problem when doing nonlinear fit. As far as I know, the most general and effective solution for it is to give the fitted parameters a good enough start value, which you've already known for your specific problem:

exp = c/(1 + ((c - n)/n)*E^(-r*t));
FindFit[points, exp, {{c, 256}, {n, 9}, r}, t]
Show[Plot[exp /. %, {t, 7, 84}], ListPlot@points]
{c -> 261.04, n -> 12.3092, r -> 0.0877072}

enter image description here

share|improve this answer
    
Thanks, i didn't know you could give the variables a rough starting value. –  user9053 Feb 21 at 11:07
add comment

If "diagnostics" or standard errors are required you can use NonlinearModelFit with the starting values:

fun = c n/(n + (c - n) Exp[-r t]);
nlm = NonlinearModelFit[points, fun, {{c, 256}, {n, 9}, r}, t]

Visualizing fit:

Show[ListPlot[points], Plot[nlm[t], {t, 0, 90}]]

enter image description here

You can get model:

nlm//Normal

yielding

3213.19/(12.3092 + 248.73 E^(-0.0877072 t))

You can look at model properties:

nlm["Properties"]

For example:

nlm["AdjustedRSquared"]

yields 0.999586.

Or

nlm["ParameterTable"]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.