README.md (3923B)
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 # Logarithm of Cumulative Distribution Function 22 23 > [Geometric][geometric-distribution] distribution logarithm of [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/logcdf/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 logcdf = require( '@stdlib/stats/base/dists/geometric/logcdf' ); 50 ``` 51 52 #### logcdf( x, p ) 53 54 Evaluates the logarithm of the [cumulative distribution function][cdf] for a [geometric][geometric-distribution] distribution with success probability `p`. 55 56 ```javascript 57 var y = logcdf( 2.0, 0.5 ); 58 // returns ~-0.134 59 60 y = logcdf( 2.0, 0.1 ); 61 // returns ~-1.306 62 ``` 63 64 If provided `NaN` as any argument, the function returns `NaN`. 65 66 ```javascript 67 var y = logcdf( NaN, 0.5 ); 68 // returns NaN 69 70 y = logcdf( 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 = logcdf( 2.0, -1.0 ); 78 // returns NaN 79 80 y = logcdf( 2.0, 1.5 ); 81 // returns NaN 82 ``` 83 84 #### logcdf.factory( p ) 85 86 Returns a function for evaluating the logarithm of the [cumulative distribution function][cdf] of a [geometric][geometric-distribution] distribution with success probability `p` 87 88 ```javascript 89 var mylogcdf = logcdf.factory( 0.5 ); 90 var y = mylogcdf( 3.0 ); 91 // returns ~-0.065 92 93 y = mylogcdf( 1.0 ); 94 // returns ~-0.288 95 ``` 96 97 </section> 98 99 <!-- /.usage --> 100 101 <section class="notes"> 102 103 ## Notes 104 105 - In virtually all cases, using the `logpmf` or `logcdf` functions is preferable to manually computing the logarithm of the `pmf` or `cdf`, respectively, since the latter is prone to overflow and underflow. 106 107 </section> 108 109 <!-- /.notes --> 110 111 <section class="examples"> 112 113 ## Examples 114 115 <!-- eslint no-undef: "error" --> 116 117 ```javascript 118 var randu = require( '@stdlib/random/base/randu' ); 119 var logcdf = require( '@stdlib/stats/base/dists/geometric/logcdf' ); 120 121 var p; 122 var x; 123 var y; 124 var i; 125 126 for ( i = 0; i < 10; i++ ) { 127 x = randu() * 5.0; 128 p = randu(); 129 y = logcdf( x, p ); 130 console.log( 'x: %d, p: %d, ln(F(x;p)): %d', x.toFixed( 4 ), p.toFixed( 4 ), y.toFixed( 4 ) ); 131 } 132 ``` 133 134 </section> 135 136 <!-- /.examples --> 137 138 <section class="links"> 139 140 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function 141 142 [geometric-distribution]: https://en.wikipedia.org/wiki/Geometric_distribution 143 144 </section> 145 146 <!-- /.links -->