Skip to content

Commit

Permalink
docs: improve examples of stats/base/dists/kumaraswamy
Browse files Browse the repository at this point in the history
PR-URL: #2605
Closes: #1632

Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
ruthwikchikoti and Planeshifter authored Nov 11, 2024
1 parent f0ecdad commit 4e1c68b
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 6 deletions.
68 changes: 64 additions & 4 deletions lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,75 @@ var y = dist.logpdf( 0.8 );

## Examples

<!-- TODO: better examples -->

<!-- eslint no-undef: "error" -->

```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var kumaraswamy = require( '@stdlib/stats/base/dists/kumaraswamy' );

console.log( objectKeys( kumaraswamy ) );
// Create a Kumaraswamy distribution object:
var a = 2.0;
var b = 5.0;
var dist = new kumaraswamy.Kumaraswamy( a, b );

// Calculate basic distribution properties:
console.log( 'Mean: %d', dist.mean );
console.log( 'Median: %d', dist.median );
console.log( 'Mode: %d', dist.mode );
console.log( 'Variance: %d', dist.variance );

// Evaluate the probability density function (PDF):
var x = 0.5;
var y = dist.pdf( x );
console.log( 'PDF at x = %d: %d', x, y );

// Evaluate the cumulative distribution function (CDF):
y = dist.cdf( x );
console.log( 'CDF at x = %d: %d', x, y );

// Evaluate the natural logarithm of PDF and CDF:
console.log( 'Log PDF at x = %d: %d', x, dist.logpdf( x ) );
console.log( 'Log CDF at x = %d: %d', x, dist.logcdf( x ) );

// Calculate the quantile for a given probability:
var p = 0.75;
x = dist.quantile( p );
console.log( 'Quantile at p = %d: %d', p, x );

// Use standalone distribution functions:
x = 0.3;
y = kumaraswamy.pdf( x, a, b );
console.log( 'Standalone PDF at x = %d: %d', x, y );

y = kumaraswamy.cdf( x, a, b );
console.log( 'Standalone CDF at x = %d: %d', x, y );

y = kumaraswamy.quantile( 0.9, a, b );
console.log( 'Standalone Quantile at p = 0.9: %d', y );

// Calculate additional distribution properties:
console.log( 'Kurtosis: %d', kumaraswamy.kurtosis( a, b ) );
console.log( 'Skewness: %d', kumaraswamy.skewness( a, b ) );
console.log( 'Standard Deviation: %d', kumaraswamy.stdev( a, b ) );

// Demonstrate the effect of different shape parameters:
console.log( '\nEffect of shape parameters:' );
var shapes = [
[ 0.5, 0.5 ],
[ 5.0, 1.0 ],
[ 1.0, 5.0 ],
[ 2.0, 2.0 ],
[ 10.0, 10.0 ]
];
var params;
var i;
for ( i = 0; i < shapes.length; i++ ) {
params = shapes[i];
console.log( '\na = %d, b = %d', params[0], params[1] );
console.log( 'Mean: %d', kumaraswamy.mean( params[0], params[1] ) );
console.log( 'Median: %d', kumaraswamy.median( params[0], params[1] ) );
console.log( 'Mode: %d', kumaraswamy.mode( params[0], params[1] ) );
console.log( 'Skewness: %d', kumaraswamy.skewness( params[0], params[1] ) );
}
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,69 @@

'use strict';

var objectKeys = require( '@stdlib/utils/keys' );
var kumaraswamy = require( './../lib' );

console.log( objectKeys( kumaraswamy ) );
// Create a Kumaraswamy distribution object:
var a = 2.0;
var b = 5.0;
var dist = new kumaraswamy.Kumaraswamy( a, b );

// Calculate basic distribution properties:
console.log( 'Mean: %d', dist.mean );
console.log( 'Median: %d', dist.median );
console.log( 'Mode: %d', dist.mode );
console.log( 'Variance: %d', dist.variance );

// Evaluate the probability density function (PDF):
var x = 0.5;
var y = dist.pdf( x );
console.log( 'PDF at x = %d: %d', x, y );

// Evaluate the cumulative distribution function (CDF):
y = dist.cdf( x );
console.log( 'CDF at x = %d: %d', x, y );

// Evaluate the natural logarithm of PDF and CDF:
console.log( 'Log PDF at x = %d: %d', x, dist.logpdf( x ) );
console.log( 'Log CDF at x = %d: %d', x, dist.logcdf( x ) );

// Calculate the quantile for a given probability:
var p = 0.75;
x = dist.quantile( p );
console.log( 'Quantile at p = %d: %d', p, x );

// Use standalone distribution functions:
x = 0.3;
y = kumaraswamy.pdf( x, a, b );
console.log( 'Standalone PDF at x = %d: %d', x, y );

y = kumaraswamy.cdf( x, a, b );
console.log( 'Standalone CDF at x = %d: %d', x, y );

y = kumaraswamy.quantile( 0.9, a, b );
console.log( 'Standalone Quantile at p = 0.9: %d', y );

// Calculate additional distribution properties:
console.log( 'Kurtosis: %d', kumaraswamy.kurtosis( a, b ) );
console.log( 'Skewness: %d', kumaraswamy.skewness( a, b ) );
console.log( 'Standard Deviation: %d', kumaraswamy.stdev( a, b ) );

// Demonstrate the effect of different shape parameters:
console.log( '\nEffect of shape parameters:' );
var shapes = [
[ 0.5, 0.5 ],
[ 5.0, 1.0 ],
[ 1.0, 5.0 ],
[ 2.0, 2.0 ],
[ 10.0, 10.0 ]
];
var params;
var i;
for ( i = 0; i < shapes.length; i++ ) {
params = shapes[ i ];
console.log( '\na = %d, b = %d', params[0], params[1] );
console.log( 'Mean: %d', kumaraswamy.mean( params[0], params[1] ) );
console.log( 'Median: %d', kumaraswamy.median( params[0], params[1] ) );
console.log( 'Mode: %d', kumaraswamy.mode( params[0], params[1] ) );
console.log( 'Skewness: %d', kumaraswamy.skewness( params[0], params[1] ) );
}

1 comment on commit 4e1c68b

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/kumaraswamy $\color{green}159/159$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}0/0$
$\color{green}+100.00\%$
$\color{green}159/159$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.