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 README examples of stats/base/dists/negative-binomial #1774

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,43 @@ var y = dist.pmf( 4.0 );
<!-- eslint no-undef: "error" -->

```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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// Skewness can be used to calculate the asymmetry of the distribution of trials:
console.log(negativeBinomial.skewness(r, p));
// => ~0.9486832980505138
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// Skewness can be used to calculate the asymmetry of the distribution of trials:
console.log(negativeBinomial.skewness(r, p));
// => ~0.9486832980505138
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved
Loading