Permutation test: Difference between revisions
→{{header|jq}}: normalize
m (→{{header|REXX}}: added more whitespace, changed some comments.) |
(→{{header|jq}}: normalize) |
||
Line 571:
def permutationTest(a; b):
def normalize(a;b): # mainly to avoid having to compute $sumab
def statistic(ab; a): # avg(a) - avg(b) (assuming ab==a+b)▼
(
| (
| (($
| [(a | map(
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
| reduce ($ab|combination(a|length)) as $perm # for each combination...▼
|
▲ | reduce ($ab|combination($a|length)) as $perm # for each combination...
if statistic($ab; $perm) <= $t_observed then .[0] += 1 else . end
| .[1] += 1 )
Line 590 ⟶ 599:
permutationTest(treatmentGroup; controlGroup) as $under
| "% under=\($under)", "% over=\(100 - $under)"</lang>
{{out}}
$ jq -n -r -f permutation_test.jq
% under=87.
% over=12.
=={{header|Mathematica}}==
|