Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
20
Task/Permutation-test/Sidef/permutation-test.sidef
Normal file
20
Task/Permutation-test/Sidef/permutation-test.sidef
Normal 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));
|
||||
7
Task/Permutation-test/jq/permutation-test-1.jq
Normal file
7
Task/Permutation-test/jq/permutation-test-1.jq
Normal 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;
|
||||
26
Task/Permutation-test/jq/permutation-test-2.jq
Normal file
26
Task/Permutation-test/jq/permutation-test-2.jq
Normal 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
|
||||
;
|
||||
5
Task/Permutation-test/jq/permutation-test-3.jq
Normal file
5
Task/Permutation-test/jq/permutation-test-3.jq
Normal 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)"
|
||||
Loading…
Add table
Add a link
Reference in a new issue