From 4d62a8ccb224f643d160116de9087b23c416ea52 Mon Sep 17 00:00:00 2001 From: Deepak CH Date: Sat, 27 Jul 2024 01:36:36 +0530 Subject: [PATCH 1/2] docs: Enhance README with detailed usage examples for hypergeometric distribution --- .../stats/base/dists/hypergeometric/README.md | 74 ++++++++++++++++++ .../dists/hypergeometric/examples/index.js | 75 ++++++++++++++++++- 2 files changed, 148 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md index 9fae818416e6..3e4da6a5efe3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md @@ -108,7 +108,81 @@ var y = dist.cdf( 0.5 ); var objectKeys = require( '@stdlib/utils/keys' ); var hypergeometric = require( '@stdlib/stats/base/dists/hypergeometric' ); +// Print namespace contents +console.log( 'Namespace contents:' ); console.log( objectKeys( hypergeometric ) ); + +// Example 1: Basic distribution properties +var N1 = 50; // population size +var K1 = 20; // number of successes in population +var n1 = 10; // number of draws + +console.log( '\nExample 1: Basic distribution properties' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N1, K1, n1 ); +console.log( 'Mean: %d', hypergeometric.mean( N1, K1, n1 ) ); +console.log( 'Variance: %d', hypergeometric.variance( N1, K1, n1 ) ); +console.log( 'Skewness: %d', hypergeometric.skewness( N1, K1, n1 ) ); +console.log( 'Excess Kurtosis: %d', hypergeometric.kurtosis( N1, K1, n1 ) ); +console.log( 'Standard Deviation: %d', hypergeometric.stdev( N1, K1, n1 ) ); + +// Example 2: PMF and CDF calculations +var N2 = 100; +var K2 = 40; +var n2 = 25; + +console.log( '\nExample 2: PMF and CDF calculations' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N2, K2, n2 ); +for ( var x = 0; x <= 10; x += 2 ) { + console.log( 'P(X = %d): %d', x, hypergeometric.pmf( x, N2, K2, n2 ) ); + console.log( 'P(X <= %d): %d', x, hypergeometric.cdf( x, N2, K2, n2 ) ); +} + +// Example 3: Quantile function +var N3 = 80; +var K3 = 30; +var n3 = 20; + +console.log( '\nExample 3: Quantile function' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N3, K3, n3 ); +var probabilities = [ 0.1, 0.25, 0.5, 0.75, 0.9 ]; +for ( var i = 0; i < probabilities.length; i++ ) { + var p = probabilities[i]; + console.log( 'Q(%d): %d', p, hypergeometric.quantile( p, N3, K3, n3 ) ); +} + +// Example 4: Random number generation +var N4 = 60; +var K4 = 25; +var n4 = 15; + +console.log( '\nExample 4: Random number generation' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N4, K4, n4 ); +var Hypergeometric = hypergeometric.Hypergeometric; +var dist = new Hypergeometric( N4, K4, n4 ); +for ( var j = 0; j < 10; j++ ) { + console.log( 'Random variate %d: %d', j+1, dist.random() ); +} + +// Example 5: Log PMF calculations +var N5 = 200; +var K5 = 80; +var n5 = 50; + +console.log( '\nExample 5: Log PMF calculations' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N5, K5, n5 ); +for ( var y = 10; y <= 30; y += 5 ) { + console.log( 'log(P(X = %d)): %d', y, hypergeometric.logpmf( y, N5, K5, n5 ) ); +} + +// Example 6: Mode calculation +var N6 = 75; +var K6 = 35; +var n6 = 20; + +console.log( '\nExample 6: Mode calculation' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N6, K6, n6 ); +console.log( 'Mode: %d', hypergeometric.mode( N6, K6, n6 ) ); + ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js index 28b4cc1b4651..2c257800df8c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js @@ -19,6 +19,79 @@ 'use strict'; var objectKeys = require( '@stdlib/utils/keys' ); -var hypergeometric = require( './../lib' ); +var hypergeometric = require( '@stdlib/stats/base/dists/hypergeometric' ); +// Print namespace contents +console.log( 'Namespace contents:' ); console.log( objectKeys( hypergeometric ) ); + +// Example 1: Basic distribution properties +var N1 = 50; // population size +var K1 = 20; // number of successes in population +var n1 = 10; // number of draws + +console.log( '\nExample 1: Basic distribution properties' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N1, K1, n1 ); +console.log( 'Mean: %d', hypergeometric.mean( N1, K1, n1 ) ); +console.log( 'Variance: %d', hypergeometric.variance( N1, K1, n1 ) ); +console.log( 'Skewness: %d', hypergeometric.skewness( N1, K1, n1 ) ); +console.log( 'Excess Kurtosis: %d', hypergeometric.kurtosis( N1, K1, n1 ) ); +console.log( 'Standard Deviation: %d', hypergeometric.stdev( N1, K1, n1 ) ); + +// Example 2: PMF and CDF calculations +var N2 = 100; +var K2 = 40; +var n2 = 25; + +console.log( '\nExample 2: PMF and CDF calculations' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N2, K2, n2 ); +for ( var x = 0; x <= 10; x += 2 ) { + console.log( 'P(X = %d): %d', x, hypergeometric.pmf( x, N2, K2, n2 ) ); + console.log( 'P(X <= %d): %d', x, hypergeometric.cdf( x, N2, K2, n2 ) ); +} + +// Example 3: Quantile function +var N3 = 80; +var K3 = 30; +var n3 = 20; + +console.log( '\nExample 3: Quantile function' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N3, K3, n3 ); +var probabilities = [ 0.1, 0.25, 0.5, 0.75, 0.9 ]; +for ( var i = 0; i < probabilities.length; i++ ) { + var p = probabilities[i]; + console.log( 'Q(%d): %d', p, hypergeometric.quantile( p, N3, K3, n3 ) ); +} + +// Example 4: Random number generation +var N4 = 60; +var K4 = 25; +var n4 = 15; + +console.log( '\nExample 4: Random number generation' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N4, K4, n4 ); +var Hypergeometric = hypergeometric.Hypergeometric; +var dist = new Hypergeometric( N4, K4, n4 ); +for ( var j = 0; j < 10; j++ ) { + console.log( 'Random variate %d: %d', j+1, dist.random() ); +} + +// Example 5: Log PMF calculations +var N5 = 200; +var K5 = 80; +var n5 = 50; + +console.log( '\nExample 5: Log PMF calculations' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N5, K5, n5 ); +for ( var y = 10; y <= 30; y += 5 ) { + console.log( 'log(P(X = %d)): %d', y, hypergeometric.logpmf( y, N5, K5, n5 ) ); +} + +// Example 6: Mode calculation +var N6 = 75; +var K6 = 35; +var n6 = 20; + +console.log( '\nExample 6: Mode calculation' ); +console.log( 'Parameters: N=%d, K=%d, n=%d', N6, K6, n6 ); +console.log( 'Mode: %d', hypergeometric.mode( N6, K6, n6 ) ); From d1802ae50ed0294b8a8162b60476021c9f2f4aa5 Mon Sep 17 00:00:00 2001 From: Deepak CH Date: Sat, 27 Jul 2024 02:13:52 +0530 Subject: [PATCH 2/2] updated readme --- .../stats/base/dists/hypergeometric/README.md | 3 +-- .../base/dists/hypergeometric/examples/index.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md index 3e4da6a5efe3..439336194281 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/README.md @@ -108,8 +108,7 @@ var y = dist.cdf( 0.5 ); var objectKeys = require( '@stdlib/utils/keys' ); var hypergeometric = require( '@stdlib/stats/base/dists/hypergeometric' ); -// Print namespace contents -console.log( 'Namespace contents:' ); + console.log( objectKeys( hypergeometric ) ); // Example 1: Basic distribution properties diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js index 2c257800df8c..1afd754f14a0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/examples/index.js @@ -19,7 +19,7 @@ 'use strict'; var objectKeys = require( '@stdlib/utils/keys' ); -var hypergeometric = require( '@stdlib/stats/base/dists/hypergeometric' ); +var hypergeometric = require( './../lib' ); // Print namespace contents console.log( 'Namespace contents:' ); @@ -46,8 +46,8 @@ var n2 = 25; console.log( '\nExample 2: PMF and CDF calculations' ); console.log( 'Parameters: N=%d, K=%d, n=%d', N2, K2, n2 ); for ( var x = 0; x <= 10; x += 2 ) { - console.log( 'P(X = %d): %d', x, hypergeometric.pmf( x, N2, K2, n2 ) ); - console.log( 'P(X <= %d): %d', x, hypergeometric.cdf( x, N2, K2, n2 ) ); + console.log( 'P(X = %d): %d', x, hypergeometric.pmf( x, N2, K2, n2 ) ); + console.log( 'P(X <= %d): %d', x, hypergeometric.cdf( x, N2, K2, n2 ) ); } // Example 3: Quantile function @@ -59,8 +59,8 @@ console.log( '\nExample 3: Quantile function' ); console.log( 'Parameters: N=%d, K=%d, n=%d', N3, K3, n3 ); var probabilities = [ 0.1, 0.25, 0.5, 0.75, 0.9 ]; for ( var i = 0; i < probabilities.length; i++ ) { - var p = probabilities[i]; - console.log( 'Q(%d): %d', p, hypergeometric.quantile( p, N3, K3, n3 ) ); + var p = probabilities[i]; + console.log( 'Q(%d): %d', p, hypergeometric.quantile( p, N3, K3, n3 ) ); } // Example 4: Random number generation @@ -73,7 +73,7 @@ console.log( 'Parameters: N=%d, K=%d, n=%d', N4, K4, n4 ); var Hypergeometric = hypergeometric.Hypergeometric; var dist = new Hypergeometric( N4, K4, n4 ); for ( var j = 0; j < 10; j++ ) { - console.log( 'Random variate %d: %d', j+1, dist.random() ); + console.log( 'Random variate %d: %d', j+1, dist.random() ); } // Example 5: Log PMF calculations @@ -84,7 +84,7 @@ var n5 = 50; console.log( '\nExample 5: Log PMF calculations' ); console.log( 'Parameters: N=%d, K=%d, n=%d', N5, K5, n5 ); for ( var y = 10; y <= 30; y += 5 ) { - console.log( 'log(P(X = %d)): %d', y, hypergeometric.logpmf( y, N5, K5, n5 ) ); + console.log( 'log(P(X = %d)): %d', y, hypergeometric.logpmf( y, N5, K5, n5 ) ); } // Example 6: Mode calculation @@ -94,4 +94,4 @@ var n6 = 20; console.log( '\nExample 6: Mode calculation' ); console.log( 'Parameters: N=%d, K=%d, n=%d', N6, K6, n6 ); -console.log( 'Mode: %d', hypergeometric.mode( N6, K6, n6 ) ); +console.log( 'Mode: %d', hypergeometric.mode( N6, K6, n6 ) ); \ No newline at end of file