How to fit with errors of measurement in scipy curve_fit?

Viewed 256

I have a dataset of (x,y,dy) where dy is the errors of measurement of y (i.e., y +/- dy). I would like to fit a function func with scipy curve_fit by using dy as the weight. Do I use curve_fit(func,x,y,sigma=dy)? I found some answers using sigma=1/dy**2 as well. So, which one should I use? Thanks!

1 Answers

From the docs:

sigma : None or M-length sequence, optional

If not None, the uncertainties in the ydata array. These are used as weights in the least-squares problem i.e. minimising np.sum( ((f(xdata, *popt) - ydata) / sigma)**2 ) If None, the uncertainties are assumed to be 1.

The sigma is already squared in the loss function, (what curve_fit essentially does is a least_squares algorithm).

Rigurously speaking, dimensional analysis says you should use the absolute sigma (not the square). In practice, you can use the sigma_square if you want, it will tend to ignore outliers more.

Related