README.md (3589B)
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 > [Geometric][geometric-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 a [geometric][geometric-distribution] random variable is 30 31 <!-- <equation class="equation" label="eq:geometric_expectation" align="center" raw="\mathbb{E}\left[ X \right] = \frac{1-p}{p}" alt="Expected value for a geometric distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="\mathbb{E}\left[ X \right] = \frac{1-p}{p}" data-equation="eq:geometric_expectation"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/geometric/mean/docs/img/equation_geometric_expectation.svg" alt="Expected value for a geometric distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 where `p` is the success probability. 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/geometric/mean' ); 54 ``` 55 56 #### mean( p ) 57 58 Returns the [expected value][expected-value] of a [geometric][geometric-distribution] distribution with success probability `p`. 59 60 ```javascript 61 var v = mean( 0.1 ); 62 // returns 9.0 63 64 v = mean( 0.5 ); 65 // returns 1.0 66 ``` 67 68 If provided a success probability `p` outside of `[0,1]`, the function returns `NaN`. 69 70 ```javascript 71 var v = mean( NaN ); 72 // returns NaN 73 74 v = mean( 1.5 ); 75 // returns NaN 76 77 v = mean( -1.0 ); 78 // returns NaN 79 ``` 80 81 </section> 82 83 <!-- /.usage --> 84 85 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 86 87 <section class="notes"> 88 89 </section> 90 91 <!-- /.notes --> 92 93 <!-- Package usage examples. --> 94 95 <section class="examples"> 96 97 ## Examples 98 99 <!-- eslint no-undef: "error" --> 100 101 ```javascript 102 var randu = require( '@stdlib/random/base/randu' ); 103 var round = require( '@stdlib/math/base/special/round' ); 104 var mean = require( '@stdlib/stats/base/dists/geometric/mean' ); 105 106 var v; 107 var i; 108 var p; 109 110 for ( i = 0; i < 10; i++ ) { 111 p = randu(); 112 v = mean( p ); 113 console.log( 'p: %d, E(X;p): %d', p.toFixed( 4 ), v.toFixed( 4 ) ); 114 } 115 ``` 116 117 </section> 118 119 <!-- /.examples --> 120 121 <!-- 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. --> 122 123 <section class="references"> 124 125 </section> 126 127 <!-- /.references --> 128 129 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 130 131 <section class="links"> 132 133 [geometric-distribution]: https://en.wikipedia.org/wiki/Geometric_distribution 134 135 [expected-value]: https://en.wikipedia.org/wiki/Expected_value 136 137 </section> 138 139 <!-- /.links -->