Dec-08-2025, 10:02 PM
(This post was last modified: Dec-09-2025, 04:00 PM by willflanagan.)
Our team is using scipy.optimize.curve_fit to return least-squares fitting and I am unable to return the "textbook uncertainties" that I expect. In fact, the uncertainty on the slope seems to be incorrect by exactly a factor of 1.5.
My toy example is three data points with only uncertainty on the y values:
(0,0+-1)
(0,1+-1)
(1,1+-2)
The best fit returned is 0+0.2x, which is correct based on my by-hand and excel calculations (attached). The uncertainty on the y-intercept is 1.0, which is also what I expect. The uncertainty on the slope is 0.8944271909999176 (python) rather than 1.341640786 (excel/hand calculations) which is a factor of exactly 1.5 to 10 digits.
I'm referencing the formulas in problem 8.19 in John Taylor's 'An Introduction to Error Analysis'.
This is a toy problem to make sure we trust the package. We will be using more points and higher-order polynomials.
Any suggestions? Thanks in advance for your time and help.
My toy example is three data points with only uncertainty on the y values:
(0,0+-1)
(0,1+-1)
(1,1+-2)
The best fit returned is 0+0.2x, which is correct based on my by-hand and excel calculations (attached). The uncertainty on the y-intercept is 1.0, which is also what I expect. The uncertainty on the slope is 0.8944271909999176 (python) rather than 1.341640786 (excel/hand calculations) which is a factor of exactly 1.5 to 10 digits.
I'm referencing the formulas in problem 8.19 in John Taylor's 'An Introduction to Error Analysis'.
This is a toy problem to make sure we trust the package. We will be using more points and higher-order polynomials.
Any suggestions? Thanks in advance for your time and help.
Attached Files
LinearLeastSquaresExample.xlsx (Size: 205.19 KB / Downloads: 1)
