10-12-2010 10:47 AM - edited 10-12-2010 10:56 AM
I've encountered a problem with the "Linear Fit" function.
If I give it the following data then it returns NaN for Intercept and Gradient.
This is when set to "bisquare" method.
I can find similar examples if I use "least absolute residual" method.
"Least squares" functions fine.
x values
1
2
3
4
4
5
6
y values
-0.337
-0.234
-0.140
-0.034
0.34
0.05
0.14
This is clearly the wrong solution. If I adjust any of the y values by 0.001 then it will work.
A much simpler example of what it can't cope with is to do a "least absolute residual" through the data
x=0,0,1
y=0,0,1
10-12-2010 10:55 AM
It worked for me.
slope = 0.104823
intercept = -0.405081
I am using LV 2009 64-bit. What version of LV are you using?
10-12-2010 10:57 AM
Did you try my two attached vi examples or type the numbers in?
Labview 8.2
10-12-2010 11:16 AM
I've just been reading this: http://en.wikipedia.org/wiki/Least_absolute_deviations
It has to use a numerical method of some sort and I guess that some combinations of points combined with rounding of numbers might give nonsensical output.
Since I don't have many data points I might make my own vi to do this using:
"Checking all combinations of lines traversing any two (x,y) data points is another method of finding the least absolute deviations line. Since it is known that at least one least absolute deviations line traverses at least two data points, this method will find a line by comparing the SAE of each line, and choosing the line with the smallest SAE. In addition, if multiple lines have the same, smallest SAE, then the lines outline the region of multiple solutions. Though simple, this final method is inefficient for large sets of dat"
10-12-2010 11:37 AM - edited 10-12-2010 11:38 AM
I tried the first one, but not the second. Trying the second, I see the same thing.
If you look at the error output it is
-220055 The number of categories or samples must be greater than one.
If the repeated x-value at the beginning of the list are something other than zero, you get an answer (I tried 0.01 for the first three x-values).
10-12-2010 08:59 PM
Hi,
I think it's better not have repeated values in X array, especially when you use LV 8.2.
Linear Fit.vi uses new algorithm in LV 2009. So it is more robust than previous version. In your second example, you have 3 points but 2 of them are the same, (0, 0). This VI may not deal with this case with Least Absolute Residual method.
Best Regards,
Michael
10-13-2010 03:25 AM
I don't really have much choice what's in the array. I know I could treat it beforehand, but I would expect a curve fitting algorithm to be robust enough to deal with the data.
Because there aren't that many points I'm using my own custom least abs residual method for now.