/usr/share/hyphy/TemplateBatchFiles/binomial.ibf is in hyphy-common 2.2.6+dfsg-3build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | /*___________________________________________________________________________________________________________*/
function extendedBinTail (ebn, ebp, ebx)
/*
returns the LEFT-tail probability for the extended binomial distribution
with ebn observations, ebp probability of success and ebx successes
i.e, Pr (X <= ebx | enb, ebp)
*/
{
if (ebp == 0)
{
return 0;
}
ebr = ebx$1; /* rounded to nearest integer */
currentBinCoeff = (1-ebp)^ebn; /*compute the first binomial coefficient */
binHead = 0;
for (ebk=0; ebk<=ebr; ebk=ebk+1)
{
binHead = binHead + currentBinCoeff;
currentBinCoeff = currentBinCoeff * (ebn-ebk) / (ebk+1) * ebp / (1-ebp);
}
if (ebx <= ebn$1)
{
binHead = binHead + currentBinCoeff*(ebx-ebr);
}
else
{
binHead = binHead + (1-binHead)*(ebx-ebr)/(ebn-ebn$1);
}
return binHead;
}
/*----------------------------------------------------------------------------*/
function computeBinTail (m,n,p)
/*
n - number of trials
m - cutoff point
p - probability of success
*/
{
if (m==0)
{
lastBinTerm = (1-p)^n;
return 1-lastBinTerm;
}
if (m==n)
{
lastBinTerm = p^n;
return 0;
}
upToTerm = m;
if (m>n$2)
{
m = n-m;
omp = 1-p;
binTail = p^n;
binTerm = n*omp*p^(n-1);
for (s=1; s<=m; s=s+1)
{
binTail = binTail + binTerm;
lastBinTerm = binTerm;
binTerm = binTerm * (n-s) * omp / (p*(s+1));
}
}
else
{
omp = 1-p;
binTail = omp^n;
binTerm = n*p*omp^(n-1);
for (s=1; s<=m; s=s+1)
{
binTail = binTail + binTerm;
lastBinTerm = binTerm;
binTerm = binTerm * (n-s) * p / (omp*(s+1));
}
binTail = 1-binTail;
}
return binTail;
}
|