From 0d0d1d0578b6f187f0554f19e957f62b0d966f1b Mon Sep 17 00:00:00 2001 From: Rejoan Sardar Date: Fri, 8 Mar 2024 17:20:10 +0530 Subject: [PATCH 1/4] feat: stats/base/dists/negative-binomial --- .../base/dists/negative-binomial/README.md | 37 ++++++++++++++++++- .../dists/negative-binomial/examples/index.js | 37 ++++++++++++++++++- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md index 25b2d04c7a72..13a5db64955b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md @@ -106,10 +106,43 @@ var y = dist.pmf( 4.0 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); var negativeBinomial = require( '@stdlib/stats/base/dists/negative-binomial' ); -console.log( objectKeys( negativeBinomial ) ); +/* +* Let's take an example of flipping a biased coin until getting 5 heads. +* This situation can be modeled using a Negative Binomial distribution with r = 5 and p = 1/2. +*/ + +var r = 5.0; +var p = 1/2; + +// Mean can be used to calculate the average number of trials needed to get 5 heads: +console.log(negativeBinomial.mean(r, p)); +// => 5 + +// PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial): +console.log(negativeBinomial.pmf(8, r, p)); +// => ~0.06042480468749999 + +// CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials): +console.log(negativeBinomial.cdf(8, r, p)); +// => ~0.8665771484375 + +// Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed: +console.log(negativeBinomial.quantile(0.8, r, p)); +// => 7 + +// Standard deviation can be used to calculate the measure of the spread of trials around the mean: +console.log(negativeBinomial.stdev(r, p)); +// => ~3.1622776601683795 + +// Skewness can be used to calculate the asymmetry of the distribution of trials: +console.log(negativeBinomial.skewness(r, p)); +// => ~0.9486832980505138 + +// MGF can be used for more advanced statistical analyses and generating moments of the distribution: +console.log(negativeBinomial.mgf(0.5, r, p)); +// => ~2277.5972997372114 ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js index b36b4b3f10de..7be4ea717eef 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js @@ -18,7 +18,40 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); var negativeBinomial = require( './../lib' ); -console.log( objectKeys( negativeBinomial ) ); +/* +* Let's take an example of flipping a biased coin until getting 5 heads. +* This situation can be modeled using a Negative Binomial distribution with r = 5 and p = 1/2. +*/ + +var r = 5.0; +var p = 1/2; + +// Mean can be used to calculate the average number of trials needed to get 5 heads: +console.log(negativeBinomial.mean(r, p)); +// => 5 + +// PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial): +console.log(negativeBinomial.pmf(8, r, p)); +// => ~0.06042480468749999 + +// CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials): +console.log(negativeBinomial.cdf(8, r, p)); +// => ~0.8665771484375 + +// Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed: +console.log(negativeBinomial.quantile(0.8, r, p)); +// => 7 + +// Standard deviation can be used to calculate the measure of the spread of trials around the mean: +console.log(negativeBinomial.stdev(r, p)); +// => ~3.1622776601683795 + +// Skewness can be used to calculate the asymmetry of the distribution of trials: +console.log(negativeBinomial.skewness(r, p)); +// => ~0.9486832980505138 + +// MGF can be used for more advanced statistical analyses and generating moments of the distribution: +console.log(negativeBinomial.mgf(0.5, r, p)); +// => ~2277.5972997372114 From 960dc07d8397e9e2ac986f5d7d6301fdba088d10 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 11 Mar 2024 21:16:24 -0400 Subject: [PATCH 2/4] Apply suggestions from code review Signed-off-by: Philipp Burckhardt --- .../stats/base/dists/negative-binomial/README.md | 10 +++++----- .../base/dists/negative-binomial/examples/index.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md index 13a5db64955b..24d34ff043db 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md @@ -122,11 +122,11 @@ console.log(negativeBinomial.mean(r, p)); // PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial): console.log(negativeBinomial.pmf(8, r, p)); -// => ~0.06042480468749999 +// => ~0.06 // CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials): console.log(negativeBinomial.cdf(8, r, p)); -// => ~0.8665771484375 +// => ~0.867 // Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed: console.log(negativeBinomial.quantile(0.8, r, p)); @@ -134,15 +134,15 @@ console.log(negativeBinomial.quantile(0.8, r, p)); // Standard deviation can be used to calculate the measure of the spread of trials around the mean: console.log(negativeBinomial.stdev(r, p)); -// => ~3.1622776601683795 +// => ~3.162 // Skewness can be used to calculate the asymmetry of the distribution of trials: console.log(negativeBinomial.skewness(r, p)); -// => ~0.9486832980505138 +// => ~0.949 // MGF can be used for more advanced statistical analyses and generating moments of the distribution: console.log(negativeBinomial.mgf(0.5, r, p)); -// => ~2277.5972997372114 +// => ~2277.598 ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js index 7be4ea717eef..b659cf8563ce 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js @@ -34,11 +34,11 @@ console.log(negativeBinomial.mean(r, p)); // PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial): console.log(negativeBinomial.pmf(8, r, p)); -// => ~0.06042480468749999 +// => ~0.06 // CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials): console.log(negativeBinomial.cdf(8, r, p)); -// => ~0.8665771484375 +// => ~0.867 // Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed: console.log(negativeBinomial.quantile(0.8, r, p)); @@ -46,12 +46,12 @@ console.log(negativeBinomial.quantile(0.8, r, p)); // Standard deviation can be used to calculate the measure of the spread of trials around the mean: console.log(negativeBinomial.stdev(r, p)); -// => ~3.1622776601683795 +// => ~3.162 // Skewness can be used to calculate the asymmetry of the distribution of trials: console.log(negativeBinomial.skewness(r, p)); -// => ~0.9486832980505138 +// => ~0.949 // MGF can be used for more advanced statistical analyses and generating moments of the distribution: console.log(negativeBinomial.mgf(0.5, r, p)); -// => ~2277.5972997372114 +// => ~2277.597 From 1ee58cd82201be063f7b4474b4a4771ae120789f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 11 Mar 2024 21:28:33 -0400 Subject: [PATCH 3/4] Apply suggestions from code review Signed-off-by: Philipp Burckhardt --- .../stats/base/dists/negative-binomial/README.md | 14 +++++++------- .../dists/negative-binomial/examples/index.js | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md index 24d34ff043db..b6146dcdff0a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md @@ -117,31 +117,31 @@ var r = 5.0; var p = 1/2; // Mean can be used to calculate the average number of trials needed to get 5 heads: -console.log(negativeBinomial.mean(r, p)); +console.log( negativeBinomial.mean( r, p ) ); // => 5 // PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial): -console.log(negativeBinomial.pmf(8, r, p)); +console.log( negativeBinomial.pmf( 8, r, p ) ); // => ~0.06 // CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials): -console.log(negativeBinomial.cdf(8, r, p)); +console.log( negativeBinomial.cdf( 8, r, p ) ); // => ~0.867 // Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed: -console.log(negativeBinomial.quantile(0.8, r, p)); +console.log( negativeBinomial.quantile( 0.8, r, p ) ); // => 7 // Standard deviation can be used to calculate the measure of the spread of trials around the mean: -console.log(negativeBinomial.stdev(r, p)); +console.log( negativeBinomial.stdev( r, p ) ); // => ~3.162 // Skewness can be used to calculate the asymmetry of the distribution of trials: -console.log(negativeBinomial.skewness(r, p)); +console.log( negativeBinomial.skewness( r, p ) ); // => ~0.949 // MGF can be used for more advanced statistical analyses and generating moments of the distribution: -console.log(negativeBinomial.mgf(0.5, r, p)); +console.log( negativeBinomial.mgf( 0.5, r, p ) ); // => ~2277.598 ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js index b659cf8563ce..a61159339dcf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js @@ -29,29 +29,29 @@ var r = 5.0; var p = 1/2; // Mean can be used to calculate the average number of trials needed to get 5 heads: -console.log(negativeBinomial.mean(r, p)); +console.log( negativeBinomial.mean( r, p ) ); // => 5 // PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial): -console.log(negativeBinomial.pmf(8, r, p)); +console.log( negativeBinomial.pmf( 8, r, p ) ); // => ~0.06 // CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials): -console.log(negativeBinomial.cdf(8, r, p)); +console.log( negativeBinomial.cdf( 8, r, p ) ); // => ~0.867 // Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed: -console.log(negativeBinomial.quantile(0.8, r, p)); +console.log( negativeBinomial.quantile( 0.8, r, p ) ); // => 7 // Standard deviation can be used to calculate the measure of the spread of trials around the mean: -console.log(negativeBinomial.stdev(r, p)); +console.log( negativeBinomial.stdev( r, p ) ); // => ~3.162 // Skewness can be used to calculate the asymmetry of the distribution of trials: -console.log(negativeBinomial.skewness(r, p)); +console.log( negativeBinomial.skewness( r, p ) ); // => ~0.949 // MGF can be used for more advanced statistical analyses and generating moments of the distribution: -console.log(negativeBinomial.mgf(0.5, r, p)); -// => ~2277.597 +console.log( negativeBinomial.mgf( 0.5, r, p ) ); +// => ~2277.598 From c31bdc103ae44a0b3229b30ce61e89ce6f677af9 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 11 Mar 2024 21:29:24 -0400 Subject: [PATCH 4/4] Apply suggestions from code review Signed-off-by: Philipp Burckhardt --- .../@stdlib/stats/base/dists/negative-binomial/README.md | 2 +- .../stats/base/dists/negative-binomial/examples/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md index b6146dcdff0a..cb6a3b486c3f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md @@ -142,7 +142,7 @@ console.log( negativeBinomial.skewness( r, p ) ); // MGF can be used for more advanced statistical analyses and generating moments of the distribution: console.log( negativeBinomial.mgf( 0.5, r, p ) ); -// => ~2277.598 +// => ~2277.597 ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js index a61159339dcf..15e63b0c6fd9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js @@ -54,4 +54,4 @@ console.log( negativeBinomial.skewness( r, p ) ); // MGF can be used for more advanced statistical analyses and generating moments of the distribution: console.log( negativeBinomial.mgf( 0.5, r, p ) ); -// => ~2277.598 +// => ~2277.597