# Find best equation for data and the area under curve

How can I find the best formula that describe the following Figure and also find the area under the curve (the numerical value):

The data for the figure can be found here:

https://pastebin.com/gz1jcRYR

I tried the following code to try to answer the part of the best equation:

fit = FindFormula[data, x, 1, "Score"]; ListPlot[data] Show[ListPlot[data], Plot[First@fit, {x, 60, 90}, PlotRange -> All]] Plot[First@hi, {x, 60, 90}, PlotRange -> All]

but I get this fit which is not correct:

Edit: This is an edit after the great answer of @JimB and is only intended for clarification. If I have the following image:

For some reason it is not possible to generate use the same code in the answer to get the fit for this curve which is similar to the first one from my question: What would be the modification to also fit this curve? (I am guessing it must be something really small but I cannot figure it out). PS: The data for this image is not provided as it is very large.

• For the second curve you'll need different starting values. Use {{r1, 0.62}, {r2, 0.01}, {r3, 2}}. – JimB May 6 '20 at 22:02

A curve that is a multiple of a gamma distribution seems to fit:

r0 = Max[data[[All, 1]]] + 0.0001;
nlm = NonlinearModelFit[data, r1 E^(-((r0 - x)/r2)) r2^-r3 (r0 - x)^(-1 + r3),
{{r1, 0.004}, {r2, 6}, {r3, 1}}, x]
Show[ListPlot[data, PlotStyle -> {{Yellow, PointSize[0.02]}}],
Plot[nlm[x], {x, 60, 90}, PlotStyle -> {{Thin, Red}}]]


area = NIntegrate[nlm[x], {x, Min[data[[All, 1]]], Max[data[[All, 1]]]}]
(* 0.0032272530500799448 *)

• +1 , I think, for calculation of the area, the integral over interpolated data should be a little bit more exact. Integrate[ Interpolation[DeleteDuplicates[dat, #1[[1]] == #2[[1]] &]][x], {x, dat[[Length[dat], 1]], dat[[1, 1]]}]  yields 0.00323111  . – Akku14 May 6 '20 at 6:17
• Thank you so much @JimB !. This is a great code. How did you know it was fitted by a multiple gamma distribution? Is there anyway that mathematica can tell you this or give the equation?. For example a code that will give r1 E^(-((r0 - x)/r2)) r2^-r3 (r0 - x)^(-1 + r3) with its parameters. – John May 6 '20 at 15:17
• How did I know? I didn't. But having 40+ years as a statistician certainly help me guess. I must say that I don't believe the "data" is real and must have been generated from a formula. Did someone create a puzzle for you to solve? – JimB May 6 '20 at 16:40
• @JimB, thanks I appreciate your answer. And no, it is not a puzzle. I generated this with a series of calculations and I just needed an equation or model to fitted. My question was only meant to know if there is a way that Mathematica will give the equation of the gamma function that you so kindly provided. – John May 6 '20 at 16:48
• @JimB I added some other image which is very close to the first image but for some reason I cannot applied the same code to this one. Could you tell me what I should modified to correctly applied it in this case? .The error I get for this new figure is: NonlinearModelFit::nrlnum: The function value {4.624912212499748*10^457+4.484830123606231*10^456 I,4.619085769989370*10^457+4.479180155848275*10^456 I,4.610359918822954*10^457+4.470718598446281*10^456 I,<<45>>,... is not a list of real numbers with dimensions {17888} at {r1,r2,r3} = {1.35271,-2048.65,-62.0308}.` Thank you – John May 6 '20 at 16:50