作者abliou (把青春freeze)
看板Perl
标题Re: [问题] PERL 怎麽算 P VALUE
时间Mon Sep 5 14:41:56 2011
※ 引述《sqrt1089 (李崩子)》之铭言:
: 如题
: 数据:
: 10 100 300 5000
: 25 100 300 5000
: 3 100 300 5000
: 59 100 300 5000
: 46 100 300 5000
: ....
: ...
: ..
: .
: 意思是说一个袋子里全部有5000颗球,有300颗是白球,其它4700颗是黑球
: 我一次取100颗出来观察,取n次,(n大概100次左右)。
: 第一次有10颗白球;第二次有25颗白球;第三次取到3颗,第四次取到59颗,...X100次
: 原本是有找到一个套件:use Math::GSL::Randist qw/:all/;
: $p = gsl_ran_hypergeometric($r, $n1, $n2, $t);
: 但这个模组一直灌不起来。
: 最後改用:use Statistics::R;
: 但是去测试後发现好慢,原因是 我一次丢四个数字给他,
: 他回传一个 P_VALUE (或是 1- P_VALUE) 回来
: 假设我取 n 次,就会丢 n 次的 四个数字给副程式
: 这样的话 副程式 就做了N次的开档关档的工作。<<<原因就是出在这
: 有什麽办法可以改善呢?谢谢。
: ####
: 程式码如下:
: open (FH,"test.txt")||die";#test.txt 就是 约100X4的数据如最上面
: while(<FH>){
: chomp;
: ..
: .
: $pvalue = &hypergeometric($get,$input,$included,$total);
: print $pvalue;
: }
: sub hypergeometric {
: my $common = shift;
: $common_gene -= 1;
: my $g1 = shift;
: my $g2 = shift;
: my $whole = shift;
: my $no_g1 = $whole - $g1;
: my $R = Statistics::R->new();
: $R->startR;
: $R->send(qq`
: x <- 0:$common; N1 <- $g1 \n
: N2 <- $no_g1; n <- $g2 \n
: ans=cumsum(dhyper(x,N1,N2,n)) \n
: print(ans)
: `);
: my $result = $R->read;
: my @value = split " ", $result;
: my $last_value = pop @value;
: my $ans = 1-$last_value;
: $R->stopR();
: return $ans;
: }
感觉写的很模糊 所以也没办法答的很清楚
现在假设你是要用t-test来求p-value好了
也许你可以尝试一些比较专门的统计模组
http://search.cpan.org/~yunfang/Statistics-TTest-1.1.0/TTest.pm
http://search.cpan.org/~swansun/Statistics-Distributions-Analyze-0.01
/lib/Statistics/Distributions/Analyze.pm
http://search.cpan.org/~mglee/Statistics-DependantTTest-0.03/DependantTTest.pm
http://search.cpan.org/~maggiexyz/PDL-Stats-0.5.5/Basic/stats_basic.pp
看你目前写的程式码 应该是使用R的interface跟perl做连结
如果很坚持要这麽使用 那就只好修改你send的指令 然後在传回perl做处理
不过如果你真的有这本事 我想直接用R处理会比较快
要不然就多开几个执行绪平行跑吧 反正你每次实验都是一个独立的个体
--
如果青春注定要向前跑
他妈的...那我的出口在那?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.0.109
1F:推 sqrt1089:T test 是2组DATA 算PVALUE的 09/05 14:51
3F:→ sqrt1089:才是我要的,只是个模组一直灌不成功~"~ 09/05 14:56
4F:→ abliou:哪种作业平台 你怎麽罐的 09/05 15:23
5F:推 sqrt1089:linux,灌法:进入CAPN後,install 模组 09/05 15:27
6F:→ abliou:错误讯息呢 09/05 15:28
7F:→ sqrt1089:好像是版本不符,灌了很多版本了 09/05 15:34
8F:→ dryman:是不是要先灌gsl啊? 09/05 16:07
9F:→ abliou:如果用cpan灌 缺的应该会自动帮你安装吧? 09/05 16:13