Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
230 changes: 230 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dists/wald/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Wald

> Wald distribution.

<section class="usage">

## Usage

```javascript
var wald = require( '@stdlib/stats/base/dists/wald' );
```

#### wald

[Wald][wald-distribution] (inverse Gaussian) distribution.

```javascript
var dist = wald;
// returns {...}
```

The namespace contains the following distribution functions:

<!-- <toc pattern="*+(cdf|pdf|mgf|quantile)*"> -->

<div class="namespace-toc">

- <span class="signature">[`cdf( x, mu, lambda )`][@stdlib/stats/base/dists/wald/cdf]</span><span class="delimiter">: </span><span class="description">Wald distribution cumulative distribution function.</span>
- <span class="signature">[`logcdf( x, mu, lambda )`][@stdlib/stats/base/dists/wald/logcdf]</span><span class="delimiter">: </span><span class="description">evaluate the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution.</span>
- <span class="signature">[`logpdf( x, mu, lambda )`][@stdlib/stats/base/dists/wald/logpdf]</span><span class="delimiter">: </span><span class="description">evaluate the natural logarithm of the probability density function (PDF) for a Wald distribution.</span>
- <span class="signature">[`mgf( t, mu, lambda )`][@stdlib/stats/base/dists/wald/mgf]</span><span class="delimiter">: </span><span class="description">Wald distribution moment-generating function (MGF).</span>
- <span class="signature">[`pdf( x, mu, lambda )`][@stdlib/stats/base/dists/wald/pdf]</span><span class="delimiter">: </span><span class="description">Wald distribution probability density function (PDF).</span>
- <span class="signature">[`quantile( p, mu, lambda )`][@stdlib/stats/base/dists/wald/quantile]</span><span class="delimiter">: </span><span class="description">Wald distribution quantile function.</span>

</div>

<!-- </toc> -->

The namespace contains the following functions for calculating distribution properties:

<!-- <toc pattern="*+(kurtosis|mean|mode|skewness|stdev|variance)*"> -->

<div class="namespace-toc">

- <span class="signature">[`kurtosis( mu, lambda )`][@stdlib/stats/base/dists/wald/kurtosis]</span><span class="delimiter">: </span><span class="description">Wald distribution excess kurtosis.</span>
- <span class="signature">[`mean( mu, lambda )`][@stdlib/stats/base/dists/wald/mean]</span><span class="delimiter">: </span><span class="description">Wald distribution expected value.</span>
- <span class="signature">[`mode( mu, lambda )`][@stdlib/stats/base/dists/wald/mode]</span><span class="delimiter">: </span><span class="description">Wald distribution mode.</span>
- <span class="signature">[`skewness( mu, lambda )`][@stdlib/stats/base/dists/wald/skewness]</span><span class="delimiter">: </span><span class="description">Wald distribution skewness.</span>
- <span class="signature">[`stdev( mu, lambda )`][@stdlib/stats/base/dists/wald/stdev]</span><span class="delimiter">: </span><span class="description">Wald distribution standard deviation.</span>
- <span class="signature">[`variance( mu, lambda )`][@stdlib/stats/base/dists/wald/variance]</span><span class="delimiter">: </span><span class="description">Wald distribution variance.</span>

</div>

<!-- </toc> -->

```javascript
var wald = require( '@stdlib/stats/base/dists/wald' );

var y = wald.pdf( 2.0, 2.0, 4.0 );
// returns ~0.282
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var wald = require( '@stdlib/stats/base/dists/wald' );

/*
A support team is modeling how long it takes agents to resolve tickets. The Wald (inverse Gaussian) distribution is a natural fit for "time until completion" data, as it models the first time a drift-diffusion process crosses a fixed threshold.

Assuming the team has collected the following data:

- Mean resolution time (μ/mu): 20 minutes.
- Shape parameter (λ/lambda): 50.0 (controls the spread/skew of resolution times).

We can model resolution times using a Wald distribution with μ (mu) = 20.0 minutes and λ (lambda) = 50.0.
*/

var mu = 20.0;
var lambda = 50.0;

// Output the shape parameter of the resolution times:
console.log( lambda );
// => 50.0

// Adjust distribution parameters to reflect a team handling more variable tickets:
lambda = 60.0;

// Adjusted shape parameter:
console.log( lambda );
// => 60.0

// Excess kurtosis of a Wald distribution (measure of "tailedness"):
console.log( wald.kurtosis( mu, lambda ) );
// => 5.0

// Variance of the resolution times after adjusting lambda:
console.log( wald.variance( mu, lambda ) );
// => ~133.333

// Probability density function at 20 minutes:
console.log( wald.pdf( 20.0, mu, 60.0 ) );
// => ~0.0345

// Cumulative distribution function at 20 minutes (portion of tickets resolved within 20 minutes):
console.log( wald.cdf( 20.0, mu, 60.0 ) );
// => ~0.607

// 50th percentile (median-like) resolution time:
console.log( wald.quantile( 0.5, mu, 60.0 ) );
// => ~17.193

// Moment-generating function value at 0.01 (used in probability theory):
console.log( wald.mgf( 0.01, mu, 60.0 ) );
// => ~1.23

// Mean resolution time:
console.log( wald.mean( mu, 60.0 ) );
// => 20.0

// Mode of the resolution times (most frequent value):
console.log( wald.mode( mu, 60.0 ) );
// => ~12.361

// Variance of the resolution times:
console.log( wald.variance( mu, 60.0 ) );
// => ~133.333

// Skewness of the distribution (symmetry measure):
console.log( wald.skewness( mu, 60.0 ) );
// => ~1.732

var myquantile = wald.quantile.factory( mu, 60.0 );

// 20th percentile (value below which 20% of resolution times fall):
console.log( myquantile( 0.2 ) );
// => ~10.875

// 80th percentile (value below which 80% of resolution times fall):
console.log( myquantile( 0.8 ) );
// => ~27.434

var mylogpdf = wald.logpdf.factory( mu, 60.0 );

// Logarithm of the probability density function at 20 minutes:
console.log( mylogpdf( 20.0 ) );
// => ~-3.365

// Logarithm of the probability density function at 15 minutes:
console.log( mylogpdf( 15.0 ) );
// => ~-3.059
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[wald-distribution]: https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution

<!-- <toc-links> -->

[@stdlib/stats/base/dists/wald/kurtosis]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/kurtosis

[@stdlib/stats/base/dists/wald/mean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/mean

[@stdlib/stats/base/dists/wald/mode]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/mode

[@stdlib/stats/base/dists/wald/skewness]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/skewness

[@stdlib/stats/base/dists/wald/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/stdev

[@stdlib/stats/base/dists/wald/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/variance

[@stdlib/stats/base/dists/wald/cdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/cdf

[@stdlib/stats/base/dists/wald/logcdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/logcdf

[@stdlib/stats/base/dists/wald/logpdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/logpdf

[@stdlib/stats/base/dists/wald/mgf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/mgf

[@stdlib/stats/base/dists/wald/pdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/pdf

[@stdlib/stats/base/dists/wald/quantile]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/wald/quantile

<!-- </toc-links> -->

</section>

<!-- /.links -->
Loading
Loading