README.md (4096B)
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 # Mean 22 23 > [Inverse gamma][invgamma-distribution] distribution [expected value][expected-value]. 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 [expected value][expected-value] for an [inverse-gamma][invgamma-distribution] random variable is 30 31 <!-- <equation class="equation" label="eq:invgamma_expectation" align="center" raw="\mathbb{E}\left[ X \right] = \frac{\beta}{\alpha-1}" alt="Expected value for an inverse-gamma distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="\mathbb{E}\left[ X \right] = \frac{\beta}{\alpha-1}" data-equation="eq:invgamma_expectation"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/invgamma/mean/docs/img/equation_invgamma_expectation.svg" alt="Expected value for an inverse-gamma distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 where `α > 0` is the shape parameter and `β > 0` is the rate 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 mean = require( '@stdlib/stats/base/dists/invgamma/mean' ); 54 ``` 55 56 #### mean( alpha, beta ) 57 58 Returns the [expected value][expected-value] of an [inverse gamma][invgamma-distribution] distribution with parameters `alpha` (shape parameter) and `beta` (rate parameter). 59 60 ```javascript 61 var v = mean( 4.0, 12.0 ); 62 // returns 4.0 63 64 v = mean( 8.0, 2.0 ); 65 // returns ~0.286 66 ``` 67 68 If provided `NaN` as any argument, the function returns `NaN`. 69 70 ```javascript 71 var v = mean( NaN, 2.0 ); 72 // returns NaN 73 74 v = mean( 2.0, NaN ); 75 // returns NaN 76 ``` 77 78 If provided `alpha <= 1`, the function returns `NaN`. 79 80 ```javascript 81 var v = mean( 0.5, 1.0 ); 82 // returns NaN 83 84 v = mean( -1.0, 1.0 ); 85 // returns NaN 86 ``` 87 88 If provided `beta <= 0`, the function returns `NaN`. 89 90 ```javascript 91 var v = mean( 1.0, 0.0 ); 92 // returns NaN 93 94 v = mean( 1.0, -1.0 ); 95 // returns NaN 96 ``` 97 98 </section> 99 100 <!-- /.usage --> 101 102 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 103 104 <section class="notes"> 105 106 </section> 107 108 <!-- /.notes --> 109 110 <!-- Package usage examples. --> 111 112 <section class="examples"> 113 114 ## Examples 115 116 <!-- eslint no-undef: "error" --> 117 118 ```javascript 119 var randu = require( '@stdlib/random/base/randu' ); 120 var EPS = require( '@stdlib/constants/float64/eps' ); 121 var mean = require( '@stdlib/stats/base/dists/invgamma/mean' ); 122 123 var alpha; 124 var beta; 125 var v; 126 var i; 127 128 for ( i = 0; i < 10; i++ ) { 129 alpha = ( randu()*10.0 ) + EPS; 130 beta = ( randu()*10.0 ) + EPS; 131 v = mean( alpha, beta ); 132 console.log( 'α: %d, β: %d, E(X;α,β): %d', alpha.toFixed( 4 ), beta.toFixed( 4 ), v.toFixed( 4 ) ); 133 } 134 ``` 135 136 </section> 137 138 <!-- /.examples --> 139 140 <!-- 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. --> 141 142 <section class="references"> 143 144 </section> 145 146 <!-- /.references --> 147 148 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 149 150 <section class="links"> 151 152 [invgamma-distribution]: https://en.wikipedia.org/wiki/Inverse-gamma_distribution 153 154 [expected-value]: https://en.wikipedia.org/wiki/Expected_value 155 156 </section> 157 158 <!-- /.links -->