time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

binomial-test.js (1167B)


      1 var vows = require('vows');
      2 var assert = require('assert');
      3 var suite = vows.describe('jStat.distribution');
      4 
      5 require('../env.js');
      6 
      7 suite.addBatch({
      8   'binomial pdf': {
      9     'topic': function() {
     10       return jStat;
     11     },
     12     //checked against R's dbinom(k, n, p)
     13     'check pdf calculation': function(jStat) {
     14       var tol = 0.0000001;
     15       assert.epsilon(tol, jStat.binomial.pdf(10, 25, 0.5), 0.09741664);
     16       assert.epsilon(tol, jStat.binomial.pdf(50, 1000, 0.05), 0.05778798);
     17     },
     18     //Checked against r's pbinom(k, n, p)
     19     'check cdf calculation': function(jStat) {
     20       var tol = 0.0000001;
     21       assert.epsilon(tol, jStat.binomial.cdf(10, 25, 0.5), 0.2121781);
     22       assert.epsilon(tol, jStat.binomial.cdf(50, 1000, 0.05), 0.537529);
     23 
     24       assert.ok(Number.isNaN(jStat.binomial.cdf(10, 12, -1)));
     25       assert.ok(Number.isNaN(jStat.binomial.cdf(10, 12, 2)));
     26       assert.equal(jStat.binomial.cdf(12, 10, 0.5), 1);
     27       assert.equal(jStat.binomial.cdf(12, -1, 0.5), 1);
     28       assert.epsilon(tol,
     29                      jStat.binomial.cdf(101073, 101184, 0.9988219676207195),
     30                      0.7857313651);
     31     }
     32   }
     33 });
     34 
     35 suite.export(module);