September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,24 @@
// version 1.1.2
val data = intArrayOf(
85, 88, 75, 66, 25, 29, 83, 39, 97,
68, 41, 10, 49, 16, 65, 32, 92, 28, 98
)
fun pick(at: Int, remain: Int, accu: Int, treat: Int): Int {
if (remain == 0) return if (accu > treat) 1 else 0
return pick(at - 1, remain - 1, accu + data[at - 1], treat) +
if (at > remain) pick(at - 1, remain, accu, treat) else 0
}
fun main(args: Array<String>) {
var treat = 0
var total = 1.0
for (i in 0..8) treat += data[i]
for (i in 19 downTo 11) total *= i
for (i in 9 downTo 1) total /= i
val gt = pick(19, 9, 0, treat)
val le = (total - gt).toInt()
System.out.printf("<= : %f%% %d\n", 100.0 * le / total, le)
System.out.printf(" > : %f%% %d\n", 100.0 * gt / total, gt)
}

View file

@ -0,0 +1,20 @@
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})

View file

@ -1,30 +1,32 @@
/*REXX program performs a permutation test on N + M subjects (volunteers): */
/* ↑ ↑ */
/* │ │ */
/* │ └─────control population. */
/* └────────treatment population. */
/*REXX program performs a permutation test on N + M subjects (volunteers): */
/* ↑ ↑ */
/* │ │ */
/* │ └─────control population. */
/* └────────treatment population. */
n=9
data=85 88 75 66 25 29 83 39 97 68 41 10 49 16 65 32 92 28 98
w=words(data); m=w-n
say 'volunteer population given treatment:' right(n,length(w))
say ' control population given a placebo:' right(m,length(w))
data= 85 88 75 66 25 29 83 39 97 68 41 10 49 16 65 32 92 28 98
w=words(data); m=w-n
say 'w=' w
say 'volunteer population given treatment:' right(n, length(w) )
say ' control population given a placebo:' right(m, length(w) )
say
say 'treatment population efficacy % (percentages):' subword(data,1,n)
say ' control population placebo % (percentages):' subword(data,n+1)
say 'treatment population efficacy % (percentages):' subword(data, 1, n)
say ' control population placebo % (percentages):' subword(data, n+1 )
say
do v= 0 for w ; #.v=word(data,v+1) ; end
treat=0; do i= 0 to n-1 ; treat=treat+#.i ; end
tot=1; do j=19 to m+1 by -1 ; tot=tot*j ; end
do k= 9 to 1 by -1 ; tot=tot/k ; end
gt=picker(n+m, n, 0)
le=tot-gt
say "<= " format(100*le/tot,,3)'%' le /*display number with 3 decimal places.*/
say " > " format(100*gt/tot,,3)'%' gt /* " " " " " " */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
picker: procedure expose #. treat; parse arg it,rest,eff
if rest==0 then return eff>treat
if it>rest then q=picker(it-1, rest, eff)
do v= 0 for w ; #.v=word(data, v+1) ; end
treat=0; do i= 0 to n-1 ; treat=treat + #.i ; end
tot=1; do j= w to m+1 by -1 ; tot=tot * j ; end
do k=w%2 to 1 by -1 ; tot=tot / k ; end
GT=picker(n+m, n, 0) /*compute the GT value from PICKER func*/
LE=tot - GT /* " " LE " via subtraction.*/
say "<= " format(100 * LE / tot, ,3)'%' LE /*display number with 3 decimal places.*/
say " > " format(100 * GT / tot, ,3)'%' GT /* " " " " " " */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
picker: procedure expose #. treat; parse arg it,rest,eff /*get args.*/
if rest==0 then return eff > treat /*Zero ? */
if it>rest then q=picker(it-1, rest, eff) /*recurse. */
else q=0
itP=it-1
return picker(itP, rest-1, eff+#.itP) + q
itP=it - 1 /*temp var.*/
return picker(itP, rest - 1, eff+#.itP) + q /*recurse. */

View file

@ -1,20 +1,20 @@
func statistic(ab, a) {
var(sumab, suma) = (ab.sum, a.sum);
var(sumab, suma) = (ab.sum, a.sum)
suma/a.size - ((sumab-suma) / (ab.size-a.size))
}
func permutationTest(a, b) {
var ab = (a + b);
var tobs = statistic(ab, a);
var under = (var count = 0);
ab.combinations(a.len).each { |perm|
statistic(ab, perm) <= tobs && (under += 1);
count += 1;
};
under * 100 / count;
var ab = (a + b)
var tobs = statistic(ab, a)
var under = (var count = 0)
ab.combinations(a.len, {|*perm|
statistic(ab, perm) <= tobs && (under += 1)
count += 1
})
under * 100 / count
}
var treatmentGroup = [85, 88, 75, 66, 25, 29, 83, 39, 97];
var controlGroup = [68, 41, 10, 49, 16, 65, 32, 92, 28, 98];
var under = permutationTest(treatmentGroup, controlGroup);
say ("under=%.2f%%, over=%.2f%%" % (under, 100 - under));
var treatmentGroup = [85, 88, 75, 66, 25, 29, 83, 39, 97]
var controlGroup = [68, 41, 10, 49, 16, 65, 32, 92, 28, 98]
var under = permutationTest(treatmentGroup, controlGroup)
say ("under=%.2f%%, over=%.2f%%" % (under, 100 - under))

View file

@ -0,0 +1,12 @@
fcn permutationTest(a,b){
ab := a.extend(b);
tObs := a.sum(0);
combs := Utils.Helpers.pickNFrom(a.len(),ab); // 92,378
under := combs.reduce('wrap(sum,perm){ sum+(perm.sum(0) <= tObs) },0);
100.0 * under / combs.len();
}
treatmentGroup := T(85, 88, 75, 66, 25, 29, 83, 39, 97);
controlGroup := T(68, 41, 10, 49, 16, 65, 32, 92, 28, 98);
under := permutationTest(treatmentGroup, controlGroup);
println("Under =%6.2f%%\nOver =%6.2f%%".fmt(under, 100.0 - under));