inverse-gamma-test.js (1650B)
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 'inverse gamma pdf': { 9 'topic': function() { 10 return jStat; 11 }, 12 13 // Checked against R's densigamma(x, alpha, beta) from pscl package 14 // install.packages("pscl") 15 // library("pscl") 16 // densigamma(0.5, 1, 1) 17 // densigamma(0.25, 10, 2) 18 // densigamma(0.95, 18, 10) 19 // densigamma(-5, 2, 4) # Note: This incorrectly throws an error! 20 'check pdf': function(jStat) { 21 tol = 0.000001; 22 assert.epsilon(tol, jStat.invgamma.pdf(0.5, 1, 1), 0.5413411329); 23 assert.epsilon(tol, jStat.invgamma.pdf(0.25, 10, 2), 3.970461353); 24 assert.epsilon(tol, jStat.invgamma.pdf(0.95, 18, 10), 0.1998306597); 25 assert.epsilon(tol, jStat.invgamma.pdf(-5, 2, 4), 0); 26 }, 27 28 //Checked against R's pigamma(q, shape, scale), which R calls alpha, beta 29 //from the pscl package 30 'check cdf': function(jStat) { 31 tol = 0.000001; 32 assert.epsilon(tol, jStat.invgamma.cdf(0.5, 1, 1), 0.1353353); 33 assert.epsilon(tol, jStat.invgamma.cdf(0.25, 10, 2), 0.7166243); 34 assert.epsilon(tol, jStat.invgamma.cdf(0.95, 18, 10), 0.9776673); 35 assert.epsilon(tol, jStat.invgamma.cdf(-5, 5, 20), 0); 36 }, 37 38 //Checked against R's qigamma(p, shape, rate = 1/scale) 39 //from the pscl package 40 'check inv': function(jStat) { 41 tol = 0.00001; 42 assert.epsilon(tol, jStat.invgamma.inv(0.135, 1, 1), 0.4993806); 43 assert.epsilon(tol, jStat.invgamma.inv(0.716, 10, 2), 0.2498429); 44 } 45 }, 46 }); 47 48 suite.export(module);