Skip to content

Commit

Permalink
docs: improve README examples for Rayleigh distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Jai0401 committed Mar 7, 2024
1 parent f626157 commit a6783fe
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
38 changes: 36 additions & 2 deletions lib/node_modules/@stdlib/stats/base/dists/rayleigh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,44 @@ var y = dist.pdf( 0.8 );
<!-- eslint no-undef: "error" -->

```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' );

console.log( objectKeys( rayleigh ) );
/*
* The Rayleigh distribution is often used to model wind speeds.
* Let's consider a scenario where we want to estimate various properties related to wind speeds.
*/

// Set the Rayleigh distribution parameter (scale parameter):
var s = 10.0;

// Calculate mean, variance, and standard deviation of the Rayleigh distribution:
console.log( rayleigh.mean( s ) );
// => ~12.533

console.log( rayleigh.variance( s ) );
// => ~42.920

console.log( rayleigh.stdev( s ) );
// => ~6.551

// Evaluate the Probability Density Function (PDF) for a specific wind speed:
var w = 15.0;
console.log( rayleigh.pdf( w, s ) );
// => 0.04869787010375246

// Determine Cumulative Distribution Function (CDF) for wind speeds up to a certain value:
var t = 15.0;
console.log( rayleigh.cdf( t, s ) );
// => ~0.675

// Calculate the probability of wind speeds exceeding the threshold:
var p = 1.0 - rayleigh.cdf( t, s );
console.log( 'Probability of wind speeds exceeding ' + t + ' m/s:', p );

// Find the wind speed at which there's a 70% chance it won't exceed using the Quantile function:
var c = 0.7;
console.log( rayleigh.quantile( c, s ) );
// => 15.517556536555205
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,41 @@

'use strict';

var objectKeys = require( '@stdlib/utils/keys' );
var rayleigh = require( './../lib' );

console.log( objectKeys( rayleigh ) );
/*
* The Rayleigh distribution is often used to model wind speeds.
* Let's consider a scenario where we want to estimate various properties related to wind speeds.
*/

// Set the Rayleigh distribution parameter (scale parameter):
var s = 10.0;

// Calculate mean, variance, and standard deviation of the Rayleigh distribution:
console.log( rayleigh.mean( s ) );
// => ~12.533

console.log( rayleigh.variance( s ) );
// => ~42.920

console.log( rayleigh.stdev( s ) );
// => ~6.551

// Evaluate the Probability Density Function (PDF) for a specific wind speed:
var w = 15.0;
console.log( rayleigh.pdf( w, s ) );
// => 0.04869787010375246

// Determine Cumulative Distribution Function (CDF) for wind speeds up to a certain value:
var t = 15.0;
console.log( rayleigh.cdf( t, s ) );
// => ~0.675

// Calculate the probability of wind speeds exceeding the threshold:
var p = 1.0 - rayleigh.cdf( t, s );
console.log( 'Probability of wind speeds exceeding ' + t + ' m/s:', p );

// Find the wind speed at which there's a 70% chance it won't exceed using the Quantile function:
var c = 0.7;
console.log( rayleigh.quantile( c, s ) );
// => 15.517556536555205

0 comments on commit a6783fe

Please sign in to comment.