# Choosing Analytic Functions to Fit to Data

I have three separate datasets that I would like to fit separate analytic distributions to. Disclaimer, I am a physicist so I don't have too thorough background in statistics, and so I am basically wondering (a) whether it is possible to fit any analytic functions to these data, especially for the second dataset (with it's vaguely sinusoidal wiggle at the start)? (b) if so, what are the PDFs that I should be trying in each case and what is the art to correctly choosing a distribution that models the data well? (these curves represent efficiency (y-axis) of a measurement a particle’s lifetime to be a certain value (x-axis))

For the first dataset, I had thought of something like sigmoid function as it looks vaguely s-shaped to me, is there a more suitable function?

For the second dataset it generally looks logarithmic to me except for the area between 0 and 0.5 which is my main issue, not sure what to suggest for this one or whether it will even be possible to model this?

With the third dataset, it basically looks exponential, so I have tried fitting an $\exp(-t/\tau)$ distribution to it (leavin $\tau$ as a floating parameter) with limited success ( $\chi^{2} \approx 3$), so I'm wondering whether I should be multiplying the exponential by another function?

Any help would be greatly appreciated, even if just to know that it won't be possible to analytically model these datasets! Thank you.

• Would you please post a link to the data? Commented Feb 3, 2018 at 14:43
• Hi James, the data exists as a ROOT ntuple but I can copy it into 3 text files and then post them here? Commented Feb 3, 2018 at 18:28
• OK. I will try my online curve fitting web site's "function finder" and see what kind of approximating functions turn up. Commented Feb 3, 2018 at 19:17
• @JamesPhillips Here are three links to the separate datasets. Note that dataset 2 and dataset 3 are binned so the texts files have two columns, one for the bin value (x-axis) and another for the proportion of events (y-axis). Dataset 1 - filetea.me/n3w5VFRl2bTTUeTu2G3eQ6MeQ Dataset 2 - filetea.me/n3wK81meHF2TKW4S9i8BGW2fw Dataset 3 - filetea.me/n3wzmPA4jf1TOG9EcYK4ULxnw Thanks for the help! Commented Feb 4, 2018 at 10:48
• The posted links are all returning 404 Not Found errors when I try them. Commented Feb 4, 2018 at 12:25

Let me start with the curve3 data set. I wanted to find a simple equation with few shape parameters, and since having an offset does not affect the shape of the curve I thought an offset would be OK. I saw that the first two data points in the text file had a Y value of exatly zero, and a scatterplot if curve3 showed that those data points did not appear to me as being suitable for fitting. So with those data points removed, here is my first cut at an approximating equation. If this seems OK with you as a starting point, then I will go on to the other data sets. See my images below.

y = 1.0 + a(1.0 - exp(bx)) + Offset

Fitting target of lowest sum of squared absolute error = 9.2632549963527454E-03

a = -4.4656332442476909E-01
b = -4.6962012198850023E-01
Offset = -4.9854885430392787E-01

Degrees of freedom (error): 95
Degrees of freedom (regression): 2
Chi-squared: 0.00926325499635
R-squared: 0.991409069502
Model F-statistic: 5481.58675134
Model F-statistic p-value: 1.11022302463e-16
Model log-likelihood: 315.01071945
AIC: -6.36756570307
BIC: -6.28843404556
Root Mean Squared Error (RMSE): 0.00972229449085

a = -4.4656332442476909E-01
std err: 2.26709E-05
t-stat: -9.37882E+01
p-stat: 0.00000E+00
95% confidence intervals: [-4.56016E-01, -4.37111E-01]

b = -4.6962012198850023E-01
std err: 1.36965E-04
t-stat: -4.01275E+01
p-stat: 0.00000E+00
95% confidence intervals: [-4.92854E-01, -4.46386E-01]

Offset = -4.9854885430392787E-01
std err: 2.92469E-05
t-stat: -9.21866E+01
p-stat: 0.00000E+00
95% confidence intervals: [-5.09285E-01, -4.87813E-01]

Coefficient Covariance Matrix
[ 0.23250348  0.25407089 -0.23512718]
[ 0.25407089  1.4046536  -0.49892657]
[-0.23512718 -0.49892657  0.2999435 ]


• Hi James, thanks for your help. Yes that looks great as a starting point, I will try that function myself in Roofit and see if I can reproduce your result. Commented Feb 4, 2018 at 20:46
• Did you manage to take a look at the other two curves yet? Commented Feb 6, 2018 at 21:15
• I take it that you have now finished your Roofit work. Curve2: "y = a*exp(pow(ln(x)-b,2.0)/c) + Offset", a = -5.7894615694792584E-01, b = -5.9567675026774103E-01 c = -1.7248538654572467E+00, Offset = 9.3297000151066323E-01 As for Curve1, it does not appear to have continous X data, rather it seems to be a numbered list. Commented Feb 7, 2018 at 9:43
• Yes sorry I fit with RooFit and I agree that the function models curve 3 very well. From an initial look I would say that your curve 2 functions looks good as well, I will quickly test it out in RooFit and let you know! How do you mean just a numbered list? The data is unbinned so these are just the raw xvalues, when I plot them I get the shape that I posted before? Commented Feb 7, 2018 at 11:06
• Since you asked, I used my online curve fitting and surface fitting web app zunzun.com - it has a "function finder" that fits the data to hundreds of known equations using a genetic algorithm to determine initial parameter estimates when solving non-linear equations - links to the Python source code are at the bottom of every page. FYI, the fitted surface equation plots look really cool in a web browser. Commented Feb 13, 2018 at 20:15

The displayed dynamics seems stochastic, the first graph especially. A question: why is your objective modeling the time series with deterministic functions? A time series model would be more appropriate. You are correct that the simplest time series models (ARMA / ARIMA) won't fit the data well. Also, the data are heteroskedastic: the variance increases with time. So some transformation of the form $Y(t) = X(t) / t^\alpha$ (or something more clever) might be appropriate.

Ideally, you would start with modeling $Y(t)$ using something like ARIMA + deterministic basis functions. One possible choice of the basis is $\{log(t), t^\beta, sin(\omega t) \}$.

• Hi stans, thanks for your reply. Apologies, I think I was a little unclear with my labelling of the x-axis as t. These curves actually represent efficiency curves for a measurement of a particle lifetime, so they should just be smooth analytic functions. The height just represents the efficiency of measuring that lifetime. If it looks like a time series that should be due to statistical fluctuations. The way the variance of the points increase for large t is due to the disparity of events at this tail coupled with these stat fluctuations. Is that a little clearer? Commented Feb 3, 2018 at 9:30
• @Pronitron, you are saying yourself that there are "stat fluctuations". Therefore a stochastic model is appropriate. That does not mean that the implied average value will not be smooth and deterministic. At any given time, the forecast N steps ahead will be a deterministic function of all the information available at that time. In particular, you can pretend that you are at time 0 and are forecasting T steps ahead, where T is the total length of the time series. Commented Feb 3, 2018 at 9:37
• A stochastic process would be appropriate for fitting exactly to the model but I guess I should rephrase my question a little. I basically was wondering whether it is possible to model the implied average value you mentioned accurately with an analytic function or whether it needs other methods? From your comments I assume that there aren’t analytic functions to model the aver vals of the curves? The actual curve I am trying to model is the product of all three of these, so I just wondered whether it would factorise into prod of 3 analytic functions for simplicity. I guess not right? Commented Feb 3, 2018 at 11:03
• @Pronitron, did not understand the end of your comment. However, "it is possible to model the implied average value ...with an analytic function", as I suggested. Whether the fit is "accurate" is to be determined by goodness-of-fit diagnostics after the estimation stage... Do what I suggested and you will see that the implied average curve is nice, smooth and closed-form (for the proposed choice of basis). Commented Feb 3, 2018 at 11:12
• What I meant is that the actual efficiency function that I am trying to model can be decomposed into these three functions that I have posted here, such that multiplying these three together produces the curve I am trying to model. I was struggling to model the total efficiency curve so I thought that decomposing it into these 3 might help if I could fit some analytic functions to each (then clearly the total will be product of these three analytic functions). This is the curve I am actually trying to model Acceptance Curve Commented Feb 3, 2018 at 18:55