Perl CPAN模块fisher精确测试

时间:2014-06-17 18:26:12

标签: perl statistics

CPAN中是否有任何模块可以提供计算Fishers精确测试的方法?

R中的例子:

在2x2列联表中,如:

    17        12
    8842559   10003821

fisher.test(matrix(data = c(17,8842559,12,10003821), nrow = 2))


        Fisher's Exact Test for Count Data

data:  counts
p-value = 0.2642
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.7213591 3.6778630
sample estimates:
odds ratio 
  1.602697 

我使用了Text::NSP::Measures::2D::Fisher模块,但我不确定它是否与上面相同。

use Text::NSP::Measures::2D::Fisher::twotailed;

my $npp = 10003821; 
my $n1p = 8842559; 
my $np1 = 12;  
my $n11 = 17;

my $twotailed_value = calculateStatistic(
    n11 => $n11,
    n1p => $n1p,
    np1 => $np1,
    npp => $npp,
);

if( (my $errorCode = getErrorCode()) ) {
  print STDERR $errorCode, " - ", getErrorMessage();
} else {
  print getStatisticName, "value for bigram is ", $twotailed_value, "\n";
}

但它没有给我任何东西

1 个答案:

答案 0 :(得分:0)

矩阵从R到perl不同。你不能使用相同的矩阵!

for perl这是矩阵(括号内):

          word2   ~word2
  word1   [n11]     n12 | [n1p]
 ~word1    n21      n22 |  n2p
           --------------
          [np1]     np2   [npp]

对于R,这是矩阵(括号内):

          word2   ~word2
  word1   [n11]    [n12] | n1p
 ~word1   [n21]    [n22] | n2p
           --------------
            np1     np2    npp