The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Text::NSP::Measures::2D - Perl module that provides basic framework for building measure of association for bigrams.

SYNOPSIS

Basic Usage

  use Text::NSP::Measures::2D::MI::ll;

  my $ll = Text::NSP::Measures::2D::MI::ll->new();

  my $npp = 60; my $n1p = 20; my $np1 = 20;  my $n11 = 10;

  $ll_value = $ll->calculateStatistic( n11=>$n11,
                                      n1p=>$n1p,
                                      np1=>$np1,
                                      npp=>$npp);

  if( ($errorCode = $ll->getErrorCode()))
  {
    print STDERR $erroCode." - ".$ll->getErrorMessage();
  }
  else
  {
    print $ll->getStatisticName."value for bigram is ".$ll_value;
  }

DESCRIPTION

This module is to be used as a foundation for building 2-dimensional measures of association. The methods in this module retrieve observed bigram frequency counts, marginal totals, and also compute expected values. They also provide error checks for these counts.

With bigram or 2d measures we use an hash to store the 2x2 contingency table to store the frequency counts associated with each word in the bigram, as well as the number of times the bigram occurs. A contingency table looks like

            |word2  | not-word2|
            --------------------
    word1   | n11   |   n12    |  n1p
  not-word1 | n21   |   n22    |  n2p
            --------------------
              np1       np2       npp

Marginal Frequencies:

  n1p = the number of bigrams where the first word is word1.
  np1 = the number of bigrams where the second word is word2.
  n2p = the number of bigrams where the first word is not word1.
  np2 = the number of bigrams where the second word is not word2.

  These marginal totals are stored in a hash. These values may then be
  referred to as follows (if the hash name is $marginal):

        $marginal->{n1p},
        $marginal->{np1},
        $marginal->{n2p},
        $marginal->{np2},
        $marginal->{npp}

  where the keys are n1p, np1, n2p, np2 and npp.

Observed Frequencies:

  n11 = number of times the bigram occurs, joint frequency
  n12 = number of times word1 occurs in the first position of a bigram
        when word2 does not occur in the second position.
  n21 = number of times word2 occurs in the second position of a
        bigram when word1 does not occur in the first position.
  n22 = number of bigrams where word1 is not in the first position and
        word2 is not in the second position.

  The observed frequencies are also stored in a hash. These values may
  then be referred to as follows (if the hash name is $observed):


        $observed->{n11},
        $observed->{n12},
        $observed->{n21},
        $observed->{n22}

  where the keys are n11, n12, n21 and n22.

Expected Frequencies:

  m11 = expected number of times both words in the bigram occur
        together if they are independent. (n1p*np1/npp)
  m12 = expected number of times word1 in the bigram will occur in
        the first position when word2 does not occur in the second
        position given that the words are independent. (n1p*np2/npp)
  m21 = expected number of times word2 in the bigram will occur
        in the second position when word1 does not occur in the first
        position given that the words are independent. (np1*n2p/npp)
  m22 = expected number of times word1 will not occur in the first
        position and word2 will not occur in the second position
        given that the words are independent. (n2p*np2/npp)

  Similarly the expected values are stored as

        $expected->{m11},
        $expected->{m12},
        $expected->{m21},
        $expected->{m22}

Methods

new() - This method creates and returns an object for the measures(constructor)

INPUT PARAMS : none

RETURN VALUES : $this .. Reference to the new object of the measure.

computeObservedValues() - A method to compute observed values, and also to verify that the computed Observed values are correct, That is they are positive, less than the marginal totals and the total bigram count.

INPUT PARAMS : $count_values .. Reference to an hash consisting of the count values passed to the calcualteStatistic() method.

RETURN VALUES : $observed .. Reference to an hash consisting of the observed values computed from the marginal totals. (n11,n12,n21,n22)

computeExpectedValues() - A method to compute expected values.

INPUT PARAMS : $count_values .. Reference to an hash consisting of the count output.

RETURN VALUES : $expected .. Reference to an hash consisting of the expected values computed from the marginal totals. (m11,m12,m21,m22)

computeMarginalTotals() - This method computes the marginal totals from the count values as passed to it.

INPUT PARAMS : $count_values .. Reference to an hash consisting of the frequency combination output.

RETURN VALUES : $marginals .. Reference to an hash consisting of the marginal totals computed from the freq combination output.

AUTHOR

Ted Pedersen, University of Minnesota Duluth <tpederse@d.umn.edu>

Satanjeev Banerjee, Carnegie Mellon University <satanjeev@cmu.edu>

Amruta Purandare, University of Pittsburgh <amruta@cs.pitt.edu>

Bridget Thomson-McInnes, University of Minnesota Twin Cities <bthompson@d.umn.edu>

Saiyam Kohli, University of Minnesota Duluth <kohli003@d.umn.edu>

HISTORY

Last updated: $Id: 2D.pm,v 1.18 2006/04/20 22:26:19 saiyam_kohli Exp $

BUGS

SEE ALSO

http://groups.yahoo.com/group/ngram/

http://www.d.umn.edu/~tpederse/nsp.html

COPYRIGHT

SEE ALSO

http://groups.yahoo.com/group/ngram/

http://www.d.umn.edu/~tpederse/nsp.html

COPYRIGHT

Copyright (C) 2000-2006, Ted Pedersen, Satanjeev Banerjee, Amruta Purandare, Bridget Thomson-McInnes and Saiyam Kohli

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to

    The Free Software Foundation, Inc.,
    59 Temple Place - Suite 330,
    Boston, MA  02111-1307, USA.

Note: a copy of the GNU General Public License is available on the web at http://www.gnu.org/licenses/gpl.txt and is included in this distribution as GPL.txt.