kumaraswamy-test.js (10151B)
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 'kumaraswamy pdf': { 9 'topic': function() { 10 return jStat; 11 }, 12 // Checked against R's dkumar(p, shape1, shape2, log=FALSE) in package VGAM 13 // install.packages("VGAM") 14 // library("VGAM") 15 // options(digits=10) 16 // dkumar(c(-5, 5), 2, 2) 17 'check pdf calculation': function(jStat) { 18 var tol = 0.0000001; 19 // outside support 20 assert.epsilon(tol, jStat.kumaraswamy.pdf(-5, 2, 2), 0); 21 assert.epsilon(tol, jStat.kumaraswamy.pdf(5, 2, 2), 0); 22 } 23 }, 24 'kumaraswamy inv': { 25 'topic': function() { 26 return jStat; 27 }, 28 // Checked against R's 29 // qkumar(p, shape1, shape2, lower.tail=TRUE, log.p=FALSE) in package VGAM 30 // install.packages("VGAM") 31 // library("VGAM") 32 // options(digits=10) 33 // qkumar(c(0, 0.5, 1), 0.5, 0.5) 34 // qkumar(c(0, 0.5, 1), 0.8, 1) 35 // qkumar(c(0, 0.5, 1), 1, 0.4) 36 // qkumar(c(0, 0.5, 1), 0.6, 1.2) 37 // qkumar(c(0, 0.5, 1), 1, 1) 38 // qkumar(c(0, 0.5, 1), 2, 1) 39 // qkumar(c(0, 0.5, 1), 1.5, 1.5) 40 // qkumar(c(0, 0.5, 1), 7, 25) 41 'check inv calculation': function(jStat) { 42 var tol = 0.0000001; 43 // 'U'-shaped distribution 44 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 0.5, 0.5), 0); 45 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 0.5, 0.5), 0.5625); 46 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 0.5, 0.5), 1); 47 48 // 'L'-shaped distribution 49 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 0.8, 1), 0); 50 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 0.8, 1), 0.4204482076); 51 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 0.8, 1), 1); 52 53 // reversed-'L'-shaped distribution 54 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 1, 0.4), 0); 55 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 1, 0.4), 0.8232233047); 56 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 1, 0.4), 1); 57 58 // sideways-'S'-shaped distribution 59 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 0.6, 1.2), 0); 60 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 0.6, 1.2), 0.2533532737); 61 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 0.6, 1.2), 1); 62 63 // flat distribution 64 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 1, 1), 0); 65 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 1, 1), 0.5); 66 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 1, 1), 1); 67 68 // '/'-shaped distribution 69 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 2, 1), 0); 70 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 2, 1), 0.7071067812); 71 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 2, 1), 1); 72 73 // inverted-'U'-shaped distribution 74 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 1.5, 1.5), 0); 75 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 1.5, 1.5), 0.5154248709); 76 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 1.5, 1.5), 1); 77 78 // peaked distribution 79 assert.epsilon(tol, jStat.kumaraswamy.inv(0, 7, 25), 0); 80 assert.epsilon(tol, jStat.kumaraswamy.inv(0.5, 7, 25), 0.5979941923); 81 assert.epsilon(tol, jStat.kumaraswamy.inv(1, 7, 25), 1); 82 } 83 }, 84 85 'kumaraswamy pdf': { 86 'topic': function() { 87 return jStat; 88 }, 89 // Checked against R's dkumar(p, shape1, shape2, log=FALSE) in package VGAM 90 // install.packages("VGAM") 91 // library("VGAM") 92 // options(digits=10) 93 // dkumar(c(0, 0.5, 1), 0.5, 0.5) 94 // dkumar(c(0, 0.5, 1), 0.8, 1) # Note: Incorrectly returns NaN for x = 1! 95 // dkumar(c(0, 0.5, 1), 1, 0.4) # Note: Incorrectly returns NaN for x = 0! 96 // dkumar(c(0, 0.5, 1), 0.6, 1.2) 97 // dkumar(c(0, 0.5, 1), 1.3, 0.5) 98 // dkumar(c(0, 0.5, 1), 1, 1) # Note: Incorrectly returns NaN for x = 0 and x = 1! 99 // dkumar(c(0, 0.5, 1), 2, 1) # Note: Incorrectly returns NaN for x = 1! 100 // dkumar(c(0, 0.5, 1), 1, 1.5) # Note: Incorrectly returns NaN for x = 0! 101 // dkumar(c(0, 0.5, 1), 1.5, 1.5) 102 // dkumar(c(0, 0.5, 1), 7, 25) 103 'check pdf calculation': function(jStat) { 104 var tol = 0.0000001; 105 // 'U'-shaped distribution 106 assert.equal(jStat.kumaraswamy.pdf(0, 0.5, 0.5), Infinity); 107 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 0.5, 0.5), 0.6532814824); 108 assert.equal(jStat.kumaraswamy.pdf(1, 0.5, 0.5), Infinity); 109 110 // 'L'-shaped distribution 111 assert.equal(jStat.kumaraswamy.pdf(0, 0.8, 1), Infinity); 112 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 0.8, 1), 0.918958684); 113 assert.epsilon(tol, jStat.kumaraswamy.pdf(1, 0.8, 1), 0.8); 114 115 // reversed-'L'-shaped distribution 116 assert.epsilon(tol, jStat.kumaraswamy.pdf(0, 1, 0.4), 0.4); 117 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 1, 0.4), 0.6062866266); 118 assert.equal(jStat.kumaraswamy.pdf(1, 1, 0.4), Infinity); 119 120 // sideways-'S'-shaped distribution 121 assert.equal(jStat.kumaraswamy.pdf(0, 0.6, 1.2), Infinity); 122 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 0.6, 1.2), 0.7657783992); 123 assert.epsilon(tol, jStat.kumaraswamy.pdf(1, 0.6, 1.2), 0); 124 125 // sideways-'Z'-shaped distribution 126 assert.epsilon(tol, jStat.kumaraswamy.pdf(0, 1.3, 0.5), 0); 127 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 1.3, 0.5), 0.6851052165); 128 assert.equal(jStat.kumaraswamy.pdf(1, 1.3, 0.5), Infinity); 129 130 // flat distribution 131 assert.epsilon(tol, jStat.kumaraswamy.pdf(0, 1, 1), 1); 132 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 1, 1), 1); 133 assert.epsilon(tol, jStat.kumaraswamy.pdf(1, 1, 1), 1); 134 135 // '/'-shaped distribution 136 assert.epsilon(tol, jStat.kumaraswamy.pdf(0, 2, 1), 0); 137 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 2, 1), 1); 138 assert.epsilon(tol, jStat.kumaraswamy.pdf(1, 2, 1), 2); 139 140 // '\'-shaped distribution 141 assert.epsilon(tol, jStat.kumaraswamy.pdf(0, 1, 1.5), 1.5); 142 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 1, 1.5), 1.060660172); 143 assert.epsilon(tol, jStat.kumaraswamy.pdf(1, 1, 1.5), 0); 144 145 // inverted-'U'-shaped distribution 146 assert.epsilon(tol, jStat.kumaraswamy.pdf(0, 1.5, 1.5), 0); 147 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 1.5, 1.5), 1.279186452); 148 assert.epsilon(tol, jStat.kumaraswamy.pdf(1, 1.5, 1.5), 0); 149 150 // peaked distribution 151 assert.epsilon(tol, jStat.kumaraswamy.pdf(0, 7, 25), 0); 152 assert.epsilon(tol, jStat.kumaraswamy.pdf(0.5, 7, 25), 2.265208101); 153 assert.epsilon(tol, jStat.kumaraswamy.pdf(1, 7, 25), 0); 154 } 155 }, 156 'kumaraswamy cdf': { 157 'topic': function() { 158 return jStat; 159 }, 160 // Checked against R's pkumar(q, shape1, shape2, lower.tail = TRUE, log.p = FALSE) in package VGAM 161 // install.packages("VGAM") 162 // library("VGAM") 163 // options(digits=10) 164 // pkumar(c(0, 0.5, 1), 0.5, 0.5) 165 // pkumar(c(0, 0.5, 1), 0.8, 1) # Note: Incorrectly returns NaN for x = 1! 166 // pkumar(c(0, 0.5, 1), 1, 0.4) # Note: Incorrectly returns NaN for x = 0! 167 // pkumar(c(0, 0.5, 1), 0.6, 1.2) 168 // pkumar(c(0, 0.5, 1), 1.3, 0.5) 169 // pkumar(c(0, 0.5, 1), 1, 1) # Note: Incorrectly returns NaN for x = 0 and x = 1! 170 // pkumar(c(0, 0.5, 1), 2, 1) # Note: Incorrectly returns NaN for x = 1! 171 // pkumar(c(0, 0.5, 1), 1, 1.5) # Note: Incorrectly returns NaN for x = 0! 172 // pkumar(c(0, 0.5, 1), 1.5, 1.5) 173 // pkumar(c(0, 0.5, 1), 7, 25) 174 // pkumar(c(-5, 5), 2, 2) 175 'check cdf calculation': function(jStat) { 176 var tol = 0.0000001; 177 // 'U'-shaped distribution 178 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 0.5, 0.5), 0); 179 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 0.5, 0.5), 0.4588038999); 180 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 0.5, 0.5), 1); 181 182 // 'L'-shaped distribution 183 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 0.8, 1), 0); 184 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 0.8, 1), 0.5743491775); 185 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 0.8, 1), 1); 186 187 // reversed-'L'-shaped distribution 188 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 1, 0.4), 0); 189 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 1, 0.4), 0.2421417167); 190 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 1, 0.4), 1); 191 192 // sideways-'S'-shaped distribution 193 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 0.6, 1.2), 0); 194 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 0.6, 1.2), 0.7257468009); 195 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 0.6, 1.2), 1); 196 197 // sideways-'Z'-shaped distribution 198 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 1.3, 0.5), 0); 199 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 1.3, 0.5), 0.2293679206); 200 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 1.3, 0.5), 1); 201 202 // flat distribution 203 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 1, 1), 0); 204 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 1, 1), 0.5); 205 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 1, 1), 1); 206 207 // '/'-shaped distribution 208 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 2, 1), 0); 209 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 2, 1), 0.25); 210 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 2, 1), 1); 211 212 // '\'-shaped distribution 213 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 1, 1.5), 0); 214 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 1, 1.5), 0.6464466094); 215 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 1, 1.5), 1); 216 217 // inverted-'U'-shaped distribution 218 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 1.5, 1.5), 0); 219 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 1.5, 1.5), 0.4802446206); 220 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 1.5, 1.5), 1); 221 222 // peaked distribution 223 assert.epsilon(tol, jStat.kumaraswamy.cdf(0, 7, 25), 0); 224 assert.epsilon(tol, jStat.kumaraswamy.cdf(0.5, 7, 25), 0.1780530605); 225 assert.epsilon(tol, jStat.kumaraswamy.cdf(1, 7, 25), 1); 226 227 // outside support 228 assert.epsilon(tol, jStat.kumaraswamy.cdf(-5, 2, 2), 0); 229 assert.epsilon(tol, jStat.kumaraswamy.cdf(5, 2, 2), 1); 230 } 231 }, 232 }); 233 234 suite.export(module);