1Statistics::Basic::ModeU(s3e)r Contributed Perl DocumentaSttiaotnistics::Basic::Mode(3)
2
3
4

NAME

6       Statistics::Basic::Mode - find the mode of a list
7

SYNOPSIS

9       Invoke it this way:
10
11           my $mode = mode(1,2,3,3);
12
13       Or this way:
14
15           my $v1  = vector(1,2,3,3);
16           my $mod = mode($v1);
17
18       And then either query the values or print them like so:
19
20           print "The mod of $v1: $mod\n";
21           my $mq = $mod->query;
22           my $m0 = 0+$mod; # this will croak occasionally, see below
23
24       The mode of an array is not necessarily a scalar.  The mode of this
25       vector is a vector:
26
27           my $mod = mode(1,2,3);
28           my $v2  = $mod->query;
29
30           print "hrm, there's three elements in this mode: $mod\n"
31               if $mod->is_multimodal;
32
33       Create a 20 point "moving" mode like so:
34
35           use Statistics::Basic qw(:all nofill);
36
37           my $sth = $dbh->prepare("select col1 from data where something");
38           my $len = 20;
39           my $mod = mode()->set_size($len);
40
41           $sth->execute or die $dbh->errstr;
42           $sth->bind_columns( my $val ) or die $dbh->errstr;
43
44           while( $sth->fetch ) {
45               $mod->insert( $val );
46               if( defined( my $m = $mod->query ) ) {
47                   print "Mode: $m\n";
48               }
49
50               print "Mode: $mod\n" if $mod->query_filled;
51           }
52

METHODS

54       new()
55           The constructor takes a list of values, a single array ref, or a
56           single Statistics::Basic::Vector as arguments.  It returns a
57           Statistics::Basic::Mode object.
58
59           Note: normally you'd use the mean() constructor, rather than
60           building these by hand using "new()".
61
62       is_multimodal()
63           Statistics::Basic::Mode objects sometimes return
64           Statistics::Basic::Vector objects instead of numbers.  When
65           "is_multimodal()" is true, the mode is a vector, not a scalar.
66
67       _OVB::import()
68           This module also inherits all the overloads and methods from
69           Statistics::Basic::_OneVectorBase.
70

OVERLOADS

72       This object is overloaded.  It tries to return an appropriate string
73       for the calculation or the value of the computation in numeric context.
74
75       In boolean context, this object is always true (even when empty).
76
77       If evaluated as a string, Statistics::Basic::Mode will try to format a
78       number (like any other Statistics::Basic object), but if the object
79       "is_multimodal()", it will instead return a Statistics::Basic::Vector
80       for stringification.
81
82           $x = mode(1,2,3);
83           $y = mode(1,2,2);
84
85           print "$x, $y\n"; # prints: [1, 2, 3], 2
86
87       If evaluated as a number, a Statistics::Basic::Mode will raise an error
88       when the object "is_multimodal()".
89

AUTHOR

91       Paul Miller "<jettero@cpan.org>"
92
94       Copyright 2009 Paul Miller -- Licensed under the LGPL
95

SEE ALSO

97       perl(1), Statistics::Basic, Statistics::Basic::_OneVectorBase,
98       Statistics::Basic::Vector
99
100
101
102perl v5.12.3                      2009-06-28        Statistics::Basic::Mode(3)
Impressum