time-to-botec

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

chisquare-test.js (1820B)


      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   'chisquare pdf': {
      9     'topic': function() {
     10       return jStat;
     11     },
     12     //Checked against R dchisq(x,df)
     13     'check pdf calculation': function(jStat) {
     14       var tol = 0.0000001;
     15       assert.epsilon(tol, jStat.chisquare.pdf(3.5, 10), 0.03395437);
     16     },
     17     // Checked against R dchisq(x,df)
     18     //   dchisq(0, 5)
     19     //   dchisq(0, 2)
     20     //   dchisq(0, 1)
     21     'check pdf calculation at x = 0.0': function(jStat) {
     22       var tol = 0.0000001;
     23       assert.epsilon(tol, jStat.chisquare.pdf(0.0, 5), 0.0);
     24       assert.epsilon(tol, jStat.chisquare.pdf(0.0, 2), 0.5);
     25       assert.equal(jStat.chisquare.pdf(0.0, 1), Infinity);
     26     },
     27     'check pdf calculation at x < 0': function(jStat) {
     28       var tol = 0.0000001;
     29       assert.epsilon(tol, jStat.chisquare.pdf(-10, 8), 0.0);
     30     },
     31     //Checked against R's pchisq(x, df)
     32     'check cdf calculation': function(jStat) {
     33       var tol = 0.0000001;
     34       assert.epsilon(tol, jStat.chisquare.cdf(2.5, 8), 0.03826905);
     35     },
     36     // Checked against R's pchisq(q, df, ncp = 0, lower.tail = TRUE, log.p = FALSE):
     37     //    pchisq(-5, 21)
     38     'check cdf calculation when x outside support (x < 0)': function(jStat) {
     39       var tol = 0.0000001;
     40       assert.epsilon(tol, jStat.chisquare.cdf(-5, 21), 0);
     41     },
     42     //Checked against R's qchisq(x, df)
     43     'check inv calculation': function(jStat) {
     44       var tol = 0.00001;
     45       assert.epsilon(tol, jStat.chisquare.inv(0.95, 10), 18.30704);
     46     },
     47     //Checked against R's qchisq(x, df)
     48     'check inv calculation again': function(jStat) {
     49       var tol = 0.00001;
     50       assert.epsilon(tol, jStat.chisquare.inv(0.85, 10), 14.53394);
     51     }
     52   },
     53 });
     54 
     55 suite.export(module);