README.md (3523B)
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 # Cumulative Distribution Function 22 23 > [Geometric][geometric-distribution] distribution [cumulative distribution function][cdf]. 24 25 <section class="intro"> 26 27 The [cumulative distribution function][cdf] for a [geometric][geometric-distribution] random variable is 28 29 <!-- <equation class="equation" label="eq:geometric_cdf" align="center" raw="F(x;p)= \begin{cases} 0 & \text{ for } x < 0 \\ 1-(1 - p)^{\left\lfloor x \right\rfloor+1} & \text{ otherwise} \end{cases}" alt="Cumulative distribution function for a geometric distribution."> --> 30 31 <div class="equation" align="center" data-raw-text="F(x;p)= \begin{cases} 0 & \text{ for } x < 0 \\ 1-(1 - p)^{\left\lfloor x \right\rfloor+1} & \text{ otherwise} \end{cases}" data-equation="eq:geometric_cdf"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/geometric/cdf/docs/img/equation_geometric_cdf.svg" alt="Cumulative distribution function for a geometric distribution."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `0 <= p <= 1` is the success probability. `x` denotes the number of _failures_ before the first success. 39 40 </section> 41 42 <!-- /.intro --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var cdf = require( '@stdlib/stats/base/dists/geometric/cdf' ); 50 ``` 51 52 #### cdf( x, p ) 53 54 Evaluates the [cumulative distribution function][cdf] for a [geometric][geometric-distribution] distribution with success probability `p`. 55 56 ```javascript 57 var y = cdf( 2.0, 0.5 ); 58 // returns 0.875 59 60 y = cdf( 2.0, 0.1 ); 61 // returns ~0.271 62 ``` 63 64 If provided `NaN` as any argument, the function returns `NaN`. 65 66 ```javascript 67 var y = cdf( NaN, 0.5 ); 68 // returns NaN 69 70 y = cdf( 0.0, NaN ); 71 // returns NaN 72 ``` 73 74 If provided a success probability `p` outside of `[0,1]`, the function returns `NaN`. 75 76 ```javascript 77 var y = cdf( 2.0, -1.0 ); 78 // returns NaN 79 80 y = cdf( 2.0, 1.5 ); 81 // returns NaN 82 ``` 83 84 #### cdf.factory( p ) 85 86 Returns a function for evaluating the [cumulative distribution function][cdf] of a [geometric][geometric-distribution] distribution with success probability `p` 87 88 ```javascript 89 var mycdf = cdf.factory( 0.5 ); 90 var y = mycdf( 3.0 ); 91 // returns 0.9375 92 93 y = mycdf( 1.0 ); 94 // returns 0.75 95 ``` 96 97 </section> 98 99 <!-- /.usage --> 100 101 <section class="examples"> 102 103 ## Examples 104 105 <!-- eslint no-undef: "error" --> 106 107 ```javascript 108 var randu = require( '@stdlib/random/base/randu' ); 109 var cdf = require( '@stdlib/stats/base/dists/geometric/cdf' ); 110 111 var p; 112 var x; 113 var y; 114 var i; 115 116 for ( i = 0; i < 10; i++ ) { 117 x = randu() * 5.0; 118 p = randu(); 119 y = cdf( x, p ); 120 console.log( 'x: %d, p: %d, F(x;p): %d', x.toFixed( 4 ), p.toFixed( 4 ), y.toFixed( 4 ) ); 121 } 122 ``` 123 124 </section> 125 126 <!-- /.examples --> 127 128 <section class="links"> 129 130 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function 131 132 [geometric-distribution]: https://en.wikipedia.org/wiki/Geometric_distribution 133 134 </section> 135 136 <!-- /.links -->