No BSD License  

Highlights from
fitlin

2.0

2.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.27 KB File ID: #20352

fitlin

by Angelini Federico

 

19 Jun 2008 (Updated 23 Jun 2008)

linear analythic least squares fit

| Watch this File

File Information
Description

Linear fit using least squares analythic computations. X is the independent variable, Y is the dependent variable, is the vector of the standard deviations of Y. The errors on a and b are calculated, too. The fit procedure weights each Y data with its own variance, so that points with big variance have a little influence. If SY i constant, fit is possible but all points will have the same weight.
The correlation coefficient is calculated by corrcoef, so it is independent on the computed coefficients. This fit is useful when you have to know exactly what the fit does, in fact the formula is absolutely deterministic.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
23 Jun 2008 John D'Errico

Um, all of the many linear least squares tools in Matlab are "absolutely deterministic". So that claim by the author is a bit silly. Why be proud of something so trivial?

More importantly, the code uses a poor scheme for the computations. The method used will be inaccurate when the problem is ill-conditioned. (Yes, ill-conditioning can be an issue even for a linear model when you have a weighted regression.)

The help could use some serious improvement. It lacks an explicit list of the variables, showing the order they appear. Nor does it have an example of use. Many users find an example a big help when they try to use a tool.

The help completely fails to describe the many output variables. What, for example, might the 4th output variable tell you? I don't feel like guessing, and the variable name is not terribly illuminating.

As for the code itself, besides using a poor methodolgy for the regression, the author provides only a single error check, one which in fact is a poor choice. If you call this code with vectors of data, one of which is a row vector, the other a column vector, the code produces an error. Better code would realize that both are vectors. Since the help only specifies that the inputs must be vectors, a user will be confused when they get an error for a valid set of data as defined by the help.

Next, no error check was provided for a singular problem, a far more important check to provide.

One of the lines in the code lacks a semi-colon, so it dumps stuff to the screen when you run it.

There are no internal comments in the code, so anyone who wants to learn what the code does by reading it had better already know what the author intended.

Oh, by the way, you don't need a return statement at the end of your functions.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
fit Angelini Federico 22 Oct 2008 10:06:38
linear Angelini Federico 22 Oct 2008 10:06:38
regression Angelini Federico 22 Oct 2008 10:06:38
analythic Angelini Federico 22 Oct 2008 10:06:38
mathematics Angelini Federico 22 Oct 2008 10:06:38

Contact us at files@mathworks.com