Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,9 +1,11 @@
A new medical treatment was tested on a population of <math>n + m</math>
volunteers, with each volunteer randomly assigned either to a group of
<math>n</math> treatment subjects, or to a group of <math>m</math> control subjects. Members of
the treatment group were given the treatment, and members of the
control group were given a placebo. The effect of the treatment or
placebo on each volunteer was measured and reported in this table.
<math>n</math> treatment subjects, or to a group of <math>m</math> control subjects.
Members of the treatment group were given the treatment,
and members of the control group were given a placebo.
The effect of the treatment or placebo on each volunteer
was measured and reported in this table.
{| style="text-align: left; width: 50%;" border="4" cellpadding="2" cellspacing="2"
|+ Table of experimental results

View file

@ -1,9 +1,8 @@
import std.stdio, std.algorithm, std.array, combinations3;
auto permutationTest(T)(in T[] a, in T[] b) /*pure nothrow*/ {
auto permutationTest(T)(in T[] a, in T[] b) pure nothrow @safe {
immutable tObs = a.sum;
//auto combs = combinations!false(a ~ b, a.length); // Not a Range.
const combs = combinations(a ~ b, a.length).array; // Slow.
auto combs = combinations!false(a ~ b, a.length);
immutable under = combs.count!(perm => perm.sum <= tObs);
return under * 100.0 / combs.length;
}

View file

@ -1,12 +1,12 @@
import std.stdio, std.algorithm, std.range;
void main() @safe {
import std.stdio, std.algorithm, std.range;
void main() {
immutable treatment = [85, 88, 75, 66, 25, 29, 83, 39, 97];
immutable control = [68, 41, 10, 49, 16, 65, 32, 92, 28, 98];
immutable both = treatment ~ control;
immutable sTreat = treatment.sum;
T pick(T)(in size_t at, in size_t remain, in T accu) pure nothrow {
T pick(T)(in size_t at, in size_t remain, in T accu) pure nothrow @safe @nogc {
if (remain == 0)
return accu > sTreat;

View file

@ -1,30 +1,30 @@
/*REXX program does a permutation test on N + M subjects (volunteers):*/
/* ↑ ↑ */
/* │ │ */
/* │ └─────control population*/
/* └────────treatment population*/
/* ↑ ↑ */
/* │ │ */
/* │ └─────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))
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
total=1; do j=19 to m+1 by -1 ; total=total*j ; end
do k= 9 to 1 by -1 ; total=total/k ; end
gt=pick(n+m, n, 0)
do v= 0 for w ; #.v=word(data,v+1) ; end
treat=0; do i= 0 to n-1 ; treat=treat+#.i ; end
total=1; do j=19 to m+1 by -1 ; total=total*j ; end
do k= 9 to 1 by -1 ; total=total/k ; end
gt=picker(n+m, n, 0)
le=total-gt
say "<= " format(100*le/total,,3)'%' le /*show 3 decimal places.*/
say " > " format(100*gt/total,,3)'%' gt
say "<= " format(100*le/total,,3)'%' le /*show 3 decimal places.*/
say " > " format(100*gt/total,,3)'%' gt
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────PICK subroutine─────────────────────*/
pick: procedure expose #. treat; parse arg it,rest,eff
/*──────────────────────────────────PICKER subroutine───────────────────*/
picker: procedure expose #. treat; parse arg it,rest,eff
if rest==0 then return eff>treat
if it>rest then q=pick(it-1, rest, eff)
if it>rest then q=picker(it-1, rest, eff)
else q=0
itP=it-1
return pick(itP, rest-1, eff+#.itP) + q
return picker(itP, rest-1, eff+#.itP) + q

View file

@ -0,0 +1,20 @@
def statistic(ab, a)
sumab, suma = ab.inject(:+).to_f, a.inject(:+).to_f
suma / a.size - (sumab - suma) / (ab.size - a.size)
end
def permutationTest(a, b)
ab = a + b
tobs = statistic(ab, a)
under = count = 0
ab.combination(a.size) do |perm|
under += 1 if statistic(ab, perm) <= tobs
count += 1
end
under * 100.0 / count
end
treatmentGroup = [85, 88, 75, 66, 25, 29, 83, 39, 97]
controlGroup = [68, 41, 10, 49, 16, 65, 32, 92, 28, 98]
under = permutationTest(treatmentGroup, controlGroup)
puts "under=%.2f%%, over=%.2f%%" % [under, 100 - under]