2
$\begingroup$

I have a large data set of different values of time. I want to make

1) a histogram

2) fit an exponential function of form A+B*exp(-t/b) from the data

To my understanding, this is how I'd do it

data=ReadList[...]

Histogram[data]

To fit equation

NonlinearModelFit[data, A + B*Exp[-t/y], {B, y, A}, t]

Is this how you would correctly do this? Because I am not getting the correct value for one of the parameters (y) and I'm not sure why

Edit: I don't want to post the dataset but it is VERY large (~44,000 entries). Essentially I want to find parameter y, which I know the known value. I'm trying to prove b by using data from experiment

edit: I tried using Import but it crashed mathematica

$\endgroup$
  • 1
    $\begingroup$ What you do basically looks correct. I think you will likely get more and more helpful answers when you provide the data (or a link to it) for which NonlinearModelFit does not work. $\endgroup$ – Albert Retey Oct 3 '18 at 7:18
  • $\begingroup$ Import instead of ReadList $\endgroup$ – Αλέξανδρος Ζεγγ Oct 3 '18 at 10:46
  • $\begingroup$ Just a sample of 20 data points will do. Also, a plot of the data might even help diagnose the problem: ListPlot[data]. $\endgroup$ – JimB Oct 3 '18 at 12:57
  • $\begingroup$ The default starting values are all 1.0 for parameters B, y, and A. If those starting values are far away from the maximum likelihood estimates, then there certainly could be convergence issues. (And you might want to avoid uppercase letters to start variable and function names in Mathematica.) Since you know what y should be, putting that in for the starting value would help. Having better starting values for B and A would help, too. Maybe using {A,Min[data[[All,2]]]} would be appropriate. But as stated before giving a few data points would really help us help you. $\endgroup$ – JimB Oct 3 '18 at 16:46
2
$\begingroup$

I have encountered the same problem. In my case, using FindFit gave better results. For example:

data = Table[{t, 3 + 1 Exp[-t/2] + 0.1 RandomReal[]}, {t, 0, 10, .25}];
model = A + B Exp[-t/y];
fit = FindFit[data, model, {A, B, y}, t]
Show[Plot[model /. fit, {t, 0, 10}], ListPlot[data, PlotRange -> All]]

Hope that could help you, Ofek.

$\endgroup$
  • 2
    $\begingroup$ For the example you give NonlinearModelFit gives the same result as FindFit for me. So I think the OPs problem is probably specific to the data he uses... $\endgroup$ – Albert Retey Oct 3 '18 at 7:28
  • 1
    $\begingroup$ @Jeffrox, if you want, you could add your data set and I could look into it more specifically $\endgroup$ – Ofek Peretz Oct 3 '18 at 8:00

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.