2 ;# lr.pl,v 3.1 1993/07/06 01:09:08 jbj Exp
5 ;# Linear Regression Package for perl
6 ;# to be 'required' from perl
9 ;# Frank Kardel, Rainer Pruy
10 ;# Friedrich-Alexander Universitaet Erlangen-Nuernberg
12 ;# Copyright (c) 1997 by
13 ;# Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>
14 ;# (Converted to a PERL 5.004 package)
16 ;#############################################################
23 ## B = (n * Sum(xy) - Sum(x) * Sum(y)) / (n * Sum(x^2) - Sum(x)^2)
25 ## A = (Sum(y) - B * Sum(x)) / n
31 ;# init(tag); initialize data set for tag
32 ;# sample(x, y, tag); enter sample
33 ;# Y(x, tag); compute y for given x
34 ;# X(y, tag); compute x for given y
35 ;# r(tag); regression coefficient
36 ;# cov(tag); covariance
39 ;# sigma(tag); standard deviation
41 #########################
63 $self->{sxy} += $_x * $_y;
64 $self->{sx2} += $_x**2;
65 $self->{sy2} += $_y**2;
72 return 1 unless ($self->{n} * $self->{sx2} - $self->{sx}**2);
73 return ($self->{n} * $self->{sxy} - $self->{sx} * $self->{sy})
74 / ($self->{n} * $self->{sx2} - $self->{sx}**2);
81 return ($self->{sy} - B() * $self->{sx}) / $self->{n};
88 return A() + B() * $_[$[];
95 return ($_[$[] - A()) / B();
102 my $s = ($self->{n} * $self->{sx2} - $self->{sx}**2)
103 * ($self->{n} * $self->{sy2} - $self->{sy}**2);
107 return ($self->{n} * $self->{sxy} - $self->{sx} * $self->{sy}) / sqrt($s);
114 return ($self->{sxy} - $self->{sx} * $self->{sy} / $self->{n})
122 return 0 if $self->{n} <= 1;
123 return sqrt(($self->{sy2} - ($self->{sy} * $self->{sy}) / $self->{n})
131 return 0 if $self->{n} <= 0;
132 return $self->{sy} / $self->{n};