~ubuntu-branches/ubuntu/natty/libstatistics-basic-perl/natty

« back to all changes in this revision

Viewing changes to lib/Statistics/Basic/Mode.pod

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur, Nathan Handler, Ryan Niebur
  • Date: 2009-07-01 20:22:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090701202206-0co1izn0pj047x4i
Tags: 1.6600-1
[ Nathan Handler ]
* debian/watch: Update to ignore development releases.

[ Ryan Niebur ]
* New upstream release
* Debian Policy 3.8.2
* enable author tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
=head1 NAME
2
2
 
3
 
Statistics::Basic::Mode - find the mode of an array
 
3
Statistics::Basic::Mode - find the mode of a list
4
4
 
5
5
=head1 SYNOPSIS
6
6
 
28
28
    print "hrm, there's three elements in this mode: $mod\n"
29
29
        if $mod->is_multimodal;
30
30
 
31
 
    use Scalar::Util qw(blessed);
32
 
 
33
 
    print "hrm, there's three elements in this mode: $mod\n"
34
 
        if blessed($v2) and $v2->isa("Statistics::Basic::Vector");
35
 
 
36
31
Create a 20 point "moving" mode like so:
37
32
 
 
33
    use Statistics::Basic qw(:all nofill);
 
34
 
38
35
    my $sth = $dbh->prepare("select col1 from data where something");
39
36
    my $len = 20;
40
 
    my $mod = mode();
41
 
       $mod->set_size($len);
 
37
    my $mod = mode()->set_size($len);
42
38
 
43
39
    $sth->execute or die $dbh->errstr;
44
40
    $sth->bind_columns( my $val ) or die $dbh->errstr;
45
41
 
46
 
    my $count = $len;
47
42
    while( $sth->fetch ) {
48
 
 
49
43
        $mod->insert( $val );
50
 
        if( -- $count <= 0 ) {
51
 
            print "Mode: $mod\n";
 
44
        if( defined( my $m = $mod->query ) ) {
 
45
            print "Mode: $m\n";
52
46
        }
 
47
 
 
48
        print "Mode: $mod\n" if $mod->query_filled;
53
49
    }
54
50
 
55
 
The full details are probably in the base module.  If you have questions, just
56
 
let me know.
 
51
=head1 METHODS
 
52
 
 
53
=over 4
 
54
 
 
55
=item B<new()>
 
56
 
 
57
The constructor takes a list of values, a single array ref, or a single
 
58
L<Statistics::Basic::Vector> as arguments.  It returns a
 
59
L<Statistics::Basic::Mode> object.
 
60
 
 
61
Note: normally you'd use the L<mean()|Statistics::Basic/mode()> constructor,
 
62
rather than building these by hand using C<new()>.
 
63
 
 
64
=item B<is_multimodal()>
 
65
 
 
66
L<Statistics::Basic::Mode> objects sometimes return L<Statistics::Basic::Vector>
 
67
objects instead of numbers.  When C<is_multimodal()> is true, the mode is a
 
68
vector, not a scalar.
 
69
 
 
70
=item B<_OVB::import()>
 
71
 
 
72
This module also inherits all the overloads and methods from
 
73
L<Statistics::Basic::_OneVectorBase>.
 
74
 
 
75
=back
 
76
 
 
77
=head1 OVERLOADS
 
78
 
 
79
This object is overloaded.  It tries to return an appropriate string for the
 
80
calculation or the value of the computation in numeric context.
 
81
 
 
82
In boolean context, this object is always true (even when empty).
 
83
 
 
84
If evaluated as a string, L<Statistics::Basic::Mode> will try to format a number
 
85
(like any other L<Statistics::Basic> object), but if the object
 
86
L</is_multimodal()>, it will instead return a L<Statistics::Basic::Vector> for
 
87
stringification.
 
88
 
 
89
    $x = mode(1,2,3);
 
90
    $y = mode(1,2,2);
 
91
 
 
92
    print "$x, $y\n"; # prints: [1, 2, 3], 2
 
93
 
 
94
If evaluated as a number, a L<Statistics::Basic::Mode> will raise an error when
 
95
the object L</is_multimodal()>.
57
96
 
58
97
=head1 AUTHOR
59
98
 
63
102
 
64
103
Copyright 2009 Paul Miller -- Licensed under the LGPL
65
104
 
66
 
 
67
105
=head1 SEE ALSO
68
106
 
69
 
perl(1), L<Statistics::Basic>
 
107
perl(1), L<Statistics::Basic>, L<Statistics::Basic::_OneVectorBase>, L<Statistics::Basic::Vector>
70
108
 
71
109
=cut