Re: Fitting data on a vertical line
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1563] Re: Fitting data on a vertical line
- From: beretta at ATHENA.MIT.EDU (Robert K Beretta)
- Date: Sat, 24 Jun 1995 06:19:17 -0400
- Organization: Massachusetts Institute of Technology
In article <3sd9dm$n5n at news0.cybernetics.net> phpull at unix1.sncc.lsu.edu (Joe Wade Pulley) writes: >Hello, > I have recently accidentally asked Mathematica to do a linear >least squares fit to a set of data which were exactly vertically >placed. Instead of giving me an error or an infinite slope, >Mathematica spits out some sort of fit which is totally wrong. >For example, if I make up a list of data which is similar to mine, I >get the following results. > > >In[1]:= >ls={{2.1,3},{2.1,4},{2.1,5},{2.1,6},{2.1,7}} > >Out[1]= >{{2.1, 3}, {2.1, 4}, {2.1, 5}, {2.1, 6}, {2.1, 7}} > >In[2]:= >ft=Fit[ls,{1,x},x] > >Out[2]= >0.924214 + 1.94085 x > >Obviously, this equation does not "fit" the data I have given. The >equation x=2.1 would. Can anyone explain this very unusual behavior. Joe, I do not believe that the return value is totally wrong. When a least squares fitting method is applied to a data set with n values for the same coordinate, the method will average the values at that coordinate and multiply the weight of the particular datum by n. If we look at the value of the Fit function with x set to 2.1, we see that it is equal to the average of the datum values. In[1]:= ls={{2.1,3},{2.1,4},{2.1,5},{2.1,6},{2.1,7}}; ft=Fit[ls,{1,x},x] Out[2]= 0.924214 + 1.94085 x In[3]:= ft /. x->2.1 Out[3]= 5. Thus, the function ft provides the best fit possible for the solitary coordinate x = 2.1, which is the only point where any information is available. Since the slope of the function described by the data is indeterminate (it is no more Infinity than -Infinity) Mma returned ... something else for the slope. Honestly, I would have expected an "indeterminate" error message from this calculation, or maybe a more recognizable function, like "5.0 + 0.0 x". But really, the function ft is just as "right" as any other function that is equal to 5.0 at x = 2.1. For what it's worth, Bob Beretta beretta at mit.edu