Re: [問題] PERL 怎麼算 P VALUE
※ 引述《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
推
09/05 14:51, , 1F
09/05 14:51, 1F
推
09/05 14:56, , 2F
09/05 14:56, 2F
→
09/05 14:56, , 3F
09/05 14:56, 3F
→
09/05 15:23, , 4F
09/05 15:23, 4F
推
09/05 15:27, , 5F
09/05 15:27, 5F
→
09/05 15:28, , 6F
09/05 15:28, 6F
→
09/05 15:34, , 7F
09/05 15:34, 7F
→
09/05 16:07, , 8F
09/05 16:07, 8F
→
09/05 16:13, , 9F
09/05 16:13, 9F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):