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,7 @@
# combination(r) generates a stream of combinations of r items from the input array.
def combination(r):
if r > length or r < 0 then empty
elif r == length then .
else ( [.[0]] + (.[1:]|combination(r-1))),
( .[1:]|combination(r))
end;

View file

@ -0,0 +1,26 @@
# a and b should be arrays:
def permutationTest(a; b):
def normalize(a;b): # mainly to avoid having to compute $sumab
(a|add) as $sa
| (b|add) as $sb
| (($sa + $sb)/((a|length) + (b|length))) as $avg
| [(a | map(.-$avg)), (b | map(.-$avg))];
# avg(a) - avg(b) (assuming ab==a+b and avg(ab) is 0)
def statistic(ab; a):
(a | add) as $suma
# (ab|add) should be 0, by normalization
| ($suma / (a|length)) +
($suma / ((ab|length) - (a|length)));
normalize(a;b)
| (a + b) as $ab # pooled observations
| .[0] as $a | .[1] as $b
| statistic($ab; $a) as $t_observed # observed difference in means
| reduce ($ab|combination($a|length)) as $perm # for each combination...
([0,0]; # state: [under,count]
if statistic($ab; $perm) <= $t_observed then .[0] += 1 else . end
| .[1] += 1 )
| .[0] * 100.0 / .[1] # under/count
;

View file

@ -0,0 +1,5 @@
def treatmentGroup: [85, 88, 75, 66, 25, 29, 83, 39, 97];
def controlGroup: [68, 41, 10, 49, 16, 65, 32, 92, 28, 98];
permutationTest(treatmentGroup; controlGroup) as $under
| "% under=\($under)", "% over=\(100 - $under)"