# odds.pm
# Package to calculate the odds ratio for a 2-d table.

# The Odds Ratio is defined as the ratio of the total number of times 
# two words occur together or not to the total number of times the two
# words occur individually. It is the cross product of the diagonal
# over the cross product off the off-diagonal in a 2-d table.  

# Copyright (C) 2001-2003.
# Nitin Varma, University of Minnesota, Duluth
# varm0003@d.umn.edu
# Ted Pedersen, University of Minnesota, Duluth
# tpederse@d.umn.edu
#
# 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.


package odds;
require Exporter;
@ISA = qw ( Exporter );
@EXPORT = qw ( getStatisticName calculateStatistic );

sub getStatisticName
{
    return "Odds- Ratio";
}

sub calculateStatistic
{
    ($freq, $freq1, $freq2, $totalBigrams) = @_;
    $a = $freq;
    $b = $freq1 - $a;
    $c = $freq2 - $a;
    $d = ($totalBigrams - $a - $b - $c);
    if(($b == 0) and ($c == 0))
    {
        return ($a*$d);
    }
   
  elsif($b ==0 and $c!=0)
  {
      return((($a)*($d))/($c));
  }
elsif($b!=0 and $c==0)
{

    return((($a)*($d))/($b));
}


    else
    {   
        
	$OR = ( ($a * $d) / ($b * $c) );
        return($OR);
    }
	
 
}

1;






