Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,20 @@
func statistic(ab, a) {
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 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,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)"