time-to-botec/squiggle/node_modules/jstat/test/distribution/hypergeometric-test.js
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

43 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var vows = require('vows');
var assert = require('assert');
var suite = vows.describe('jStat.distribution');
require('../env.js');
suite.addBatch({
'hypergeometric pdf': {
'topic': function() {
return jStat;
},
'check pdf calculation': function(jStat) {
var tol = 0.0000001;
// How many 1s were obtained by sampling?
var successes = [10, 16];
// How big was the source population?
var population = [100, 3589];
// How many 1s were in it?
var available = [20, 16];
// How big a sample was taken?
var draws = [15, 2290];
// What was the probability of exactly this many 1s?
// Obtained from the calculator at
// <http://www.geneprof.org/GeneProf/tools/hypergeometric.jsp>
var answers = [0.000017532028090435493, 0.0007404996809672229];
for (var i = 0; i < answers.length; i++) {
// See if we get the right answer for each calculation.
var calculated = jStat.hypgeom.pdf(successes[i],
population[i],
available[i],
draws[i]);
// None of the answers should be NaN
assert(!isNaN(calculated));
// And they should all match
assert.epsilon(tol, calculated, answers[i]);
}
}
}
});
suite.export(module);