LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Negative values for residue in curve fitting - why?

Hi.  I'm using the curve fitting vi in Labview 8.0.  I'm doing an unweighted fit, and I get negative values for the "residue".  I get negative values for all three curve fitting methods:  least squares, least absolute residual, and turkey bisquare.  The "residue" is supposed to be weighted mean square error for the least square and bisquare methods.  I can't figure out how this could possibly be negative if it's squared.  I looked at the equations in the help file and here (https://www.ni.com/en/shop/labview/overview-of-curve-fitting-models-and-methods-in-labview.html) and it looks like all the numbers are squares and should be positive.

  Can anyone give me an idea of what I'm missing?

 

Thanks 

0 Kudos
Message 1 of 10
(4,508 Views)

bchampine,

 

Can you please post an example vi with negative values for the residue.  This may help others (myself included) in understanding what is going on.  Regards, -SS



0 Kudos
Message 2 of 10
(4,474 Views)

  Hi.  Thank you for the offer to help.  What would you like for me to post on here exactly?  The vi I have written takes data from instrumentation, performs the curve fit, and then writes the output to an output file.  It wouldn't be able to run if it didn't have the associated instrumentation.

  I'm self taught on LabView, so I only have learned how to do what's needed to make my programs and instruments do what I want.  I haven't learned anything about sharing the VIs or results. 

 

Thank you,

 

Brian 

0 Kudos
Message 3 of 10
(4,460 Views)

Click on Add Attachments when you reply to this messsage and attach a copy of your vi.  I would copy the vi after runing it once and change any input parameters to a constant that way we should be able to reproduce the behavior the way you see it.

 

There are many self taught labview uses on the forums.  Regards,  -SS

 

Message Edited by ShotSimon on 04-08-2009 04:26 PM


0 Kudos
Message 4 of 10
(4,454 Views)

Hello,

 

If you could post your VI or even screen shots of the code, that would be great to see how this is happening.

 

Thanks,

 

Anna K.

National Instruments
0 Kudos
Message 5 of 10
(4,431 Views)
I just did some tests creating 2 arrays with a sort of linear fit and calculated the residual using the Curve Fitting. In some cases I got negative values but it is fine. I am not sure how you calculate the residual but the one that comes out of Curve Fitting is not the mean square error so it does not have to be negative. Actually its the Sigma(Y-y) where Y is f(x) of the fit and y is the real f(x). So basically an optimal fit will give you a zero residual and a good fit will give you a residual close to zero but it could be either negative or positive. Hope this is what you looking for.
0 Kudos
Message 6 of 10
(4,423 Views)

Mathematically, the residue can only be negative is the weight is negative.

 

The residue is the sum of the squared differences between y(data) and y(fit) (=always positive! or absolute difference, also positive, depending on the method.) multiplied by the weight and divided by N (always positive!).

 

Could it be you have some inputs wired wrong? The nonlinear fit VIs have the code exposed, and they explicitly take the absolute values of the weight for protection. I don't know if the linear fit does the same.

Message Edited by altenbach on 04-09-2009 09:43 AM
0 Kudos
Message 7 of 10
(4,415 Views)
I think what you are refering to is the mean square error.Here is a set of points which gives a negative residual.
0 Kudos
Message 8 of 10
(4,405 Views)

Don't confuse "residual" and "residue". The residual is the difference between signal and fit, and is actually an array of three elements in your case. Look at the dynamic data instead of coercing it to a scalar DBL.

 

from the help:

 

residualReturns the difference between the original data and the best fit.

Message Edited by altenbach on 04-09-2009 11:21 AM
0 Kudos
Message 9 of 10
(4,386 Views)

Hi all.  Thank you for the replies.  I tried today to do as recommended and change the variables to constants for posting here.  The trouble is that the program take a long time to run and acquire the data, or else it's random rather than linear.  After messing up a few times, I had run out of time.  Hopefully I can post something here on Monday night.

 

Thanks,

 

Brian 

0 Kudos
Message 10 of 10
(4,372 Views)