README.md (4872B)
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 # Moment-Generating Function 22 23 > [Beta][beta-distribution] distribution moment-generating function (MGF). 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 The [moment-generating function][mgf] for a [beta][beta-distribution] random variable is 30 31 <!-- <equation class="equation" label="eq:beta_beta_mgf" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = 1 +\sum_{k=1}^{\infty} \left( \prod_{r=0}^{k-1} \frac{\alpha+r}{\alpha+\beta+r} \right) \frac{t^k}{k!}" alt="Moment-generating function (MGF) for a beta distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = 1 +\sum_{k=1}^{\infty} \left( \prod_{r=0}^{k-1} \frac{\alpha+r}{\alpha+\beta+r} \right) \frac{t^k}{k!}" data-equation="eq:beta_beta_mgf"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/beta/mgf/docs/img/equation_beta_beta_mgf.svg" alt="Moment-generating function (MGF) for a beta distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 where `alpha > 0` is the first shape parameter and `beta > 0` is the second shape parameter. 41 42 </section> 43 44 <!-- /.intro --> 45 46 <!-- Package usage documentation. --> 47 48 <section class="usage"> 49 50 ## Usage 51 52 ```javascript 53 var mgf = require( '@stdlib/stats/base/dists/beta/mgf' ); 54 ``` 55 56 #### mgf( t, alpha, beta ) 57 58 Evaluates the [moment-generating function][mgf] (MGF) for a [beta][beta-distribution] distribution with parameters `alpha` (first shape parameter) and `beta` (second shape parameter). 59 60 ```javascript 61 var y = mgf( 0.5, 1.0, 1.0 ); 62 // returns ~1.297 63 64 y = mgf( 0.5, 2.0, 4.0 ); 65 // returns ~1.186 66 67 y = mgf( 3.0, 2.0, 2.0 ); 68 // returns ~5.575 69 70 y = mgf( -0.8, 4.0, 4.0 ); 71 // returns ~0.676 72 ``` 73 74 If provided `NaN` as any argument, the function returns `NaN`. 75 76 ```javascript 77 var y = mgf( NaN, 1.0, 1.0 ); 78 // returns NaN 79 80 y = mgf( 0.0, NaN, 1.0 ); 81 // returns NaN 82 83 y = mgf( 0.0, 1.0, NaN ); 84 // returns NaN 85 ``` 86 87 If provided `alpha <= 0`, the function returns `NaN`. 88 89 ```javascript 90 var y = mgf( 2.0, -1.0, 0.5 ); 91 // returns NaN 92 93 y = mgf( 2.0, 0.0, 0.5 ); 94 // returns NaN 95 ``` 96 97 If provided `beta <= 0`, the function returns `NaN`. 98 99 ```javascript 100 var y = mgf( 2.0, 0.5, -1.0 ); 101 // returns NaN 102 103 y = mgf( 2.0, 0.5, 0.0 ); 104 // returns NaN 105 ``` 106 107 #### mgf.factory( alpha, beta ) 108 109 Returns a function for evaluating the [moment-generating function][mgf] for a [beta][beta-distribution] distribution with parameters `alpha` (first shape parameter) and `beta` (second shape parameter). 110 111 ```javascript 112 var mymgf = mgf.factory( 0.5, 0.5 ); 113 114 var y = mymgf( 0.8 ); 115 // returns ~1.552 116 117 y = mymgf( 0.3 ); 118 // returns ~1.168 119 ``` 120 121 </section> 122 123 <!-- /.usage --> 124 125 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 126 127 <section class="notes"> 128 129 </section> 130 131 <!-- /.notes --> 132 133 <!-- Package usage examples. --> 134 135 <section class="examples"> 136 137 ## Examples 138 139 <!-- eslint no-undef: "error" --> 140 141 ```javascript 142 var randu = require( '@stdlib/random/base/randu' ); 143 var EPS = require( '@stdlib/constants/float64/eps' ); 144 var mgf = require( '@stdlib/stats/base/dists/beta/mgf' ); 145 146 var alpha; 147 var beta; 148 var t; 149 var v; 150 var i; 151 152 for ( i = 0; i < 10; i++ ) { 153 t = randu() * 20.0; 154 alpha = ( randu()*5.0 ) + EPS; 155 beta = ( randu()*5.0 ) + EPS; 156 v = mgf( t, alpha, beta ); 157 console.log( 't: %d, α: %d, β: %d, M_X(t;α,β): %d', t.toFixed( 4 ), alpha.toFixed( 4 ), beta.toFixed( 4 ), v.toFixed( 4 ) ); 158 } 159 ``` 160 161 </section> 162 163 <!-- /.examples --> 164 165 <!-- 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. --> 166 167 <section class="references"> 168 169 </section> 170 171 <!-- /.references --> 172 173 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 174 175 <section class="links"> 176 177 [beta-distribution]: https://en.wikipedia.org/wiki/Beta_distribution 178 179 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function 180 181 </section> 182 183 <!-- /.links -->