Jarkko Hietaniemi >
Statistics-Frequency-0.03 >
Statistics::Frequency

Module Version: 0.03
Statistics::Frequency - simple counting of elements

use Statistics::Frequency; my $f1 = Statistics::Frequency->new; $f1->add_data( @data ); $f1->add_data( \@data ); $f1->add_data( \%data ); my @list_of_different_elements = $f1->elements; my $number_of_different_elements = $f1->elements; my $freq = $f1->frequency('x'); my $f2a = Statistics::Frequency->new( @data ); # a list my $f2b = Statistics::Frequency->new( \@data ); # an arrayref my $f2c = Statistics::Frequency->new( \%data ); # a hashref $f->remove_data( @data ); $f->remove_data( \@data ); $f->remove_data( \%data ); $f->remove_elements('y'); $f->clear_data; my $g = $f->copy_data; my %freq = $f->frequencies; my $sum = $f->frequencies_sum; my $min = $f->frequencies_min; my $max = $f->frequencies_max; my %prop = $f->proportional_frequencies; my $prop = $f->proportional_frequency('z');

Statistics::Frequency is a simple class for counting *elements*, in other words, their *frequencies*.

Note that Statistics::Frequency is not similar to statistics modules like, say, Statistics::Descriptive. Statistics::Frequency doesn't operate on numbers, it operates on *elements*, which are basically opaque strings. Therefore there can't be, say, "an average" of the elements.

The goal of Statistics::Frequency is simply to be provide container for sets of elements and their respective frequencies.

my $freq = Statistics::Frequency->new; my $freq = Statistics::Frequency->new(@data); my $freq = Statistics::Frequency->new(\@data); my $freq = Statistics::Frequency->new(\%data);

Create a new Statistics::Frequency object. The object can be either empty or a list of elements can be given. See "add_data" for details.

my @elements = $freq->elements; my $elements = $freq->elements;

- In array context, return the elements.
- In scalar context, return the number of elements.

$f = $freq->frequency($element);

Return the frequency of an element.

$freq->add_data(@data); $freq->add_data(\@data); $freq->add_data(\%data);

- If an element of the argument list is another frequency object, the frequencies in the invocant object of the elements are increased by the frequencies in the argument object.
- If an element is an array reference, add_data() is called recursively with the elements of the array behind the reference.
- If an element is a hash reference, the keys are assumed to be elements and the value are assumed to be their frequencies.
- Otherwise an element is just an ordinary element and its frequency is incremented by one.

$freq->remove_data(@data); $freq->remove_data(\@data); $freq->remove_data(\%data);

Remove elements, arguments as with with add_data().

$freq->remove_elements( @elements );

Remove elements and their respective frequencies.

$freq->clear_data;

Clear all the data in a frequency object.

my $copy = $freq->copy_data;

Create a copy of a frequency object.

my %freq = $freq->frequencies;

Return the frequencies as a hash, the elements as the keys and the frequencies as the values.

my $sum = $freq->frequencies_sum;

Return the sum of all the frequencies.

my $sum = $freq->frequencies_min;

Return the minimum of all the frequencies.

my $sum = $freq->frequencies_max;

Return the maximum of all the frequencies.

my %freq = $freq->proportional_frequencies;

Return the proportional frequencies as a hash, the elements as the keys and the frequencies as the values. Proportional meaning that proportional frequencies total 1.0, in other words, each of the frequencies of elements are divided by the sum of all the frequencies.

my $f = $freq->proportional_frequency($element);

Return the proportional frequency of the element.

Statistics::Descriptive, Statistics::Descriptive::Discrete

Jarkko Hietaniemi <jhi@iki.fi>

Copyright 2002 Jarkko Hietaniemi All Rights Reserved

This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: