README.md (4373B)
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 # Mode 22 23 > [Negative binomial][negative-binomial-distribution] distribution [mode][mode]. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 The [mode][mode] for a [negative-binomial][negative-binomial-distribution] random variable is 30 31 <!-- <equation class="equation" label="eq:negative_binomial_mode" align="center" raw="\operatorname{mode}\left( X \right) = \begin{cases}{\big \lfloor }{\frac{p(r-1)}{1-p}}{\big \rfloor } & \text{ if }\ r>1\\ 0 & \text{ if } \ r\leq 1\end{cases}" alt="Mode for a negative-binomial distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="\operatorname{mode}\left( X \right) = \begin{cases}{\big \lfloor }{\frac{p(r-1)}{1-p}}{\big \rfloor } & \text{ if }\ r>1\\ 0 & \text{ if } \ r\leq 1\end{cases}" data-equation="eq:negative_binomial_mode"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/mode/docs/img/equation_negative_binomial_mode.svg" alt="Mode for a negative-binomial distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 where `r` is the number of successes until experiment is stopped and `p` is the success probability in each trial. The random variable `X` denotes the number of failures until the `r` success is reached. 41 42 </section> 43 44 <!-- /.intro --> 45 46 <!-- Package usage documentation. --> 47 48 <section class="usage"> 49 50 ## Usage 51 52 ```javascript 53 var mode = require( '@stdlib/stats/base/dists/negative-binomial/mode' ); 54 ``` 55 56 #### mode( r, p ) 57 58 Returns the [mode][mode] of a [negative binomial][negative-binomial-distribution] distribution with parameters `r` (number of successes until experiment is stopped) and `p` (success probability). 59 60 ```javascript 61 var v = mode( 100, 0.2 ); 62 // returns 396 63 64 v = mode( 50, 0.5 ); 65 // returns 49 66 ``` 67 68 If provided `NaN` as any argument, the function returns `NaN`. 69 70 ```javascript 71 var v = mode( NaN, 0.5 ); 72 // returns NaN 73 74 v = mode( 20, NaN ); 75 // returns NaN 76 ``` 77 78 If provided a `r` which is not a positive number, the function returns `NaN`. 79 80 ```javascript 81 var v = mode( -2.0, 0.5 ); 82 // returns NaN 83 ``` 84 85 If provided a success probability `p` outside of `[0,1]`, the function returns `NaN`. 86 87 ```javascript 88 var v = mode( 20, -1.0 ); 89 // returns NaN 90 91 v = mode( 20, 1.5 ); 92 // returns NaN 93 ``` 94 95 </section> 96 97 <!-- /.usage --> 98 99 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 100 101 <section class="notes"> 102 103 </section> 104 105 <!-- /.notes --> 106 107 <!-- Package usage examples. --> 108 109 <section class="examples"> 110 111 ## Examples 112 113 <!-- eslint no-undef: "error" --> 114 115 ```javascript 116 var randu = require( '@stdlib/random/base/randu' ); 117 var mode = require( '@stdlib/stats/base/dists/negative-binomial/mode' ); 118 119 var v; 120 var i; 121 var r; 122 var p; 123 124 for ( i = 0; i < 10; i++ ) { 125 r = randu() * 100; 126 p = randu(); 127 v = mode( r, p ); 128 console.log( 'r: %d, p: %d, mode(X;r,p): %d', r, p.toFixed( 4 ), v.toFixed( 4 ) ); 129 } 130 ``` 131 132 </section> 133 134 <!-- /.examples --> 135 136 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 137 138 <section class="references"> 139 140 </section> 141 142 <!-- /.references --> 143 144 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 145 146 <section class="links"> 147 148 [negative-binomial-distribution]: https://en.wikipedia.org/wiki/Negative_binomial_distribution 149 150 [mode]: https://en.wikipedia.org/wiki/Mode_%28statistics%29 151 152 </section> 153 154 <!-- /.links -->