README.md (3837B)
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 > [Bernoulli][bernoulli-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 [Bernoulli][bernoulli-distribution] random variable is 30 31 <!-- <equation class="equation" label="eq:bernoulli_mode" align="center" raw="\operatorname{Mode}\left( X \right) = \begin{cases} 0 & \text{if } p < 1/2 \\ 0, 1 &\text{if } p = 1/2 \\ 1 & \text{if } p > 1/2 \end{cases}" alt="Mode for a Bernoulli distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="\operatorname{Mode}\left( X \right) = \begin{cases} 0 & \text{if } p < 1/2 \\ 0, 1 &\text{if } p = 1/2 \\ 1 & \text{if } p > 1/2 \end{cases}" data-equation="eq:bernoulli_mode"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@e1fbdee688c5409e4cc6b0cd06d90b1cd2abd67c/lib/node_modules/@stdlib/stats/base/dists/bernoulli/mode/docs/img/equation_bernoulli_mode.svg" alt="Mode for a Bernoulli distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 where `p` is the success probability. 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/bernoulli/mode' ); 54 ``` 55 56 #### mode( p ) 57 58 Returns the [mode][mode] of a [Bernoulli][bernoulli-distribution] distribution with success probability `p`. 59 60 ```javascript 61 var v = mode( 0.1 ); 62 // returns 0 63 64 v = mode( 0.5 ); 65 // returns 0 66 67 v = mode( 0.8 ); 68 // returns 1 69 ``` 70 71 If provided a success probability `p` outside of `[0,1]`, the function returns `NaN`. 72 73 ```javascript 74 var v = mode( NaN ); 75 // returns NaN 76 77 v = mode( 1.5 ); 78 // returns NaN 79 80 v = mode( -1.0 ); 81 // returns NaN 82 ``` 83 84 </section> 85 86 <!-- /.usage --> 87 88 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 89 90 <section class="notes"> 91 92 ## Notes 93 94 - For `p = 0.5`, the mode is either `0` or `1`. This implementation returns `0` for `p = 0.5`. 95 96 </section> 97 98 <!-- /.notes --> 99 100 <!-- Package usage examples. --> 101 102 <section class="examples"> 103 104 ## Examples 105 106 <!-- eslint no-undef: "error" --> 107 108 ```javascript 109 var randu = require( '@stdlib/random/base/randu' ); 110 var round = require( '@stdlib/math/base/special/round' ); 111 var mode = require( '@stdlib/stats/base/dists/bernoulli/mode' ); 112 113 var v; 114 var i; 115 var p; 116 117 for ( i = 0; i < 10; i++ ) { 118 p = randu(); 119 v = mode( p ); 120 console.log( 'p: %d, Mode(X;p): %d', p.toFixed( 4 ), v.toFixed( 4 ) ); 121 } 122 ``` 123 124 </section> 125 126 <!-- /.examples --> 127 128 <!-- 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. --> 129 130 <section class="references"> 131 132 </section> 133 134 <!-- /.references --> 135 136 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 137 138 <section class="links"> 139 140 [bernoulli-distribution]: https://en.wikipedia.org/wiki/Bernoulli_distribution 141 142 [mode]: https://en.wikipedia.org/wiki/Mode_%28statistics%29 143 144 </section> 145 146 <!-- /.links -->