[問題] PERL 怎麼算 P VALUE
如題
數據:
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;
}
--
\ ∩──、 =====
\/ ● , \ ======
/\( ● ¯● |つ
| ╳_入_ノ ミ ︵ 用這種餌
(_/ ノ / / 也想讓本大爺上鉤…
/\___ノ_/ / ======
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.215.174
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):