【问题标题】:Perl CPAN module fisher exact testPerl CPAN 模块 Fisher 精确测试
【发布时间】:2017-05-02 21:12:45
【问题描述】:

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";
}

但它没有给我任何东西

【问题讨论】:

  • 模块的单行描述:Text::NSP::Measures::2D::Fisher - Perl 模块,提供计算 Fisher 精确检验的方法。 也许你可以包含您在使用模块时使用的代码,并显示其结果与您的预期有何不同。如果您不确定结果是否匹配,那么您最适合进行测试并获得保证。
  • @DavidO 谢谢,我添加了我的代码
  • 该代码确实为我产生了输出:“202 - ngram 'n11' 的频率值不得超过边际总数。”它也应该适合你。当我在 Text::NSP 中查找该错误消息时,它显示“其中一个频率值 (n11) 超过了二元组的总数 (npp) 或边际总数 (n1p, np1)。 i>”,这对我来说没有任何意义,但对于需要这个模块的人来说应该是有意义的。
  • ...但这可能是因为$n11 在您的代码中设置为 17,大于设置为 12 的$np1。也许您只是输入了错误的值进入错误的位置。如果我在您的代码中交换 12 和 17,我会得到“Two Tailed Fishervalue for bigram is 0.0393735436982673
  • 是的,给定图表,np1n1p 都必须是 >= n11npp 必须是 >= 这三个。

标签: perl statistics


【解决方案1】:

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

对于 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

【讨论】:

    猜你喜欢
    • 2018-06-24
    • 2013-11-09
    • 2013-06-30
    • 1970-01-01
    • 2013-11-22
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    相关资源
    最近更新 更多