Permutation test: Difference between revisions

m
moved Phix/PicoLisp below Perl
m (moved Phix/PicoLisp below Perl)
Line 796:
<pre><=: 80551 87.1972%
>: 11827 12.8028%</pre>
 
=={{header|Phix}}==
{{Trans|C}}
<lang Phix>constant data = {85, 88, 75, 66, 25, 29, 83, 39, 97,
68, 41, 10, 49, 16, 65, 32, 92, 28, 98 }
function pick(int at, int remain, int accu, int treat)
if remain=0 then return iff(accu>treat?1:0) end if
return pick(at-1, remain-1, accu+data[at], treat) +
iff(at>remain?pick(at-1, remain, accu, treat):0)
end function
int treat = 0, le, gt
atom total = 1;
for i=1 to 9 do treat += data[i] end for
for i=19 to 11 by -1 do total *= i end for
for i=9 to 1 by -1 do total /= i end for
gt = pick(19, 9, 0, treat)
le = total - gt;
printf(1,"<= : %f%% %d\n > : %f%% %d\n",
{100*le/total, le, 100*gt/total, gt})</lang>
{{out}}
<pre>
<= : 87.197168% 80551
> : 12.802832% 11827
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(load "@lib/simul.l") # For 'subsets'
 
(scl 2)
 
(de _stat (A)
(let (LenA (length A) SumA (apply + A))
(-
(*/ SumA LenA)
(*/ (- SumAB SumA) (- LenAB LenA)) ) ) )
 
(de permutationTest (A B)
(let
(AB (append A B)
SumAB (apply + AB)
LenAB (length AB)
Tobs (_stat A)
Count 0 )
(*/
(sum
'((Perm)
(inc 'Count)
(and (>= Tobs (_stat Perm)) 1) )
(subsets (length A) AB) )
100.0
Count ) ) )
 
(setq
*TreatmentGroup (0.85 0.88 0.75 0.66 0.25 0.29 0.83 0.39 0.97)
*ControlGroup (0.68 0.41 0.10 0.49 0.16 0.65 0.32 0.92 0.28 0.98) )
 
(let N (permutationTest *TreatmentGroup *ControlGroup)
(prinl "under = " (round N) "%, over = " (round (- 100.0 N)) "%") )</lang>
{{out}}
<pre>under = 87.85%, over = 12.15%</pre>
 
=={{header|Perl}}==
Line 983 ⟶ 919:
Less or Equal: %87.197168
</pre>
 
=={{header|Phix}}==
{{Trans|C}}
<lang Phix>constant data = {85, 88, 75, 66, 25, 29, 83, 39, 97,
68, 41, 10, 49, 16, 65, 32, 92, 28, 98 }
function pick(int at, int remain, int accu, int treat)
if remain=0 then return iff(accu>treat?1:0) end if
return pick(at-1, remain-1, accu+data[at], treat) +
iff(at>remain?pick(at-1, remain, accu, treat):0)
end function
int treat = 0, le, gt
atom total = 1;
for i=1 to 9 do treat += data[i] end for
for i=19 to 11 by -1 do total *= i end for
for i=9 to 1 by -1 do total /= i end for
gt = pick(19, 9, 0, treat)
le = total - gt;
printf(1,"<= : %f%% %d\n > : %f%% %d\n",
{100*le/total, le, 100*gt/total, gt})</lang>
{{out}}
<pre>
<= : 87.197168% 80551
> : 12.802832% 11827
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(load "@lib/simul.l") # For 'subsets'
 
(scl 2)
 
(de _stat (A)
(let (LenA (length A) SumA (apply + A))
(-
(*/ SumA LenA)
(*/ (- SumAB SumA) (- LenAB LenA)) ) ) )
 
(de permutationTest (A B)
(let
(AB (append A B)
SumAB (apply + AB)
LenAB (length AB)
Tobs (_stat A)
Count 0 )
(*/
(sum
'((Perm)
(inc 'Count)
(and (>= Tobs (_stat Perm)) 1) )
(subsets (length A) AB) )
100.0
Count ) ) )
 
(setq
*TreatmentGroup (0.85 0.88 0.75 0.66 0.25 0.29 0.83 0.39 0.97)
*ControlGroup (0.68 0.41 0.10 0.49 0.16 0.65 0.32 0.92 0.28 0.98) )
 
(let N (permutationTest *TreatmentGroup *ControlGroup)
(prinl "under = " (round N) "%, over = " (round (- 100.0 N)) "%") )</lang>
{{out}}
<pre>under = 87.85%, over = 12.15%</pre>
 
=={{header|PureBasic}}==
7,805

edits