README.md (6454B)
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 # Gamma 22 23 > Gamma distribution constructor. 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 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var Gamma = require( '@stdlib/stats/base/dists/gamma/ctor' ); 41 ``` 42 43 #### Gamma( \[alpha, beta] ) 44 45 Returns a [gamma][gamma-distribution] distribution object. 46 47 ```javascript 48 var gamma = new Gamma(); 49 50 var mode = gamma.mode; 51 // returns 0.0 52 ``` 53 54 By default, `alpha = 1.0` and `beta = 1.0`. To create a distribution having a different `alpha` (shape parameter) and `beta` (rate parameter), provide the corresponding arguments. 55 56 ```javascript 57 var gamma = new Gamma( 2.0, 4.0 ); 58 59 var mu = gamma.mean; 60 // returns 0.5 61 ``` 62 63 * * * 64 65 ## gamma 66 67 A [gamma][gamma-distribution] distribution object has the following properties and methods... 68 69 ### Writable Properties 70 71 #### gamma.alpha 72 73 Shape parameter of the distribution. `alpha` **must** be a positive number. 74 75 ```javascript 76 var gamma = new Gamma(); 77 78 var alpha = gamma.alpha; 79 // returns 1.0 80 81 gamma.alpha = 3.0; 82 83 alpha = gamma.alpha; 84 // returns 3.0 85 ``` 86 87 #### gamma.beta 88 89 Rate parameter of the distribution. `beta` **must** be a positive number. 90 91 ```javascript 92 var gamma = new Gamma( 2.0, 4.0 ); 93 94 var b = gamma.beta; 95 // returns 4.0 96 97 gamma.beta = 3.0; 98 99 b = gamma.beta; 100 // returns 3.0 101 ``` 102 103 * * * 104 105 ### Computed Properties 106 107 #### Gamma.prototype.entropy 108 109 Returns the [differential entropy][entropy]. 110 111 ```javascript 112 var gamma = new Gamma( 4.0, 12.0 ); 113 114 var entropy = gamma.entropy; 115 // returns ~-0.462 116 ``` 117 118 #### Gamma.prototype.kurtosis 119 120 Returns the [excess kurtosis][kurtosis]. 121 122 ```javascript 123 var gamma = new Gamma( 4.0, 12.0 ); 124 125 var kurtosis = gamma.kurtosis; 126 // returns 1.5 127 ``` 128 129 #### Gamma.prototype.mean 130 131 Returns the [expected value][expected-value]. 132 133 ```javascript 134 var gamma = new Gamma( 4.0, 12.0 ); 135 136 var mu = gamma.mean; 137 // returns ~0.333 138 ``` 139 140 #### Gamma.prototype.mode 141 142 Returns the [mode][mode]. 143 144 ```javascript 145 var gamma = new Gamma( 4.0, 12.0 ); 146 147 var mode = gamma.mode; 148 // returns 0.25 149 ``` 150 151 #### Gamma.prototype.skewness 152 153 Returns the [skewness][skewness]. 154 155 ```javascript 156 var gamma = new Gamma( 4.0, 12.0 ); 157 158 var skewness = gamma.skewness; 159 // returns 1.0 160 ``` 161 162 #### Gamma.prototype.stdev 163 164 Returns the [standard deviation][standard-deviation]. 165 166 ```javascript 167 var gamma = new Gamma( 4.0, 12.0 ); 168 169 var s = gamma.stdev; 170 // returns ~0.167 171 ``` 172 173 #### Gamma.prototype.variance 174 175 Returns the [variance][variance]. 176 177 ```javascript 178 var gamma = new Gamma( 4.0, 12.0 ); 179 180 var s2 = gamma.variance; 181 // returns ~0.028 182 ``` 183 184 * * * 185 186 ### Methods 187 188 #### Gamma.prototype.cdf( x ) 189 190 Evaluates the [cumulative distribution function][cdf] (CDF). 191 192 ```javascript 193 var gamma = new Gamma( 2.0, 4.0 ); 194 195 var y = gamma.cdf( 0.5 ); 196 // returns ~0.594 197 ``` 198 199 #### Gamma.prototype.logcdf( x ) 200 201 Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF). 202 203 ```javascript 204 var gamma = new Gamma( 2.0, 4.0 ); 205 206 var y = gamma.logcdf( 0.5 ); 207 // returns ~-0.521 208 ``` 209 210 #### Gamma.prototype.logpdf( x ) 211 212 Evaluates the natural logarithm of the [probability density function][pdf] (PDF). 213 214 ```javascript 215 var gamma = new Gamma( 2.0, 4.0 ); 216 217 var y = gamma.logpdf( 0.8 ); 218 // returns ~-0.651 219 ``` 220 221 #### Gamma.prototype.mgf( t ) 222 223 Evaluates the [moment-generating function][mgf] (MGF). 224 225 ```javascript 226 var gamma = new Gamma( 2.0, 4.0 ); 227 228 var y = gamma.mgf( 0.5 ); 229 // returns ~1.306 230 ``` 231 232 #### Gamma.prototype.pdf( x ) 233 234 Evaluates the [probability density function][pdf] (PDF). 235 236 ```javascript 237 var gamma = new Gamma( 2.0, 4.0 ); 238 239 var y = gamma.pdf( 0.8 ); 240 // returns ~0.522 241 ``` 242 243 #### Gamma.prototype.quantile( p ) 244 245 Evaluates the [quantile function][quantile-function] at probability `p`. 246 247 ```javascript 248 var gamma = new Gamma( 2.0, 4.0 ); 249 250 var y = gamma.quantile( 0.5 ); 251 // returns ~0.42 252 253 y = gamma.quantile( 1.9 ); 254 // returns NaN 255 ``` 256 257 </section> 258 259 <!-- /.usage --> 260 261 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 262 263 <section class="notes"> 264 265 </section> 266 267 <!-- /.notes --> 268 269 <!-- Package usage examples. --> 270 271 * * * 272 273 <section class="examples"> 274 275 ## Examples 276 277 <!-- eslint no-undef: "error" --> 278 279 ```javascript 280 var Gamma = require( '@stdlib/stats/base/dists/gamma/ctor' ); 281 282 var gamma = new Gamma( 2.0, 4.0 ); 283 284 var mu = gamma.mean; 285 // returns 0.5 286 287 var mode = gamma.mode; 288 // returns 0.25 289 290 var s2 = gamma.variance; 291 // returns 0.125 292 293 var y = gamma.cdf( 0.8 ); 294 // returns ~0.829 295 ``` 296 297 </section> 298 299 <!-- /.examples --> 300 301 <!-- 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. --> 302 303 <section class="references"> 304 305 </section> 306 307 <!-- /.references --> 308 309 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 310 311 <section class="links"> 312 313 [gamma-distribution]: https://en.wikipedia.org/wiki/Gamma_distribution 314 315 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function 316 317 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function 318 319 [pdf]: https://en.wikipedia.org/wiki/Probability_density_function 320 321 [quantile-function]: https://en.wikipedia.org/wiki/Quantile_function 322 323 [entropy]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29 324 325 [expected-value]: https://en.wikipedia.org/wiki/Expected_value 326 327 [kurtosis]: https://en.wikipedia.org/wiki/Kurtosis 328 329 [mode]: https://en.wikipedia.org/wiki/Mode_%28statistics%29 330 331 [skewness]: https://en.wikipedia.org/wiki/Skewness 332 333 [standard-deviation]: https://en.wikipedia.org/wiki/Standard_deviation 334 335 [variance]: https://en.wikipedia.org/wiki/Variance 336 337 </section> 338 339 <!-- /.links -->