RosettaCodeData/Task/Permutation-test/Sidef/permutation-test.sidef

21 lines
608 B
Text
Raw Permalink Normal View History

2016-12-05 23:44:36 +01:00
func statistic(ab, a) {
2017-09-23 10:01:46 +02:00
var(sumab, suma) = (ab.sum, a.sum)
2016-12-05 23:44:36 +01:00
suma/a.size - ((sumab-suma) / (ab.size-a.size))
}
func permutationTest(a, b) {
2017-09-23 10:01:46 +02:00
var ab = (a + b)
var tobs = statistic(ab, a)
var under = (var count = 0)
ab.combinations(a.len, {|*perm|
statistic(ab, perm) <= tobs && (under += 1)
count += 1
})
under * 100 / count
2016-12-05 23:44:36 +01:00
}
2017-09-23 10:01:46 +02:00
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))