README.md (5104B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Quantile Function 22 23 > [Negative binomial][negative-binomial-distribution] distribution [quantile function][quantile-function]. 24 25 <section class="intro"> 26 27 The [quantile function][quantile-function] for a [negative binomial][negative-binomial-distribution] random variable `X` returns for any `k` satisfying `0 <= k <= 1` the value `x` for which 28 29 <!-- <equation class="equation" label="eq:negative_binomial_quantile_function" align="center" raw="F(x-1;r,p) < k \le F(x;r,p)" alt="Quantile for a negative binomial distribution."> --> 30 31 <div class="equation" align="center" data-raw-text="F(x-1;r,p) < k \le F(x;r,p)" data-equation="eq:negative_binomial_quantile_function"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/quantile/docs/img/equation_negative_binomial_quantile_function.svg" alt="Quantile for a negative binomial distribution."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 holds, where `F` is the cumulative distribution function (CDF) of a negative binomial distribution with parameters `r` and `p`, where `r` is the number of successes until the experiment is stopped and `p` is the success probability. The random variable `X` denotes the number of failures until the `r` success is reached. 39 40 </section> 41 42 <!-- /.intro --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var quantile = require( '@stdlib/stats/base/dists/negative-binomial/quantile' ); 50 ``` 51 52 #### quantile( k, r, p ) 53 54 Evaluates the [quantile function][quantile-function] for a [negative binomial][negative-binomial-distribution] distribution with number of successes until experiment is stopped `r` and success probability `p`. 55 56 ```javascript 57 var y = quantile( 0.9, 20.0, 0.2 ); 58 // returns 106 59 60 y = quantile( 0.9, 20.0, 0.8 ); 61 // returns 8 62 63 y = quantile( 0.5, 10.0, 0.4 ); 64 // returns 14 65 66 y = quantile( 0.0, 10.0, 0.9 ); 67 // returns 0 68 ``` 69 70 If provided an input value `k` outside of `[0,1]`, the function returns `NaN`. 71 72 ```javascript 73 var y = quantile( 1.1, 20.0, 0.5 ); 74 // returns NaN 75 76 y = quantile( -0.1, 20.0, 0.5 ); 77 // returns NaN 78 ``` 79 80 While `r` can be interpreted as the number of successes until the experiment is stopped, the [negative binomial][negative-binomial-distribution] distribution is also defined for non-integers `r`. In this case, `r` denotes shape parameter of the [gamma mixing distribution][negative-binomial-mixture-representation]. 81 82 ```javascript 83 var y = quantile( 0.5, 15.5, 0.5 ); 84 // returns 15 85 86 y = quantile( 0.3, 7.4, 0.4 ); 87 // returns 8 88 ``` 89 90 If provided a `r` which is not a positive number, the function returns `NaN`. 91 92 ```javascript 93 var y = quantile( 0.5, 0.0, 0.5 ); 94 // returns NaN 95 96 y = quantile( 0.5, -2.0, 0.5 ); 97 // returns NaN 98 ``` 99 100 If provided `NaN` as any argument, the function returns `NaN`. 101 102 ```javascript 103 var y = quantile( NaN, 20.0, 0.5 ); 104 // returns NaN 105 106 y = quantile( 0.3, NaN, 0.5 ); 107 // returns NaN 108 109 y = quantile( 0.3, 20.0, NaN ); 110 // returns NaN 111 ``` 112 113 If provided a success probability `p` outside of `[0,1]`, the function returns `NaN`. 114 115 ```javascript 116 var y = quantile( 0.3, 20.0, -1.0 ); 117 // returns NaN 118 119 y = quantile( 0.3, 20.0, 1.5 ); 120 // returns NaN 121 ``` 122 123 #### quantile.factory( r, p ) 124 125 Returns a function for evaluating the [quantile function][quantile-function] for a [negative binomial][negative-binomial-distribution] distribution with number of successes until experiment is stopped `r` and success probability `p`. 126 127 ```javascript 128 var myquantile = quantile.factory( 10.0, 0.5 ); 129 var y = myquantile( 0.1 ); 130 // returns 5 131 132 y = myquantile( 0.9 ); 133 // returns 16 134 ``` 135 136 </section> 137 138 <!-- /.usage --> 139 140 <section class="examples"> 141 142 ## Examples 143 144 <!-- eslint no-undef: "error" --> 145 146 ```javascript 147 var randu = require( '@stdlib/random/base/randu' ); 148 var quantile = require( '@stdlib/stats/base/dists/negative-binomial/quantile' ); 149 150 var i; 151 var k; 152 var r; 153 var p; 154 var y; 155 156 for ( i = 0; i < 10; i++ ) { 157 k = randu(); 158 r = randu() * 100; 159 p = randu(); 160 y = quantile( k, r, p ); 161 console.log( 'k: %d, r: %d, p: %d, Q(k;r,p): %d', k.toFixed( 4 ), r.toFixed( 4 ), p.toFixed( 4 ), y ); 162 } 163 ``` 164 165 </section> 166 167 <!-- /.examples --> 168 169 <section class="links"> 170 171 [negative-binomial-mixture-representation]: https://en.wikipedia.org/wiki/Negative_binomial_distribution#Gamma.E2.80.93Poisson_mixture 172 173 [negative-binomial-distribution]: https://en.wikipedia.org/wiki/Negative_binomial_distribution 174 175 [quantile-function]: https://en.wikipedia.org/wiki/Quantile_function 176 177 </section> 178 179 <!-- /.links -->