time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (4622B)


      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 > [Hypergeometric][hypergeometric-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 Imagine a scenario with a population of size `N`, of which a subpopulation of size `K` can be considered successes. We draw `n` observations from the total population. Defining the random variable `X` as the number of successes in the `n` draws, `X` is said to follow a [hypergeometric distribution][hypergeometric-distribution]. The [mode][mode] for a [hypergeometric][hypergeometric-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:hypergeometric_mode" align="center" raw="\operatorname{mode}\left( X \right) = \left\lfloor {\frac{(n+1)(K+1)}{N+2}}\right\rfloor" alt="Mode for a hypergeometric distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="\operatorname{mode}\left( X \right) = \left\lfloor {\frac{(n+1)(K+1)}{N+2}}\right\rfloor" data-equation="eq:hypergeometric_mode">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/mode/docs/img/equation_hypergeometric_mode.svg" alt="Mode for a hypergeometric distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 </section>
     41 
     42 <!-- /.intro -->
     43 
     44 <!-- Package usage documentation. -->
     45 
     46 <section class="usage">
     47 
     48 ## Usage
     49 
     50 ```javascript
     51 var mode = require( '@stdlib/stats/base/dists/hypergeometric/mode' );
     52 ```
     53 
     54 #### mode( N, K, n )
     55 
     56 Returns the [mode][mode] of a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws).
     57 
     58 ```javascript
     59 var v = mode( 16, 11, 4 );
     60 // returns 3
     61 
     62 v = mode( 2, 1, 1 );
     63 // returns 1
     64 ```
     65 
     66 If provided `NaN` as any argument, the function returns `NaN`.
     67 
     68 ```javascript
     69 var v = mode( NaN, 10, 4 );
     70 // returns NaN
     71 
     72 v = mode( 20, NaN, 4 );
     73 // returns NaN
     74 
     75 v = mode( 20, 10, NaN );
     76 // returns NaN
     77 ```
     78 
     79 If provided a population size `N`, subpopulation size `K`, or draws `n` which is not a nonnegative integer, the function returns `NaN`.
     80 
     81 ```javascript
     82 var v = mode( 10.5, 5, 2 );
     83 // returns NaN
     84 
     85 v = mode( 10, 1.5, 2 );
     86 // returns NaN
     87 
     88 v = mode( 10, 5, -2.0 );
     89 // returns NaN
     90 ```
     91 
     92 If the number of draws `n` or the subpopulation size `K` exceed population size `N`, the function returns `NaN`.
     93 
     94 ```javascript
     95 var v = mode( 10, 5, 12 );
     96 // returns NaN
     97 
     98 v = mode( 10, 12, 5 );
     99 // returns NaN
    100 ```
    101 
    102 </section>
    103 
    104 <!-- /.usage -->
    105 
    106 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    107 
    108 <section class="notes">
    109 
    110 </section>
    111 
    112 <!-- /.notes -->
    113 
    114 <!-- Package usage examples. -->
    115 
    116 <section class="examples">
    117 
    118 ## Examples
    119 
    120 <!-- eslint no-undef: "error" -->
    121 
    122 ```javascript
    123 var randu = require( '@stdlib/random/base/randu' );
    124 var round = require( '@stdlib/math/base/special/round' );
    125 var mode = require( '@stdlib/stats/base/dists/hypergeometric/mode' );
    126 
    127 var v;
    128 var i;
    129 var N;
    130 var K;
    131 var n;
    132 
    133 for ( i = 0; i < 10; i++ ) {
    134     N = round( randu() * 20 );
    135     K = round( randu() * N );
    136     n = round( randu() * K );
    137     v = mode( N, K, n );
    138     console.log( 'N: %d, K: %d, n: %d, mode(X;N,K,n): %d', N, K, n, v.toFixed( 4 ) );
    139 }
    140 ```
    141 
    142 </section>
    143 
    144 <!-- /.examples -->
    145 
    146 <!-- 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. -->
    147 
    148 <section class="references">
    149 
    150 </section>
    151 
    152 <!-- /.references -->
    153 
    154 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    155 
    156 <section class="links">
    157 
    158 [hypergeometric-distribution]: https://en.wikipedia.org/wiki/Hypergeometric_distribution
    159 
    160 [mode]: https://en.wikipedia.org/wiki/Mode_%28statistics%29
    161 
    162 </section>
    163 
    164 <!-- /.links -->