Ted Pedersen

# NAME

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

# SYNOPSIS

This module can be used as a foundation for building 3-dimensional measures of association that can then be used by statistic.pl. In particular this module provides methods that give convenient access to 3-d (i.e., trigram) frequency counts as created by count.pl, as well as some degree of error handling that verifies the data.

### Basic Usage

``````  use Text::NSP::Measures::3D::MI::ll;

my \$ll = Text::NSP::Measures::3D::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 trigram is ".\$ll_value;
}``````

# DESCRIPTION

The methods in this module retrieve observed trigram frequency counts and marginal totals, and also compute expected values. They also provide support for error checking of the output produced by count.pl. These methods are used in all the trigram (3d) measure modules provided in NSP. If you are writing your own 3d measure, you can use these methods as well.

With trigram or 3d measures we use a 3x3 contingency table to store the frequency counts associated with each word in the trigram, as well as the number of times the trigram occurs. The notation we employ is as follows:

Marginal Frequencies:

`````` n1pp = the number of trigrams where the first word is word1.
np1p = the number of trigrams where the second word is word2.
npp1 = the number of trigrams where the third word is word3
n2pp = the number of trigrams where the first word is not word1.
np2p = the number of trigrams where the second word is not word2.
npp2 = the number of trigrams where the third word is not word3.``````

Observed Frequencies:

`````` n111 = number of times word1, word2 and word3 occur together in
their respective positions, joint frequency.
n112 = number of times word1 and word2 occur in their respective
positions but word3 does not.
n121 = number of times word1 and word3 occur in their respective
positions but word2 does not.
n211 = number of times word2 and word3 occur in their respective
positions but word1 does not.
n122 = number of times word1 occurs in its respective position
but word2 and word3 do not.
n212 = number of times word2 occurs in in its respective position
but word1 and word3 do not.
n221 = number of times word3 occurs in its respective position
but word1 and word2 do not.
n222 = number of time neither word1, word2 or word3 occur in their
respective positions.``````

Expected Frequencies:

`````` m111 = expected number of times word1, word2 and word3 occur together in
their respective positions.
m112 = expected number of times word1 and word2 occur in their respective
positions but word3 does not.
m121 = expected number of times word1 and word3 occur in their respective
positions but word2 does not.
m211 = expected number of times word2 and word3 occur in their respective
positions but word1 does not.
m122 = expected number of times word1 occurs in its respective position
but word2 and word3 do not.
m212 = expected number of times word2 occurs in in its respective position
but word1 and word3 do not.
m221 = expected number of times word3 occurs in its respective position
but word1 and word2 do not.
m222 = expected number of time neither word1, word2 or word3 occur in their
respective positions.``````

## 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(\$count_values) - 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(\$count_values) - 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(\$marginal_values) - This method computes the marginal totals from the valuescomputed by the count.pl program and are passed to the calculateStatistic() method.

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: 3D.pm,v 1.11 2006/06/15 16:53:04 saiyam_kohli Exp \$

# SEE ALSO

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

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

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.