Skip to content

stdlib-js/stats-base-dists-hypergeometric-ctor

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

Hypergeometric

NPM version Build Status Coverage Status

Hypergeometric distribution constructor.

Installation

npm install @stdlib/stats-base-dists-hypergeometric-ctor

Alternatively,

  • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
  • If you are using Deno, visit the deno branch (see README for usage intructions).
  • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (see README).

The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.

To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.

Usage

var Hypergeometric = require( '@stdlib/stats-base-dists-hypergeometric-ctor' );

Hypergeometric( N, K, n )

Returns a hypergeometric distribution object with parameters N (population size), K (subpopulation size), and n (number of draws).

var hypergeometric = new Hypergeometric( 20, 15, 5 );

var mu = hypergeometric.mean;
// returns 3.75

hypergeometric

A hypergeometric distribution object has the following properties and methods...

Writable Properties

hypergeometric.N

Population size of the distribution. N must be a nonnegative integer that is both larger than or equal to K and n.

var hypergeometric = new Hypergeometric( 100, 50, 20 );

var N = hypergeometric.N;
// returns 100.0

hypergeometric.N = 60;

N = hypergeometric.N;
// returns 60.0

hypergeometric.K

Subpopulation size of the distribution. K must be a nonnegative integer that is smaller than or equal to N.

var hypergeometric = new Hypergeometric( 100, 50, 20 );

var K = hypergeometric.K;
// returns 50.0

hypergeometric.K = 30;

K = hypergeometric.K;
// returns 30.0

hypergeometric.n

Number of draws of the distribution. n must be a nonnegative integer that is smaller than or equal to N.

var hypergeometric = new Hypergeometric( 100, 50, 20 );

var n = hypergeometric.n;
// returns 20.0

hypergeometric.n = 80;

n = hypergeometric.n;
// returns 80.0

Computed Properties

Hypergeometric.prototype.kurtosis

Returns the excess kurtosis.

var hypergeometric = new Hypergeometric( 20, 15, 5 );

var kurtosis = hypergeometric.kurtosis;
// returns ~-0.276

Hypergeometric.prototype.mean

Returns the expected value.

var hypergeometric = new Hypergeometric( 20, 15, 5 );

var mu = hypergeometric.mean;
// returns ~3.75

Hypergeometric.prototype.mode

Returns the mode.

var hypergeometric = new Hypergeometric( 20, 15, 5 );

var mode = hypergeometric.mode;
// returns 4.0

Hypergeometric.prototype.skewness

Returns the skewness.

var hypergeometric = new Hypergeometric( 20, 15, 5 );

var skewness = hypergeometric.skewness;
// returns ~-0.323

Hypergeometric.prototype.stdev

Returns the standard deviation.

var hypergeometric = new Hypergeometric( 20, 15, 5 );

var s = hypergeometric.stdev;
// returns ~0.86

Hypergeometric.prototype.variance

Returns the variance.

var hypergeometric = new Hypergeometric( 20, 15, 5 );

var s2 = hypergeometric.variance;
// returns ~0.74

Methods

Hypergeometric.prototype.cdf( x )

Evaluates the cumulative distribution function (CDF).

var hypergeometric = new Hypergeometric( 8, 2, 4 );

var y = hypergeometric.cdf( 0.5 );
// returns ~0.214

Hypergeometric.prototype.logpmf( x )

Evaluates the natural logarithm of the probability mass function (PMF).

var hypergeometric = new Hypergeometric( 8, 2, 4 );

var y = hypergeometric.logpmf( 2.0 );
// returns ~-1.54

Hypergeometric.prototype.pmf( x )

Evaluates the probability mass function (PMF).

var hypergeometric = new Hypergeometric( 8, 2, 4 );

var y = hypergeometric.pmf( 2.0 );
// returns ~0.214

Hypergeometric.prototype.quantile( p )

Evaluates the quantile function at probability p.

var hypergeometric = new Hypergeometric( 8, 2, 4 );

var y = hypergeometric.quantile( 0.8 );
// returns 2.0

y = hypergeometric.quantile( 1.9 );
// returns NaN

Examples

var Hypergeometric = require( '@stdlib/stats-base-dists-hypergeometric-ctor' );

var hypergeometric = new Hypergeometric( 100, 50, 20 );

var mu = hypergeometric.mean;
// returns 10.0

var mode = hypergeometric.mode;
// returns 10.0

var s2 = hypergeometric.variance;
// returns ~4.04

var y = hypergeometric.cdf( 10.5 );
// returns ~0.598

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


Copyright

Copyright © 2016-2024. The Stdlib Authors.