# Fitting an equation to data set, am I doing this right?

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

• 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. – Albert Retey Oct 3 '18 at 7:18
• Import instead of ReadList – Αλέξανδρος Ζεγγ Oct 3 '18 at 10:46
• Just a sample of 20 data points will do. Also, a plot of the data might even help diagnose the problem: ListPlot[data]. – JimB Oct 3 '18 at 12:57
• 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. – JimB Oct 3 '18 at 16:46

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}];

• 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... – Albert Retey Oct 3 '18 at 7:28