>> I am looking for statistics modules to enable me to fit trendlines to
>> charts. I am thinking of linear regression, logrithmic, exponential, power
>> and moving averages. I found a module called Statistics OLS dated 1998.
>> Before I continue to look for modules I thought I would ask the community
>> for their experiences and suggestions.

I looked for similar about 3 or 4 months ago, but found nothing in Perl itself.

I did find a load of websites about CurveFitting, and some software, but the
only source I found was a very frightening page of JavaScript that fit any
arbitrary formula, but the code was obfuscation gone mad -
http://members.aol.com/johnp71/nonlin.html
I don't believe in translating code I don't understand, but if anyone knows more
about curve-fitting than me then they might be able to get somewhere with it.

I ended up using Statistics::OLS ; I only needed log curve fitting and you can
solve that perfectly using Least Squares (see below, and yes there are pages of
proof that this is valid at sites like Mathematica's web site).

I mailed the author of Statistics::OLS but got no reply....

Anyway, my log-curve code is below... if you find anything else I'd be
interested to hear

Cheers

Tim


  use Statistics::OLS;

  #----------------------------------------------------------------------
  #
  # Passed a list of x and list of y, return coefficients a and b for
  # y = a + b.log(x) to fit the points.
  # Returns (a,b) or (undef,undef) if no curve to be made (eg less than 3
points)
  #
  sub FitLogCurve
  {
    my($x,$y) = @_;

    # work out the coefficents of the curve y = a + b * log(x)
    my(@lx, @ly);
    foreach (0..$#$x)
    {
        next unless defined $y->[$_];   # skip non-values ...
        next if $x->[$_] <= 0;          # and ignore illegal x values....
        push(@lx, log($x->[$_]));
        push(@ly, $y->[$_]);
    }
    return(undef,undef) if @lx < 3;

    my $ls = Statistics::OLS->new or die "Can't make ls\n";
    $ls->setData(\@lx, \@ly) or die "Error setting data - ".$ls->error;
    $ls->regress() or die "Can't regress - ".$ls->error();
    my($intercept, $slope) = $ls->coefficients();

    return($intercept, $slope);
  }







"Ranga Nathan" <[EMAIL PROTECTED]> on 20/05/2000 16:36:33

Please respond to "Ranga Nathan" <[EMAIL PROTECTED]>

To:   "Perl-Win32-Users Mailing List" <[EMAIL PROTECTED]>
cc:    (bcc: Tim Meadowcroft/LON/WLB)
Subject:  Curve Fitting and statistics



I am looking for statistics modules to enable me to fit trendlines to
charts. I am thinking of linear regression, logrithmic, exponential, power
and moving averages. I found a module called Statistics OLS dated 1998.
Before I continue to look for modules I thought I would ask the community
for their experiences and suggestions.

Thanks
[EMAIL PROTECTED]
______________________________________
A smile that comes around, goes around!


---
You are currently subscribed to perl-win32-users as:
[EMAIL PROTECTED]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to
         [EMAIL PROTECTED]









_________________________________________________________________________
                                                                      
The information contained in this message is intended for the addressee
only and may contain confidential and/or privileged information.
If you are not the addressee, please delete this message and notify the
sender; you should not copy or distribute this message or disclose its
contents to anyone.
Any views or opinions expressed in this message are those of the author
and do not necessarily represent those of WestLB or any of its affiliates.
No reliance may be placed on this message without written confirmation
from an authorised representative of its contents.

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to