Scaling covariance for an error calculation

In summary, the conversation is about the parameter "scale_covar" in fitting programs such as Python's lmfit or scipy, which allows for a scaling of the covariance matrix to calculate errors. When the parameter is set to True, the errors on the data are adjusted until the chi-square is 1, and the errors on the parameters are reported using these adjusted values. When set to False, scaling the errors on the data will also change the errors on the parameters. The question is when to use scaling and when not to, and if there is a generally agreed upon convention for this. It is advised to first check for any errors in the data or model before using scaling, and to discuss it explicitly if it is necessary.
  • #1
Malamala
299
27
Hello! I just discovered (maybe a bit late) that most fitting programs (Python lmfit or scipy, for example) have a parameter (by default turned on) that allows a scaling of the covariance matrix for calculating the errors (usually called scale_covar or something similar). After some reading I figured out (hopefully correctly) that setting that parameter on (scale_covar=True) means basically to adjust the errors on the data until the chi-square would be 1, and report the errors on parameters using these adjusted values. I have noticed that doing so, if you scale all the y error by the same amount the error on the parameter fit doesn't change. On the other hand if I set the parameter off (scale_covar=False), scaling the errors on y changes the errors on the parameters of the fit, too.

In my case I need ,to do a linear fit to some data. If I use scale_covar=True (which is the default) I get something around (ignoring decimals) ##25 \pm 1##. If I set it to False I get half the error ##25 \pm 0.5##. I am quite confident about the errors on my points and the fit looks good. Which value should I report? And in general, for any fit, when should I set this parameter to True and when to False?

Lastly, I don't really remember reading any experimental physics paper where they actually talk about which of these 2 methods they use to get the errors from a fit. They just state the errors on the parameters. Is there a generally agreed upon way of doing this, such that everyone is setting that parameter (in their fitting program) to True or False? And if so what is the convention.

In principle, I would like to know, if I were to publish my data in a journal (say PRL), without talking about this covariance scaling stuff (as no one does, it seems) should I use (in my linear case fit) 0.5 or 1 for the error?

Thank you!
 
Physics news on Phys.org
  • #2
If that scaling is significant something went wrong with your uncertainties.
The particle data group scales up the uncertainty if the measurements are incompatible (not sure what exactly their threshold is) and points out that it did so in the few cases where this is necessary.
 
  • #3
mfb said:
If that scaling is significant something went wrong with your uncertainties.
The particle data group scales up the uncertainty if the measurements are incompatible (not sure what exactly their threshold is) and points out that it did so in the few cases where this is necessary.
Thank you for your reply. So should I use scaling when I am not sure that my errors are correct? But in my case I am not sure what would be incompatible with what. I just have 5 data points with errors on them and I want to fit a straight line to it. I don't have 2 sets of measurements or something to compare with such that I could say that something is not compatible. But, regardless of that, could you please explain to me when one should use scaling and when not? I am not sure I understand that. Thank you!
 
  • #4
Maybe a straight line is a bad assumption or you underestimate your uncertainties on these points.
If in doubt be conservative and give the larger uncertainty.
 
  • #5
mfb said:
Maybe a straight line is a bad assumption or you underestimate your uncertainties on these points.
If in doubt be conservative and give the larger uncertainty.
But I am still not sure I understand when I should use scaling and when not. Could you explain that a bit (or point me towards some readings)? Thank you!
 
  • #6
If it is significant you should first try to find the errors in your data points or your model to describe the data points. You might fit nonsense. If you do not then the scaling shouldn't be a factor 2.
Check Anscombe's quartet. 4 datasets that all give the same straight line fit - but in three cases that fit is clearly the wrong approach. Here are more examples.

If you can't find any reason why your ##\chi^2/ndf## is so bad then it might be acceptable to use the scaled up uncertainties to get something, but you should discuss this explicitly because it means something went wrong somewhere.
 
  • #7
mfb said:
If it is significant you should first try to find the errors in your data points or your model to describe the data points. You might fit nonsense. If you do not then the scaling shouldn't be a factor 2.
Check Anscombe's quartet. 4 datasets that all give the same straight line fit - but in three cases that fit is clearly the wrong approach. Here are more examples.

If you can't find any reason why your ##\chi^2/ndf## is so bad then it might be acceptable to use the scaled up uncertainties to get something, but you should discuss this explicitly because it means something went wrong somewhere.
Thank you again for your reply! Here is my actual data that I am trying to fit:
##x = [-0.312, -0.217, -0.081, 0., 0.211]##
##y = [-8.050, -5.278 , -3.510, 0., 5.521]##
##y_{err} = [0.121, 0.218, 0.421, 0.115, 0.305]##

I also attached the plot with the fit I get. (I am using the lmfit package in python). When I use scaled covariance I am getting these parameters for the fit:
line1intercept: -0.02108874 +/- 0.20201635
line1slope: 25.6603677 +/- 0.95263756
when I don't use scaled covariance I am getting this:
line1intercept: -0.02108874 +/- 0.09520060
line1slope: 25.6603677 +/- 0.44893231

The reduced chi squared is 4.50291419. Is there something I am doing wrong? To me the fit looks pretty good (and there are some theoretical motivations for a straight fit, too). Thank you, again, for the help.

Screen Shot 2019-12-16 at 02.35.22.png
 
  • #8
The central data point is a bit over 3 standard deviations away from the fit. If you think this is a good data point and nothing went wrong with it use the scaled up uncertainties. Most likely something went wrong there, so it is better to be conservative.
 
  • #9
mfb said:
The central data point is a bit over 3 standard deviations away from the fit. If you think this is a good data point and nothing went wrong with it use the scaled up uncertainties. Most likely something went wrong there, so it is better to be conservative.
Thank you for this! I digged a bit deeper into my problem, more specifically where are my errors coming from. I have a counting measurement and I fit my points with a curve. From there I extract the centers of the peaks for different measurements and the plot I showed previously shows the difference between such centers. So the errors there come from the error on the centers of the peaks i.e. from the errors given by the fitting program (which is the same as before, lmfit). I attach below such a counting fit. I have noticed that here I have exactly the same problem as before: scaling my errors give me twice the errors on the parameters (mainly the peak center) compared to when I don't scale them. So the issue I mentioned above, I think, it's just a propagation of the issue from here. In the plot below, the errors are just Poisson i.e. square root of the number of counts. Also the fit is motivated on theoretical grounds. Do you know why do I have this problem here, in the first place when in principle, both the fit and the errors should be right? Thank you so much for your help!

Screen Shot 2019-12-16 at 20.22.42.png
 
  • #10
Your uncertainties are clearly smaller than the spread of the measurements. Something makes them spread by more than the square root of the counts. In addition the fit doesn't do a good job in the two larger peaks and it overestimates the flat area to the right of the last peak.
 
  • Like
Likes BvU

What is scaling covariance for an error calculation?

Scaling covariance for an error calculation is a statistical method used to adjust the covariance of a set of variables in order to account for differences in scale or magnitude between the variables. This is important because the covariance of two variables may be affected by their respective scales, and scaling can help to make the covariance more meaningful and comparable.

Why is scaling covariance important in scientific research?

Scaling covariance is important in scientific research because it allows for a more accurate and meaningful interpretation of the relationship between two variables. By adjusting for differences in scale, researchers can better understand the true nature of the relationship and make more accurate conclusions about their data.

How is scaling covariance calculated?

The most commonly used method for scaling covariance is the Pearson correlation coefficient, which is calculated by dividing the covariance of two variables by the product of their standard deviations. This produces a value between -1 and 1, with a value of 1 indicating a perfect positive relationship, 0 indicating no relationship, and -1 indicating a perfect negative relationship.

What are some potential limitations of scaling covariance?

One limitation of scaling covariance is that it assumes a linear relationship between the variables, which may not always be the case. Additionally, it does not account for other factors that may influence the relationship between variables, such as confounding variables or outliers. It is important for researchers to use caution and consider these limitations when interpreting the results of a scaled covariance calculation.

Can scaling covariance be used for non-numerical data?

No, scaling covariance is a statistical method specifically used for numerical data. It cannot be used for non-numerical data, such as categorical or ordinal data. In these cases, other statistical methods such as chi-square or rank correlation should be used to assess the relationship between variables.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
13
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
899
  • Set Theory, Logic, Probability, Statistics
Replies
3
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
921
  • Set Theory, Logic, Probability, Statistics
Replies
14
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
30
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
840
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
16
Views
1K
Back
Top