Scilab Home Page | Wiki | Bug Tracker | Forge | Mailing List Archives | Scilab Online Help | File Exchange
ATOMS : fitters details
Please login or create an account

fitters

Polynomial and multiple linear regression
(2509 downloads for this version - 2509 downloads for all versions)
Details
Version
1.0
Author
Javier I. Carrero
Owner Organization
Unal
Maintainer
Javier Carrero
License
Creation Date
November 9, 2010
Source created on
Scilab 5.2.x
Binaries available on
This toolbox is in the process of being built
Description
            The fitters module contains two scilab functions
polyfit.sci: polynomial regression
linfit.sci:  linear regression over multiple independent variables
            
Files (1)
[304.37 kB]
Source code archive

News (0)
Comments (11)     Leave a comment 
Comment from Michael Baudin -- November 10, 2010, 01:10:52 PM    
Hi,

Does the linfit function satisfy the same API as Matlab/linfit : 
http://www.mathworks.com/help/toolbox/stats/nlinfit.html

Do you have examples using your functions ?

Best regards,

Michaël Baudin
Comment from Javier Carrero -- November 10, 2010, 04:36:35 PM    
Well in brief

-Matlab's nlfit is based on the Levenberg–Marquardt algorithm (LMA), which is an
iterative
procedure. Therefore its results depend on the choice of parameters for the convergence of
the method. LMA can be applied to linear problems (which are a particular case of the
general non-linear problems), but it is possible that different choices of parameters
produce different sets of coefficients for the same data set.

-linfit is a non-iterative procedure based on the analytic solution of the equations
resulting from the application of the minimum conditions. It allways produce the same
result, and does not require an initial estimation of the values of the parameters. But it
does not solve non-linear problems.

Comment from Javier Carrero -- November 10, 2010, 05:06:39 PM    
Sorry, it wasn't my intention to use the same name as your code, simply I wasn't aware of
the existence of another polyfit in stixbox. Since no polyfit appears in Scilab's help I
assumed there wasn't one, and I didn't checked Git/stixbox. I chose the name trying to
make it clear it has the same purpose as the Matlab's polyfit.

Comparing the two codes I realized that the results seems to be the same, but my
implementation offers two options for the output, a Scilab polynomial object or a matrix
ordered as in Matlab, besides graphic comparison.

Given that the purpose of linfit and polyfit seems to fit ;) in Git/stixbox I would
suggest in incorporate them into that project.
Comment from Bb Aa -- May 30, 2011, 10:22:16 AM    
Hi,
can you please tel me haw can i use this package to use polyfit function, I am working
with Scilab for 1 weak a go.
thanks 
Comment from Bb Aa -- May 30, 2011, 10:22:34 AM    
Hi,
can you please tel me haw can i use this package to use polyfit function, I am working
with Scilab for 1 weak a go.
thanks 
Comment from Bb Aa -- May 30, 2011, 11:06:21 AM    
please help me, I don't know haw can I install this fitters zip!!!!!
Comment from Bb Aa -- May 30, 2011, 11:06:26 AM    
please help me, I don't know haw can I install this fitters zip!!!!!
Answer from Javier Carrero -- May 30, 2011, 09:47:16 PM    
> please help me, I don't know haw can I install this fitters zip!!!!!
Sorry but installation with atoms is not possible, it seems that the module was never
packaged after I uploaded it. Anyway the documentation (manuals in pdf format) is in the
docs folder, and the functions are in the files linfit.sci and polyfit.sci. Therefore you
can load the functions in memory by executing these files after unzip fitters.zip. The
usage is described in the manuals.
Best regards
Javier 
Comment from Luis Botello -- February 26, 2015, 03:42:29 PM    
Great tool. Thanks Javier
Comment from Gabriel Maciel -- July 8, 2015, 04:57:07 PM    
I Found a possible issue in this function.
The code below works
x=[-6e6 0 6e6]; y=[-65.0155 0 65.0155]; p=polyfit(x,y,2)
but if you change to
x=[-6e9 0 6e9]; y=[-65.0155 0 65.0155]; p=polyfit(x,y,2)
There is an error: Division by xero. It should work for both cases.
Answer from Javier Carrero -- September 4, 2015, 05:50:54 PM    
This answer has been deleted.
Answer from Javier Carrero -- September 4, 2015, 06:00:11 PM    
Sorry for this late reply.
You are right, it seems this behavior is related with the use of the qr algorithm (line
177), but I have not found a solution yet. I will keep you informed. 
Comment from Michael Baudin -- February 27, 2016, 11:30:28 AM    
Hi,

There is already a "polyfit" in Stixbox, which has full help page, unit tests and
 
interesting options such as the statistical analysis of the residuals. 

So what are the advantages of your module on this topic ?

For the error of Gabriel, Stixbox's polyfit works, although it produces a Warning, 
due to the bad scaling of the input x :

-->x=[-6e9 0 6e9]; y=[-65.0155 0 65.0155]; p=polyfit(x,y,2)
Warning : matrix is close to singular or badly scaled. 
 p  =
 10^(-20) *
    1.268D-14    1.084D+12    0.  

A possible solution is to scale the input x by dividing by the maximum absolute value 
of the input :

-->scale=max(abs(x))
 scale  = 
    6.000D+09   
-->z=x/scale; 
-->p=polyfit(z,y,2)
 p  = 
  - 5.263D-15    65.0155    0.   

To evaluate the polynomial, all you have to do is to rescale the input :

-->y = polyval(p,x/scale)
 y  = 
  - 65.0155    0.    65.0155  

This works because drastically reduces the orders of magnitude inside Vandermonde's 
matrix, making the problem much easier to handle : all entries are in [-1,1]. (In 
your particular example, the data has already been scaled so that the mean is zero.) 

Matlab's solution for scaling is to handle the mean and the standard deviation of x 
with the mu parameter. I will had this to Stixbox's polyfit/polyval.

Best regards,

Michaël
Answer from Javier Carrero -- February 28, 2016, 06:11:04 PM    
After considering the facts I think Stixbox's polyfit is better than my proposal (that
anyway dates back to five years ago and is almost forgotten). In other words, I agree on
using Stibox.
However, being part of a module puts it in disadvantage with Matlab's polyfit, which comes
with its standard installer. Many users don't have the time or the inclination to deal
with additional modules and go to Matlab when they don't find polyfit.
By the way the Stixbox URL seems empty. 
(http://forge.scilab.org/index.php/p/stixbox/doc/)

Answer from Javier Carrero -- February 28, 2016, 06:11:34 PM    
After considering the facts I think Stixbox's polyfit is better than my proposal (that
anyway dates back to five years ago and is almost forgotten). In other words, I agree on
using Stibox.
However, being part of a module puts it in disadvantage with Matlab's polyfit, which comes
with its standard installer. Many users don't have the time or the inclination to deal
with additional modules and go to Matlab when they don't find polyfit.
By the way the Stixbox URL seems empty. 
(http://forge.scilab.org/index.php/p/stixbox/doc/)

Leave a comment
You must register and log in before leaving a comment.
Email notifications
Send me email when this toolbox has changes, new files or a new release.
You must register and log in before setting up notifications.