blib/lib/Statistics/LSNoHistory.pm

filter: Statementstmt 86.8% 132 / 152 Branchbran 63.6% 42 / 66 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 92.0% 23 / 25 Podpod 0.0% 0 / 21 totaltotal 72.4% 202 / 279 CC 39 SCAR 18.0
CC
39
Cov
78%
new
16.7
append_point
6.0
predict
6.0
CRAP 6.0
↑ Summary
1 #
2 # LSNoHistory.pm - least-squares regression without data history
3 #
4 # $Id: LSNoHistory.pm,v 1.6 2003/02/23 05:11:29 pliam Exp $
5 #
6  
7 package Statistics::LSNoHistory;
8 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $VERSION = sprintf("%d.%02d", (q$Name: LSNoHist_Release_0_01 $ =~ /\d+/g));
12  
13 #############################################################################
14 # top-level pod
15 #############################################################################
16  
17 =pod
18  
19 =head1 NAME
20  
21 Statistics::LSNoHistory - Least-Squares linear regression package without
22 data history
23  
24 =head1 SYNOPSIS
25  
26 # construct from points
27 $reg = Statistics::LSNoHistory->new(points => [
28 1.0 => 1.0,
29 2.1 => 1.9,
30 2.8 => 3.2,
31 4.0 => 4.1,
32 5.2 => 4.9
33 ]);
34  
35 # other equivalent constructions
36 $reg = Statistics::LSNoHistory->new(
37 xvalues => [1.0, 2.1, 2.8, 4.0, 5.2],
38 yvalues => [1.0, 1.9, 3.2, 4.1, 4.9]
39 );
40 # or
41 $reg = Statistics::LSNoHistory->new;
42 $reg->append_arrays(
43 [1.0, 2.1, 2.8, 4.0, 5.2],
44 [1.0, 1.9, 3.2, 4.1, 4.9]
45 );
46 # or
47 $reg = Statistics::LSNoHistory->new;
48 $reg->append_points(
49 1.0 => 1.0, 2.1 => 1.9, 2.8 => 3.2, 4.0 => 4.1, 5.2 => 4.9
50 );
51  
52 # You may also construct from the preliminary statistics of a
53 # previous regression:
54 $reg = Statistics::LSNoHistory->new(
55 num => 5,
56 sumx => 15.1,
57 sumy => 15.1,
58 sumxx => 56.29,
59 sumyy => 55.67,
60 sumxy => 55.83,
61 minx => 1.0,
62 maxx => 5.2,
63 miny => 1.0,
64 maxy => 4.9
65 );
66 # thus a branch may be instantiated as follows
67 $branch = Statistics::LSNoHistory->new(%{$reg->dump_stats});
68 $reg->append_point(6.1, 5.9);
69 $branch->append_point(5.8, 6.0);
70  
71 # calculate regression values, print some
72 printf("Slope: %.2f\n", $reg->slope);
73 printf("Intercept %.2f\n", $reg->intercept);
74 printf("Correlation Coefficient: %.2f\n", $reg->pearson_r);
75 ...
76  
77  
78 =head1 DESCRIPTION
79  
80 This package provides standard least squares linear regression
81 functionality without the need for storing the complete data history.
82 Like any other, it finds best m,k (in least squares sense) so that
83 y = m*x + k fits data points (x_1,y_1),...,(x_n,y_n).
84  
85 In many applications involving linear regression, it is desirable
86 to compute a regression based on the intermediate statistics of a
87 previous regression along with any I<new> data points. Thus there
88 is no need to store a complete data history, but rather only a minimal
89 set of intermediate statistics, the number of which, thanks to Gauss,
90 is 6.
91  
92 The user interface provides a way to instantiate a regression object
93 with either raw data or previous intermediate statistics.
94  
95 =cut
96  
97 #############################################################################
98 # construction
99 #############################################################################
100  
101 =pod
102  
103 =head1 CONSTRUCTOR ARGUMENTS
104  
105 The constructor (or class method I<new>) takes several possible
106 arguments. The initialization scenario depends on the kinds of
107 arguments passed and falls into one of the following categories:
108  
109 =over 2
110  
111 =item *
112  
113 I<default:> S<new>() by itself is equivalent to initializing with no
114 data. All internal statistics are set to zero.
115  
116 =item *
117  
118 I<data points array:> new(I<points> => [x_1 => y_1, x_2 => y_2,...,
119 x_n => y_n]) processes the n specified data points. Note that
120 points expects an array reference even though we've written it
121 in "hash notation" for clarity.
122  
123 =item *
124  
125 I<data value arrays:> new(I<xvalues> => [x_1, x_2,..., x_n],
126 I<yvalues> => [y_1, y_2,..., y_n]) is equivalent to the above.
127  
128 =item *
129  
130 I<previous state:> new(I<state arguments>) requires I<all> of the
131 following intermediate statistics:
132  
133 =over 6
134  
135 =item I<num>
136  
137 S<=E<gt>> Number of points.
138  
139 =item I<sumx>
140  
141 S<=E<gt>> Sum of x values.
142  
143 =item I<sumy>
144  
145 S<=E<gt>> Sum of y values.
146  
147 =item I<sumxx>
148  
149 S<=E<gt>> Sum of x values squared.
150  
151 =item I<sumyy>
152  
153 S<=E<gt>> Sum of y values squared.
154  
155 =item I<sumxy>
156  
157 S<=E<gt>> Sum of x*y products.
158  
159 =item I<minx>
160  
161 S<=E<gt>> Minimum x value.
162  
163 =item I<maxx>
164  
165 S<=E<gt>> Maximum x value.
166  
167 =item I<miny>
168  
169 S<=E<gt>> Minimum y value.
170  
171 =item I<maxy>
172  
173 S<=E<gt>> Maximum y value.
174  
175 =back 6
176  
177 =back 2
178  
179 =cut
180  
181 ## new constructor
182 11 ▶sub new {
Subroutine new: called CC=13 SCAR=28.1
Pod undocumented
183 11 my $class = shift;
184 11 my %args = @_;
185 11 my $self;
186 11 my @stats = qw(num sumx sumy sumxx sumyy sumxy);
187 11 push(@stats, qw(minx maxx miny maxy)); # min/max
188  
189 # if complete set of statistics, construct from previous state
190 # if (@stats == scalar(grep {defined($args{$_})} @stats)) {
191 11 ▶ if (@stats == grep {defined($args{$_})} @stats) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stats == grep({defined $args{$_};} @stats)) 2 9 11
192 # reject unsupported arguments and combinations
193 2 ▶ if (grep {defined($args{$_})} qw(points xvalues yvalues)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $args{$_};} "points", "xvalues", "yvalues") 0 2 2
194 0 die "Cannot give new data along with previous state.";
195 }
196 2 ▶ unless (@stats == keys %args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stats == keys %args) 0 2 2
197 0 die "Unknown constructor arguments.";
198 }
199 # check the number of points for consistency
200 2 ▶ unless (abs(int($args{num})) == $args{num}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (abs int $args{"num"} == $args{"num"}) 0 2 2
201 0 die "Bad number of points: must be positive integer.";
202 }
203 2 $self = \%args;
204 2 bless $self, $class;
205 2 return $self;
206 }
207 # in any other case we're starting from scratch
208 9 $self = {};
209 9 bless $self, $class;
210 9 $self->_init;
211 # x & y value array refs
212 9 ▶ if (defined($args{xvalues}) && defined($args{yvalues})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'xvalues'} and defined $args{'yvalues'}) { } 3 6 9
elsif (defined $args{'points'}) { } 3 3 6
Condition66%2/3
defined $args{"xvalues"} and defined $args{"yvalues"}
!ll&&!rl&&r
603
MC/DC50%1/2
defined $args{"xvalues"} and defined $args{"yvalues"}
defined $args{"xvalues"} defined $args{"yvalues"}
Truth table66%2/3
A and B
A= defined $args{"xvalues"}B= defined $args{"yvalues"}
ABresult
0X0
100
111
213 3 ▶ if (defined $args{points}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"points"}) 0 3 3
214 0 die "Must give points or array values, but not both";
215 }
216 3 ▶ unless (scalar(keys %args) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %args == 2) 0 3 3
217 0 die "Unknown constructor arguments.";
218 }
219 3 $self->append_arrays($args{xvalues}, $args{yvalues});
220 }
221 # (x,y) point array ref
222 elsif (defined($args{points})) {
223 3 ▶ if (grep {defined($args{$_})} qw(xvalues yvalues)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $args{$_};} "xvalues", "yvalues") 0 3 3
224 0 die "Must give points or array values, but not both";
225 }
226 3 ▶ unless (scalar(keys %args) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %args == 1) 0 3 3
227 0 die "Unknown constructor arguments.";
228 }
229 3 $self->append_points(@{$args{points}});
230 }
231 # default constructor (already initialized above)
232 else {
233 3 ▶ if (scalar(keys %args)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %args) 0 3 3
234 0 die "Unknown constructor arguments.";
235 }
236 }
237 9 return $self;
238 }
239  
240 ## _init in this context really means start with state of 0's
241 9 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
242 9 my $self = shift;
243 9 my @stats = qw(num sumx sumy sumxx sumyy sumxy);
244 9 push(@stats, qw(minx maxx miny maxy)); # min/max
245  
246 9 @$self{@stats} = (0) x scalar(@stats);
247 }
248  
249  
250 #############################################################################
251 # other methods
252 #############################################################################
253 =pod
254  
255 =head1 METHODS
256  
257 =over 2
258  
259 =cut
260  
261 #
262 # adding data
263 #
264  
265 ## append_point
266 =pod
267  
268 =item *
269  
270 I<append_point>(x,y) process an additional data point.
271  
272 =cut
273 64 ▶sub append_point {
Subroutine append_point: called CC=6 SCAR=17.9
Pod undocumented
274 64 my $self = shift;
275 64 my($x,$y) = @_;
276  
277 ## will have to recompute regression
278 64 $self->{cached} = 0;
279  
280 # min/max
281 64 ▶ if ($self->{num}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'num'}) { } 55 9 64
282 55 ▶ $self->{minx} = ($x < $self->{minx}) ? $x : $self->{minx};
Branch: 1 branch
BranchTrueFalseTotal
$x < $self->{'minx'} ? : 7 48 55
283 55 ▶ $self->{maxx} = ($x > $self->{maxx}) ? $x : $self->{maxx};
Branch: 1 branch
BranchTrueFalseTotal
$x > $self->{'maxx'} ? : 27 28 55
284 55 ▶ $self->{miny} = ($y < $self->{miny}) ? $y : $self->{miny};
Branch: 1 branch
BranchTrueFalseTotal
$y < $self->{'miny'} ? : 6 49 55
285 55 ▶ $self->{maxy} = ($y > $self->{maxy}) ? $y : $self->{maxy};
Branch: 1 branch
BranchTrueFalseTotal
$y > $self->{'maxy'} ? : 30 25 55
286 }
287 else {
288 9 $self->{minx} = $x;
289 9 $self->{maxx} = $x;
290 9 $self->{miny} = $y;
291 9 $self->{maxy} = $y;
292 }
293  
294 # classic stats
295 64 $self->{num}++;
296 64 $self->{sumx} += $x;
297 64 $self->{sumy} += $y;
298 64 $self->{sumxx} += $x**2;
299 64 $self->{sumyy} += $y**2;
300 64 $self->{sumxy} += $x*$y;
301 }
302  
303 ## append_points
304 =pod
305  
306 =item *
307  
308 I<append_points>(x_1 => y_1,..., x_n => y_n) process additional data points,
309 which is equivalent to calling append_point() n times.
310  
311 =cut
312 4 ▶sub append_points {
Subroutine append_points: called CC=3 SCAR=11.2
Pod undocumented
313 4 my $self = shift;
314 4 my @points = @_;
315 4 my $num = scalar(@points);
316  
317 0 ▶ if ($num % 2) { die "Incomplete list of points."; }
Branch: 1 branch
BranchTrueFalseTotal
if ($num % 2) 0 4 4
318  
319 4 $num /= 2;
320 4 for (1..$num) { $self->append_point(splice(@points, 0, 2)); }
321 }
322  
323  
324 ## append_arrays
325 =pod
326  
327 =item *
328  
329 I<append_arrays>([x_1, x_2,..., x_n], [y_1, y_2,..., y_n])
330 process additional data points given a pair x and y data array
331 references. Also equivalent to calling append_point() n times.
332  
333 =cut
334 4 ▶sub append_arrays {
Subroutine append_arrays: called CC=5 SCAR=17.8
Pod undocumented
335 4 my $self = shift;
336 4 my ($xr, $yr) = @_;
337 4 my ($xn, $yn);
338  
339 # check arg type
340 4 ▶ unless ((ref($xr) eq 'ARRAY') && (ref($yr) eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $xr eq "ARRAY" and ref $yr eq "ARRAY") 0 4 4
Condition33%1/3
ref $xr eq "ARRAY" and ref $yr eq "ARRAY"
!ll&&!rl&&r
004
MC/DC0%0/2
ref $xr eq "ARRAY" and ref $yr eq "ARRAY"
ref $xr eq "ARRAY" ref $yr eq "ARRAY"
Truth table33%1/3
A and B
A= ref $xr eq "ARRAY"B= ref $yr eq "ARRAY"
ABresult
0X0
100
111
341 0 die "Must pass pair of array references.";
342 }
343  
344 # check that sizes match
345 4 $xn = scalar(@$xr);
346 4 $yn = scalar(@$yr);
347 0 ▶ unless ($xn == $yn) { die "Incomplete list of points."; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($xn == $yn) 0 4 4
348  
349 4 for (1..$xn) { $self->append_point(shift(@$xr), shift(@$yr)); }
350 }
351  
352 #
353 # computing the regression
354 #
355  
356 ## _regress method -- done behind the scenes & considered private
357 12 ▶sub _regress {
Subroutine _regress: called CC=4 SCAR=14.0
358 12 my $self = shift;
359 12 my($n) = $self->{num};
360 12 my($dx) = $n*$self->{sumxx} - $self->{sumx}**2;
361 12 my($dy) = $n*$self->{sumyy} - $self->{sumy}**2;
362  
363 # check that we have 2 points
364 12 ▶ unless ($n >= 2) { die "Must have at least 2 points for regression."; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($n >= 2) 1 11 12
365 # check data for consistency
366 11 ▶ unless (($dx!=0) && ($dy!=0)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dx != 0 and $dy != 0) 0 11 11
Condition33%1/3
$dx != 0 and $dy != 0
!ll&&!rl&&r
0011
MC/DC0%0/2
$dx != 0 and $dy != 0
$dx != 0 $dy != 0
Truth table33%1/3
A and B
A= $dx != 0B= $dy != 0
ABresult
0X0
100
111
367 0 die "Inconsistent data: would divide by zero.";
368 }
369  
370 # means and variances
371 11 $self->{avgx} = $self->{sumx}/$n;
372 11 $self->{avgy} = $self->{sumy}/$n;
373 11 $self->{varx} = $dx/$n/($n-1);
374 11 $self->{vary} = $dy/$n/($n-1);
375  
376 # slopes and intercepts
377 11 $self->{mx} = ($n*$self->{sumxy} - $self->{sumx}*$self->{sumy})/$dx;
378 11 $self->{kx} = $self->{avgy} - $self->{mx}*$self->{avgx};
379 11 $self->{my} = ($n*$self->{sumxy} - $self->{sumx}*$self->{sumy})/$dy;
380 11 $self->{ky} = $self->{avgx} - $self->{my}*$self->{avgy};
381
382 # correlation coefficient (Pearson's r) and chi squared
383 $self->{r} = ($n*$self->{sumxy} - $self->{sumx}*$self->{sumy})
384 11 / sqrt($dx*$dy);
385 11 $self->{chi2} = (1-$self->{r}**2)*$dy/$n;
386  
387 # flag that regression calculations are up to date
388 11 $self->{cached} = 1;
389 }
390  
391 #
392 # presentation of stats, prediction
393 #
394  
395 ## average_x
396 =pod
397  
398 =item *
399  
400 I<average_x> returns the mean of the x values.
401  
402 =cut
403 19 ▶sub average_x {
Subroutine average_x: called CC=2 SCAR=6.9
Pod undocumented
404 19 my $self = shift;
405 19 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 10 9 19
406 return $self->{avgx}
407 18 }
408  
409 ## average_y
410 =pod
411  
412 =item *
413  
414 I<average_y> returns the mean of the y values.
415  
416 =cut
417 18 ▶sub average_y {
Subroutine average_y: called CC=2 SCAR=7.1
Pod undocumented
418 18 my $self = shift;
419 18 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 18 18
420 return $self->{avgy}
421 18 }
422  
423 ## variance_x
424 =pod
425  
426 =item *
427  
428 I<variance_x> returns the (n-1)-style variance of the x values.
429  
430 =cut
431 18 ▶sub variance_x {
Subroutine variance_x: called CC=2 SCAR=7.1
Pod undocumented
432 18 my $self = shift;
433 18 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 18 18
434 return $self->{varx}
435 18 }
436  
437 ## variance_y
438 =pod
439  
440 =item *
441  
442 I<variance_y> returns the (n-1)-style variance of the y values.
443  
444 =cut
445 18 ▶sub variance_y {
Subroutine variance_y: called CC=2 SCAR=7.1
Pod undocumented
446 18 my $self = shift;
447 18 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 18 18
448 return $self->{vary}
449 18 }
450  
451 ## slope
452 =pod
453  
454 =item *
455  
456 I<slope> returns the slope m so that y = m*x + k is a least squares fit.
457 Note that this is the least (y-y_avg)**2, and thus the standard slope.
458  
459 =cut
460 19 ▶sub slope {
Subroutine slope: called CC=2 SCAR=7.1
Pod undocumented
461 19 my $self = shift;
462 19 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 19 19
463 return $self->{mx}
464 19 }
465  
466 ## intercept
467 =pod
468  
469 =item *
470  
471 I<intercept> returns the intercept k so that y = m*x + k is a least squares
472 fit. Note again that this is the least (y-y_avg)**2, and thus the
473 standard intercept.
474  
475 =cut
476 19 ▶sub intercept {
Subroutine intercept: called CC=2 SCAR=7.1
Pod undocumented
477 19 my $self = shift;
478 19 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 19 19
479 return $self->{kx}
480 19 }
481  
482 ## predict - predicte a y value given an x value
483 =pod
484  
485 =item *
486  
487 I<predict>(x) predicts a y value, given an x value. Computes m*x + k, where
488 m, k are the standard regression slope and intercept (->slope and ->intercept,
489 respectively) for the most recent data.
490  
491 =cut
492 0 ▶sub predict {
Subroutine predict: not called CC=2 SCAR=17.9
Pod undocumented
493 0 my $self = shift;
494 0 my($x) = @_;
495  
496 0 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 0 0
497 0 return $self->{mx}*$x + $self->{kx};
498 }
499  
500 ## slope_y
501 =pod
502  
503 =item *
504  
505 I<slope_y> returns the slope m' so that y = m'*x + k' is a least squares fit.
506 Note that this is the least (x-x_avg)**2, and thus I<not> the standard slope.
507  
508 =cut
509 18 ▶sub slope_y {
Subroutine slope_y: called CC=2 SCAR=7.1
Pod undocumented
510 18 my $self = shift;
511 18 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 18 18
512 return $self->{my}
513 18 }
514  
515 ## intercept_y
516 =pod
517  
518 =item *
519  
520 I<intercept_y> returns the intercept k' so that y = m'*x + k' is a least
521 squares fit. Note that this is the least (x-x_avg)**2, and thus I<not>
522 the standard intercept.
523  
524 =cut
525 18 ▶sub intercept_y {
Subroutine intercept_y: called CC=2 SCAR=7.1
Pod undocumented
526 18 my $self = shift;
527 18 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 18 18
528 return $self->{ky}
529 18 }
530  
531 ## predict_x - predicte an x value given a y value
532 =pod
533  
534 =item *
535  
536 I<predict_x>(y) predicts an x value given a y value. Computes m'*y + k',
537 where m', k' are the regression (y-reletive) slope and intercept
538 (->slope_y and ->intercept_y, respectively) for the most recent data.
539  
540 =cut
541 0 ▶sub predict_x {
Subroutine predict_x: not called CC=2 SCAR=17.9
Pod undocumented
542 0 my $self = shift;
543 0 my($y) = @_;
544  
545 0 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 0 0
546 0 return $self->{my}*$y + $self->{ky};
547 }
548  
549 ## pearson_r
550 =pod
551  
552 =item *
553  
554 I<pearson_r> returns Pearson's r correlation coefficient.
555  
556 =cut
557 21 ▶sub pearson_r {
Subroutine pearson_r: called CC=2 SCAR=6.9
Pod undocumented
558 21 my $self = shift;
559 21 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 2 19 21
560 return $self->{r}
561 21 }
562  
563 ## chi_squared
564 =pod
565  
566 =item *
567  
568 I<chi_squared> returns the chi squared statistic.
569  
570 =cut
571 17 ▶sub chi_squared {
Subroutine chi_squared: called CC=2 SCAR=7.1
Pod undocumented
572 17 my $self = shift;
573 17 ▶ $self->_regress unless $self->{cached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cached"} 0 17 17
574 return $self->{chi2}
575 17 }
576  
577 ## minimum_x
578 =pod
579  
580 =item *
581  
582 I<minimum_x> returns the minimum x value
583  
584 =cut
585 17 ▶sub minimum_x { return shift->{minx}; }
Subroutine minimum_x: called CC=1 SCAR=0.0
Pod undocumented
586  
587 ## maximum_x
588 =pod
589  
590 =item *
591  
592 I<maximum_x> returns the maximum x value
593  
594 =cut
595 17 ▶sub maximum_x { return shift->{maxx}; }
Subroutine maximum_x: called CC=1 SCAR=0.0
Pod undocumented
596  
597 ## minimum_y
598 =pod
599  
600 =item *
601  
602 I<minimum_y> returns the minimum y value
603  
604 =cut
605 17 ▶sub minimum_y { return shift->{miny}; }
Subroutine minimum_y: called CC=1 SCAR=0.0
Pod undocumented
606  
607 ## maximum_y
608 =pod
609  
610 =item *
611  
612 I<maximum_y> returns the maximum y value
613  
614 =cut
615 17 ▶sub maximum_y { return shift->{maxy}; }
Subroutine maximum_y: called CC=1 SCAR=0.0
Pod undocumented
616  
617 ## dump_stats
618 =pod
619  
620 =item *
621  
622 I<dump_stats> returns a hash reference of the form
623  
624 { num => <val>,
625 sumx => <val>,
626 sumy => <val>,
627 sumxx => <val>,
628 sumyy => <val>,
629 sumxy => <val>,
630 minx => <val>,
631 maxx => <val>,
632 miny => <val>,
633 maxy => <val> }
634  
635 in other words, containing all the stats required by the final constructor
636 above. This effectively dumps the regression history.
637  
638 =cut
639 11 ▶sub dump_stats {
Subroutine dump_stats: called CC=1 SCAR=0.0
Pod undocumented
640 11 my $self = shift;
641 11 my @stats = qw(num sumx sumy sumxx sumyy sumxy);
642 11 push(@stats, qw(minx maxx miny maxy)); # min/max
643 11 my %dump;
644  
645 11 @dump{@stats} = @$self{@stats};
646 11 return \%dump;
647 }
648  
649 3 1;
650  
651 __END__
↑ Summary