Linear curve fitting with errors

假如想象 提交于 2019-12-04 04:57:57

The very useful book Numerical Recipes provides a method to fit data to a straight line, with uncertainties in both X and Y coordinates. It can be found online in these two versions:

The method is based on minimizing the χ2 (chi-square) which is similar to the least-square but takes into account the individual uncertainty of each data point. When the uncertainty σi is on the Y axis only, a weight proportional to 1/σi2 is assigned to the point in the calculations. When the data has uncertainties in the X and Y coordinates, given by σxi and σyi respectively, the fit to a straight line

y(x) = a + b · x

uses a χ2 where each point has a weight proportional to

1 / (σ2yi + b2 · σ2xi)

The detailed method and the code (in C or Fortran) can be found in the book. Due to copyright, I cannot reproduce them here.

It seems that the least squares (LS) method is indeed a good direction. Given a list of x & y, the least squares return values for m & b that minimize $$\sum_{i} (m*x_{i}+b -y_{i})^{2} $$.

The benefits of the LS method is that you will find the optimal values for the parameter, the computation is fast and you will probably be able to find implantation in java script, like this one.

Now you should take care of the margins of errors that you have. Note that the way that you treat the margin of errors is more of a "business question" than a mathematical question. Meaning that few might choose few treatments based on their needs and they'll all be indifferent from mathematical point of view.

Without more knowledge about your need, I suggest that you will turn each point (x,y) into 4 points based on the margins. (x+e,y+e), (x-e, y+e), (x+e, y-e), (x-e,y-e).

The benefits of this representation is that it is simple, it gives way to the end of the margin boundaries that are typically more sensitive and the best of all - it is a reduction. Hence, once you generate the new values you can use the regular LS implementation without having to implement such algorithm on your own.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!