Skip to content

Commit 37f46fe

Browse files
docs: improve README examples of stats/base/dists/negative-binomial
PR-URL: #1774 Closes: #1637 --------- Signed-off-by: Philipp Burckhardt <[email protected]> Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent d8f6700 commit 37f46fe

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/README.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,43 @@ var y = dist.pmf( 4.0 );
106106
<!-- eslint no-undef: "error" -->
107107

108108
```javascript
109-
var objectKeys = require( '@stdlib/utils/keys' );
110109
var negativeBinomial = require( '@stdlib/stats/base/dists/negative-binomial' );
111110

112-
console.log( objectKeys( negativeBinomial ) );
111+
/*
112+
* Let's take an example of flipping a biased coin until getting 5 heads.
113+
* This situation can be modeled using a Negative Binomial distribution with r = 5 and p = 1/2.
114+
*/
115+
116+
var r = 5.0;
117+
var p = 1/2;
118+
119+
// Mean can be used to calculate the average number of trials needed to get 5 heads:
120+
console.log( negativeBinomial.mean( r, p ) );
121+
// => 5
122+
123+
// PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial):
124+
console.log( negativeBinomial.pmf( 8, r, p ) );
125+
// => ~0.06
126+
127+
// CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials):
128+
console.log( negativeBinomial.cdf( 8, r, p ) );
129+
// => ~0.867
130+
131+
// Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed:
132+
console.log( negativeBinomial.quantile( 0.8, r, p ) );
133+
// => 7
134+
135+
// Standard deviation can be used to calculate the measure of the spread of trials around the mean:
136+
console.log( negativeBinomial.stdev( r, p ) );
137+
// => ~3.162
138+
139+
// Skewness can be used to calculate the asymmetry of the distribution of trials:
140+
console.log( negativeBinomial.skewness( r, p ) );
141+
// => ~0.949
142+
143+
// MGF can be used for more advanced statistical analyses and generating moments of the distribution:
144+
console.log( negativeBinomial.mgf( 0.5, r, p ) );
145+
// => ~2277.597
113146
```
114147

115148
</section>

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/examples/index.js

+35-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,40 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
2221
var negativeBinomial = require( './../lib' );
2322

24-
console.log( objectKeys( negativeBinomial ) );
23+
/*
24+
* Let's take an example of flipping a biased coin until getting 5 heads.
25+
* This situation can be modeled using a Negative Binomial distribution with r = 5 and p = 1/2.
26+
*/
27+
28+
var r = 5.0;
29+
var p = 1/2;
30+
31+
// Mean can be used to calculate the average number of trials needed to get 5 heads:
32+
console.log( negativeBinomial.mean( r, p ) );
33+
// => 5
34+
35+
// PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial):
36+
console.log( negativeBinomial.pmf( 8, r, p ) );
37+
// => ~0.06
38+
39+
// CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials):
40+
console.log( negativeBinomial.cdf( 8, r, p ) );
41+
// => ~0.867
42+
43+
// Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed:
44+
console.log( negativeBinomial.quantile( 0.8, r, p ) );
45+
// => 7
46+
47+
// Standard deviation can be used to calculate the measure of the spread of trials around the mean:
48+
console.log( negativeBinomial.stdev( r, p ) );
49+
// => ~3.162
50+
51+
// Skewness can be used to calculate the asymmetry of the distribution of trials:
52+
console.log( negativeBinomial.skewness( r, p ) );
53+
// => ~0.949
54+
55+
// MGF can be used for more advanced statistical analyses and generating moments of the distribution:
56+
console.log( negativeBinomial.mgf( 0.5, r, p ) );
57+
// => ~2277.597

0 commit comments

Comments
 (0)