time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (4198B)


      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 # Variance
     22 
     23 > [Lognormal][lognormal-distribution] distribution [variance][variance].
     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 [variance][variance] for a [lognormal][lognormal-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:lognormal_variance" align="center" raw="\operatorname{Var}\left( X \right) = [\exp({\sigma^{2}})-1] \cdot \exp({2\mu +\sigma^{2}})" alt="Variance for a lognormal distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="\operatorname{Var}\left( X \right) = [\exp({\sigma^{2}})-1] \cdot \exp({2\mu +\sigma^{2}})" data-equation="eq:lognormal_variance">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/lognormal/variance/docs/img/equation_lognormal_variance.svg" alt="Variance for a lognormal distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `μ` is the location parameter and `σ > 0` is the scale parameter. According to the definition, the _natural logarithm_ of a random variable from a
     41 [lognormal distribution][lognormal-distribution] follows a [normal distribution][normal-distribution].
     42 
     43 </section>
     44 
     45 <!-- /.intro -->
     46 
     47 <!-- Package usage documentation. -->
     48 
     49 <section class="usage">
     50 
     51 ## Usage
     52 
     53 ```javascript
     54 var variance = require( '@stdlib/stats/base/dists/lognormal/variance' );
     55 ```
     56 
     57 #### variance( mu, sigma )
     58 
     59 Returns the [variance][variance] for a [lognormal][lognormal-distribution] distribution with location `mu` and scale `sigma`.
     60 
     61 ```javascript
     62 var y = variance( 2.0, 1.0 );
     63 // returns ~255.016
     64 
     65 y = variance( 0.0, 1.0 );
     66 // returns ~4.671
     67 
     68 y = variance( -1.0, 2.0 );
     69 // returns ~396.04
     70 ```
     71 
     72 If provided `NaN` as any argument, the function returns `NaN`.
     73 
     74 ```javascript
     75 var y = variance( NaN, 1.0 );
     76 // returns NaN
     77 
     78 y = variance( 0.0, NaN );
     79 // returns NaN
     80 ```
     81 
     82 If provided `sigma <= 0`, the function returns `NaN`.
     83 
     84 ```javascript
     85 var y = variance( 0.0, 0.0 );
     86 // returns NaN
     87 
     88 y = variance( 0.0, -1.0 );
     89 // returns NaN
     90 ```
     91 
     92 </section>
     93 
     94 <!-- /.usage -->
     95 
     96 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     97 
     98 <section class="notes">
     99 
    100 </section>
    101 
    102 <!-- /.notes -->
    103 
    104 <!-- Package usage examples. -->
    105 
    106 <section class="examples">
    107 
    108 ## Examples
    109 
    110 <!-- eslint no-undef: "error" -->
    111 
    112 ```javascript
    113 var randu = require( '@stdlib/random/base/randu' );
    114 var variance = require( '@stdlib/stats/base/dists/lognormal/variance' );
    115 
    116 var sigma;
    117 var mu;
    118 var y;
    119 var i;
    120 
    121 for ( i = 0; i < 10; i++ ) {
    122     mu = ( randu()*10.0 ) - 5.0;
    123     sigma = randu() * 20.0;
    124     y = variance( mu, sigma );
    125     console.log( 'µ: %d, σ: %d, Var(X;µ,σ): %d', mu.toFixed( 4 ), sigma.toFixed( 4 ), y.toFixed( 4 ) );
    126 }
    127 ```
    128 
    129 </section>
    130 
    131 <!-- /.examples -->
    132 
    133 <!-- 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. -->
    134 
    135 <section class="references">
    136 
    137 </section>
    138 
    139 <!-- /.references -->
    140 
    141 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    142 
    143 <section class="links">
    144 
    145 [lognormal-distribution]: https://en.wikipedia.org/wiki/Log-normal_distribution
    146 
    147 [normal-distribution]: https://en.wikipedia.org/wiki/Normal_distribution
    148 
    149 [variance]: https://en.wikipedia.org/wiki/Variance
    150 
    151 </section>
    152 
    153 <!-- /.links -->