NAME

Statistics::Frequency - simple counting of elements

SYNOPSIS

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');

DESCRIPTION

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.

new

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.

elements

my @elements = $freq->elements;
my $elements = $freq->elements;
  • In array context, return the elements.

  • In scalar context, return the number of elements.

frequency

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

Return the frequency of an element.

add_data

$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.

remove_data

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

Remove elements, arguments as with with add_data().

remove_elements

$freq->remove_elements( @elements );

Remove elements and their respective frequencies.

clear_data

$freq->clear_data;

Clear all the data in a frequency object.

copy_data

my $copy = $freq->copy_data;

Create a copy of a frequency object.

frequencies

my %freq = $freq->frequencies;

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

frequencies_sum

my $sum = $freq->frequencies_sum;

Return the sum of all the frequencies.

frequencies_min

my $sum = $freq->frequencies_min;

Return the minimum of all the frequencies.

frequencies_max

my $sum = $freq->frequencies_max;

Return the maximum of all the frequencies.

proportional_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.

proportional_frequency

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

Return the proportional frequency of the element.

SEE ALSO

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

AUTHOR

Jarkko Hietaniemi <jhi@iki.fi>

COPYRIGHT AND LICENSE

Copyright (C) 2002-2015, Jarkko Hietaniemi <jhi@iki.fi>

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