Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve stats/base/dists/lognormal README Examples #2003

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 94 additions & 7 deletions lib/node_modules/@stdlib/stats/base/dists/lognormal/README.md
Original file line number Diff line number Diff line change
@@ -36,7 +36,22 @@ Lognormal distribution.

```javascript
var dist = lognormal;
// returns {...}
// returns {
// cdf: [Function: cdf],
// LogNormal: [Function: LogNormal],
// entropy: [Function: entropy],
// kurtosis: [Function: kurtosis],
// logcdf: [Function: logcdf],
// logpdf: [Function: logpdf],
// mean: [Function: mean],
// median: [Function: median],
// mode: [Function: mode],
// pdf: [Function: pdf],
// quantile: [Function: quantile],
// skewness: [Function: skewness],
// stdev: [Function: stdev],
// variance: [Function: variance]
// }
```

The namespace contains the following distribution functions:
@@ -87,19 +102,14 @@ The namespace contains a constructor function for creating a [lognormal][lognorm
<!-- </toc> -->

```javascript
var LogNormal = require( '@stdlib/stats/base/dists/lognormal' ).LogNormal;

var dist = new LogNormal( 2.0, 4.0 );

var y = dist.cdf( 0.5 );
// returns ~0.25
```

</section>

<!-- /.usage -->

<section class="examples">
`<section class="examples">

## Examples

@@ -110,8 +120,83 @@ var y = dist.cdf( 0.5 );
```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var lognormal = require( '@stdlib/stats/base/dists/lognormal' );
var LogNormal = require( '@stdlib/stats/base/dists/lognormal' ).LogNormal;
var Cdf = require('@stdlib/stats/base/dists/lognormal').cdf
var Pdf = require('@stdlib/stats/base/dists/lognormal').pdf
var Mean = require('@stdlib/stats/base/dists/lognormal').mean
var Median = require('@stdlib/stats/base/dists/lognormal').median
var Mode = require('@stdlib/stats/base/dists/lognormal').mode
var Entropy = require('@stdlib/stats/base/dists/lognormal').entropy
var Kurtosis = require('@stdlib/stats/base/dists/lognormal').kurtosis
var LogCdf = require('@stdlib/stats/base/dists/lognormal').logcdf
var LogPdf = require('@stdlib/stats/base/dists/lognormal').logpdf
var Quantile = require('@stdlib/stats/base/dists/lognormal').quantile
var Skewness = require('@stdlib/stats/base/dists/lognormal').skewness
var Stdev = require('@stdlib/stats/base/dists/lognormal').stdev
var Variance = require('@stdlib/stats/base/dists/lognormal').variance

console.log( objectKeys( lognormal ) );



// Create a Lognormal distribution with parameters mu = 2.0 and sigma = 4.0
var lognormal = lognormal(2.0, 4.0);
// returns ~0.25

// Calculate the cumulative distribution function (CDF) at x = 0.5
var cdf = Cdf(0.5, 2.0, 4.0);
// returns ~0.25039

// Calculate the probability density function (PDF) at x = 0.5
var pdf = Pdf(0.5, 2.0, 4.0);
// returns ~0.16

// Calculate the mean of the distribution
var mean = Mean(2.0, 4.0);
// returns ~22026.46

// Calculate the median of the distribution
var median = Median(2.0, 4.0);
// returns ~7.39

// Calculate the mode of the distribution
var mode = Mode(2.0, 4.0);
// returns ~8.316e-7

// Calculate the entropy of the distribution
var entropy = Entropy(2.0, 4.0);
// returns ~4.9

// Calculate the excess kurtosis of the distribution
var kurtosis = Kurtosis(2.0, 4.0);
// returns ~6.236+27

// Calculate the natural logarithm of the cumulative distribution function (CDF) at x = 0.5
var logcdf = LogCdf(0.5, 2.0, 4.0);
// returns ~-1.39

// Calculate the natural logarithm of the probability density function (PDF) at x = 0.5
var logpdf = LogPdf(0.5, 2.0, 4.0);
// returns ~-1.9

// Calculate the quantile function at p = 0.5
var quantile = Quantile(0.5, 2.0, 4.0);
// returns ~-7.39

// Calculate the skewness of the distribution
var skewness = Skewness(2.0, 4.0);
// returns ~26489126601.3

// Calculate the standard deviation of the distribution
var stdev = Stdev(2.0, 4.0);
// returns ~65659965.443

// Calculate the variance of the distribution
var variance = Variance(2.0, 4.0);
// returns ~4311231061950000.0



```

</section>
@@ -166,4 +251,6 @@ console.log( objectKeys( lognormal ) );

</section>



<!-- /.links -->
70 changes: 70 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dists/lognormal/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var LogNormal = require( '@stdlib/stats/base/dists/lognormal' ).LogNormal;
var Cdf = require('@stdlib/stats/base/dists/lognormal').cdf
var Pdf = require('@stdlib/stats/base/dists/lognormal').pdf
var Mean = require('@stdlib/stats/base/dists/lognormal').mean
var Median = require('@stdlib/stats/base/dists/lognormal').median
var Mode = require('@stdlib/stats/base/dists/lognormal').mode
var Entropy = require('@stdlib/stats/base/dists/lognormal').entropy
var Kurtosis = require('@stdlib/stats/base/dists/lognormal').kurtosis
var LogCdf = require('@stdlib/stats/base/dists/lognormal').logcdf
var LogPdf = require('@stdlib/stats/base/dists/lognormal').logpdf
var Quantile = require('@stdlib/stats/base/dists/lognormal').quantile
var Skewness = require('@stdlib/stats/base/dists/lognormal').skewness
var Stdev = require('@stdlib/stats/base/dists/lognormal').stdev
var Variance = require('@stdlib/stats/base/dists/lognormal').variance


// Create a Lognormal distribution with parameters mu = 2.0 and sigma = 4.0
var dist = new LogNormal(2.0, 4.0);

// Calculate the cumulative distribution function (CDF) at x = 0.5
var cdfValue = Cdf(0.5, 2.0, 4.0);
console.log('CDF at x = 0.5:', cdfValue);

// Calculate the probability density function (PDF) at x = 0.5
var pdfValue = Pdf(0.5, 2.0, 4.0);
console.log('PDF at x = 0.5:', pdfValue);

// Calculate the mean of the distribution
var meanValue = Mean(2.0, 4.0);
console.log('Mean:', meanValue);

// Calculate the median of the distribution
var medianValue = Median(2.0, 4.0);
console.log('Median:', medianValue);

// Calculate the mode of the distribution
var modeValue = Mode(2.0, 4.0);
console.log('Mode:', modeValue);

// Calculate the entropy of the distribution
var entropyValue = Entropy(2.0, 4.0);
console.log('Entropy:', entropyValue);

// Calculate the excess kurtosis of the distribution
var kurtosisValue = Kurtosis(2.0, 4.0);
console.log('Excess Kurtosis:', kurtosisValue);

// Calculate the natural logarithm of the cumulative distribution function (CDF) at x = 0.5
var logcdfValue = LogCdf(0.5, 2.0, 4.0);
console.log('LogCDF at x = 0.5:', logcdfValue);

// Calculate the natural logarithm of the probability density function (PDF) at x = 0.5
var logpdfValue = LogPdf(0.5, 2.0, 4.0);
console.log('LogPDF at x = 0.5:', logpdfValue);

// Calculate the quantile function at p = 0.5
var quantileValue = Quantile(0.5, 2.0, 4.0);
console.log('Quantile at p = 0.5:', quantileValue);

// Calculate the skewness of the distribution
var skewnessValue = Skewness(2.0, 4.0);
console.log('Skewness:', skewnessValue);

// Calculate the standard deviation of the distribution
var stdevValue = Stdev(2.0, 4.0);
console.log('Standard Deviation:', stdevValue);

// Calculate the variance of the distribution
var varianceValue = Variance(2.0, 4.0);
console.log('Variance:', varianceValue);
Loading
Oops, something went wrong.