# How to calculate the uncertainty of a fit function? [closed]

I'm doing research on nuclear physics. What I will be asking is actually some general question.

Suppose that I have a set of data with 8 points x={x0,x2...,x7} (in my example, x-axis is transverse momentum), y={y0,...,y7}, and statistical error bars ey={ey0,...ey7}. Using any software that is based on least $$\chi^2$$ method (for example, CERN ROOT) and is fed with some fit function $$f(x;\vec{p})$$ (here, let's assume we have 4 parameters), we would get the precise value of p={p0,p1,p2,p3} and their uncertainties err_p={errp0,errp1,errp2,errp3}.

Now here's the question, how can I draw a band that specifies the statistical uncertainties of this fit function, as illustrated by the red band? Please also give the underlying reason briefly, or maybe some paper that documented this problem well.

• there isn't such option to downscale images on SE Jul 6 '19 at 17:48
• Have to vote to close this question since it really isn't a physics question. It's a question about how to use some curve fitting & plotting software that you haven't specified. The answer depends on the particular software package that you're using. I usually use Mathematica, so personally I would pose the question on a Mathematica users forum if I had such a question. Look up the relevant users forum for the particular software that you use.
– user93237
Jul 6 '19 at 17:55
• @SamuelWeir, Sorry. Most software and most people use least $\chi^2$ method inherently, so it's software-independent. Actually, it's more of a theoretical statistics question, rather than some software technique question. Jul 6 '19 at 18:06

There exists a norm, which describes exactly how one does this in industry. This norm ist called "ISO / IEC 98-3; Uncertainty of measurement — Part 3: Guide to the expression of uncertainty in measurement". Though I didn't have the time to read the norm, yet, I was told that it is done as follows:

If you have the 95% confidence intervals of each of the four fit-parameters, you can use the following steps:

1. Assume a distribution for each fit-parameter. For example, if the 95% confidence interval of the first fit-parameter if $$[10, 80]$$ you can assume a normal distribution. Thus the mean value of the first fit-parameter would be $$\mu_1=(80-10)/2 = 45$$ and its standard deviation is equal to $$\sigma_1=(80-10)/4 = 22.5$$ -- the later is valid, because the 95% confidence interval covers approx. the values from $$-2\sigma$$ to $$+2\sigma$$. Thus for the first fit-parameter you draw a random number from $$N(\mu_1, \sigma_1^2)$$.
2. Proceed like this for each of the four fit-parameters.
3. If you have a set of four random numbers (one for each fit-parameter) you use your fit function to calculate the value using these four randomly generated parameters.
4. Repeat step 1 to 3 many times. Thus you obtain many "randomly generated data-points".
5. Finally calculate the 95% confidence interval of your randomly generated data-points and draw them onto the graph.
• Yes, thanks. However, I have this method in my mind, but how do you know that these 4 parameters are independent (that's what I and my advisor are worrying about)? This way of "sampling" seems to me that it's implying 4 parameters got to be independent, and thus can be randomly generated separately.@Semoi Jul 6 '19 at 21:49
• @collin. You should get a covariant matrix from your fit. Look at the off-diagonal elements: their size will tell you how correlated the parameters are. The formal solution is to find the eigenvectors of that matrix (independent by definition) and vary each of those. Jul 6 '19 at 21:54
• @BobJacobsen Hi Bob, do you happen to know any documents that tells the principle of extracting the covariance matrix? Not a lot of people need it, so I currently find it hard to find one. That being said, according to what you said, after I get the eigenvectors, I will have 4 new "parameters", and then I will apply Semoi 's method to the 4 new "parameters", right? Jul 6 '19 at 22:58
• Some ROOT sample code: root.cern/doc/v610/rf607__fitresult_8C.html. See also root-forum.cern.ch/t/how-to-get-covariance-matrix/21250/2 Jul 7 '19 at 0:56
• Jul 7 '19 at 1:00