LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to weight a linear fit with errors in x and y

Hello all,

 

I need to do a linear fit with error in X and Y, specifically, I have the standard deviation at each point.  How do I formulate the weight function?

 

Thanks,

 

Scott

0 Kudos
Message 1 of 5
(4,665 Views)

For the y-errors:

1.) take the standard deviation for each point and square it.

2.) Take the inverse of step 1, that is, x^-1

3.) Normalize such that the weights add up to one. (Divide the array by the sum of the points)

 

Use these as your weights in whatever vi you are using to fit.

 

I do not know whether LabVIEW has VIs for including errors in X. You may have to write something yourself.

 

Cheers,

mcduff

0 Kudos
Message 2 of 5
(4,652 Views)

Your comments are much appreciated - though I had sussed out your steps 1-3.  It is working the problem for both x and y errors that is the trick!

 

Thanks,

 

Scott

0 Kudos
Message 3 of 5
(4,629 Views)

The standard model for doing fits (least squares) generally assumes that the X values are "known" (or ,precise not to be an issue) and the only variation is in Y. You derive a fitting function for Y as a function of X, and the math is fairly straight-forward and derivable.

 

When both X and Y vary, the math becomes much more complicated.  About a decade ago, I had such an issue, went to a colleague in the Math department who lent me a book on the subject that I barely understood (sorry, I don't recall its name), and (unfortunately) I never did fully understand the issue.

 

If this is something you need to do, you might consider asking a mathematician or statistician, but be warned that the answer (compared to Least Squares) will not be simple ...  [I recall the term "covariance matrix" figured in there somwhere ...]

 

Bob Schor

0 Kudos
Message 4 of 5
(4,597 Views)

As per Numerical Recipes for instance, your weight function for each point should be 1/(s_y_iˆ2 + b^2* s_x_iˆ2), where your equation is y = a + bx and s_x_i and s_y_i are the standard deviation of x_i and y_i respectively. Notice the parameter b above in the formula for the weight: the weight needs to be updated at each iteration of the minimization algorithm.

The main issue you will have is that the algorithms used in LabVIEW are not designed to minimize a chiˆ2 function in which one of the parameters is present in the weight function of each data point (as it is in the formula above).

The good news is that for a linear fit, the simplest algortihm is relatively straightforward to implement (again, NR is a good source) but it still needs to be implemented.

0 Kudos
Message 5 of 5
(4,585 Views)