3
$\begingroup$

In fitting the following data, if I first log transform the y-values and use LinearModelFit I get a set of parameters that fits the data:

data = {{248, 0.032}, {280, 0.0498}, {327, 0.0971}, {360, 0.162}};
loggedData = ReplaceList[data, {__, {x_Integer, y_Real}, ___} -> {x, Log[y]}];
linFit = LinearModelFit[loggedData, t, t];

linFit["BestFitParameters"]

{-7.03516, 0.0144417}

However, if I instead use NonlinearModelFit on the data directly (not log transformed), I get nonsense

data = {{248, 0.032}, {280, 0.0498}, {327, 0.0971}, {360, 0.162}};
NonlinearModelFit[data, a Exp[b t], {a, b}, t]["BestFitParameters"] 

{a -> 0., b -> 1.}   

Have I found the one set of points that NonlinearModelFit cannot handle? It seems that any other exponential data I feed in can be fit just fine by NonlinearModelFit. Are there any additional directives I can give to NonlinearModelFit to get a sensible result?

$\endgroup$
  • $\begingroup$ This is another case of having to give reasonable starting values when you have a function that depends exponentially on the parameters (cf. this). Try NonlinearModelFit[data, a Exp[b t], {{a, 0}, {b, 0}}, t]["BestFitParameters"] and you will find that it works correctly. $\endgroup$ – Oleksandr R. Mar 5 '13 at 13:41
6
$\begingroup$

Add Method -> "NMinimize" to the NonlinearModelFit call.

data = {{248, 0.032}, {280, 0.0498}, {327, 0.0971}, {360, 0.162}};
NonlinearModelFit[data, a Exp[b t], {a, b}, t, 
                  Method -> "NMinimize"]["BestFitParameters"]

{a -> 0.000783053, b -> 0.0147985}

The fit looks good:

Show[ListPlot@data, Plot[a Exp[b t] /. fit, {t, 248, 360}]]

enter image description here

See this answer for more details on how the NMinimize method works.

$\endgroup$
  • $\begingroup$ Ahh, it seems my problem is having Mathematica 7! Thanks for the tip. $\endgroup$ – joshsilverman Mar 5 '13 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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