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