README.md (3995B)
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 > [Inverse Gamma][inverse-gamma] distribution [cumulative distribution function][cdf]. 24 25 <section class="intro"> 26 27 The [cumulative distribution function][cdf] for an [inverse gamma][inverse-gamma] random variable is 28 29 <!-- <equation class="equation" label="eq:invgamma_cdf" align="center" raw="F(x; \alpha, \beta) = \frac{\Gamma\left(\alpha,\frac{\beta}{x}\right)}{\Gamma(\alpha)} = Q\left(\frac{\beta}{x},\alpha\right)" alt="Cumulative distribution function for a Inverse Gamma distribution."> --> 30 31 <div class="equation" align="center" data-raw-text="F(x; \alpha, \beta) = \frac{\Gamma\left(\alpha,\frac{\beta}{x}\right)}{\Gamma(\alpha)} = Q\left(\frac{\beta}{x},\alpha\right)" data-equation="eq:invgamma_cdf"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/invgamma/cdf/docs/img/equation_invgamma_cdf.svg" alt="Cumulative distribution function for a Inverse Gamma distribution."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `alpha > 0` is the shape parameter and `beta > 0` is the scale parameter. `Q` is the upper regularized incomplete gamma function. 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/invgamma/cdf' ); 50 ``` 51 52 #### cdf( x, alpha, beta ) 53 54 Evaluates the [cumulative distribution function][cdf] (CDF) for an [inverse gamma][inverse-gamma] distribution with parameters `alpha` (shape parameter) and `beta` (rate parameter). 55 56 ```javascript 57 var y = cdf( 2.0, 1.0, 1.0 ); 58 // returns ~0.607 59 60 y = cdf( 2.0, 3.0, 1.0 ); 61 // returns ~0.986 62 63 y = cdf( -1.0, 2.0, 2.0 ); 64 // returns 0.0 65 66 y = cdf( -Infinity, 4.0, 2.0 ); 67 // returns 0.0 68 69 y = cdf( +Infinity, 4.0, 2.0 ); 70 // returns 1.0 71 ``` 72 73 If provided `NaN` as any argument, the function returns `NaN`. 74 75 ```javascript 76 var y = cdf( NaN, 1.0, 1.0 ); 77 // returns NaN 78 79 y = cdf( 0.0, NaN, 1.0 ); 80 // returns NaN 81 82 y = cdf( 0.0, 1.0, NaN ); 83 // returns NaN 84 ``` 85 86 If provided `alpha <= 0`, the function returns `NaN`. 87 88 ```javascript 89 var y = cdf( 2.0, -1.0, 0.5 ); 90 // returns NaN 91 ``` 92 93 If provided `beta <= 0`, the function returns `NaN`. 94 95 ```javascript 96 var y = cdf( 2.0, 0.5, -1.0 ); 97 // returns NaN 98 ``` 99 100 #### cdf.factory( alpha, beta ) 101 102 Returns a function for evaluating the [cumulative distribution function][cdf] for an [inverse gamma][inverse-gamma] distribution with parameters `alpha` (shape parameter) and `beta` (rate parameter). 103 104 ```javascript 105 var mycdf = cdf.factory( 0.5, 0.1 ); 106 107 var y = mycdf( 12.0 ); 108 // returns ~0.897 109 110 y = mycdf( 8.0 ); 111 // returns ~0.874 112 ``` 113 114 </section> 115 116 <!-- /.usage --> 117 118 <section class="examples"> 119 120 ## Examples 121 122 <!-- eslint no-undef: "error" --> 123 124 ```javascript 125 var randu = require( '@stdlib/random/base/randu' ); 126 var cdf = require( '@stdlib/stats/base/dists/invgamma/cdf' ); 127 128 var alpha; 129 var beta; 130 var x; 131 var y; 132 var i; 133 134 for ( i = 0; i < 10; i++ ) { 135 x = randu() * 2.0; 136 alpha = randu() * 5.0; 137 beta = randu() * 5.0; 138 y = cdf( x, alpha, beta ); 139 console.log( 'x: %d, α: %d, β: %d, F(x;α,β): %d', x.toFixed( 4 ), alpha.toFixed( 4 ), beta.toFixed( 4 ), y.toFixed( 4 ) ); 140 } 141 ``` 142 143 </section> 144 145 <!-- /.examples --> 146 147 <section class="links"> 148 149 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function 150 151 [inverse-gamma]: https://en.wikipedia.org/wiki/Inverse-gamma_distribution 152 153 </section> 154 155 <!-- /.links -->