From d7919883e765d375ebfae924aa782bce48194cb4 Mon Sep 17 00:00:00 2001 From: Ahmed Atwa Date: Sun, 3 Mar 2024 23:31:47 +0200 Subject: [PATCH 1/3] docs: add examples and documentation for normal distribution --- .../@stdlib/stats/base/dists/normal/README.md | 90 +++++++++++++++++++ .../base/dists/normal/examples/example1.js | 40 +++++++++ .../base/dists/normal/examples/example2.js | 36 ++++++++ .../base/dists/normal/examples/example3.js | 42 +++++++++ .../base/dists/normal/examples/example4.js | 38 ++++++++ 5 files changed, 246 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/README.md b/lib/node_modules/@stdlib/stats/base/dists/normal/README.md index 7d8fd6317786..2d2f84bfcf74 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/README.md @@ -115,6 +115,96 @@ var normal = require( '@stdlib/stats/base/dists/normal' ); console.log( objectKeys( normal ) ); ``` +```javascript +var Normal = require( '@stdlib/stats/base/dists/normal/ctor' ); + +var normalDist = new Normal( 4.0, 9.0 ); + +console.log(normalDist.sigma); +// => 9.0 + +normalDist.sigma = 12.0; + +console.log(normalDist.sigma); +// => 12.0 + +console.log(normalDist.kurtosis); +// => 0.0 + +console.log(normalDist.median); +// => 4.0 + +console.log(normalDist.variance); +// => 144.0 +``` + +```javascript +var normal = require( '@stdlib/stats/base/dists/normal' ); + +var mean = 4; +var sigma = 9; + +console.log(normal.pdf( 2.0, mean, sigma )); +// => ~ 0.043 + +console.log(normal.cdf( 2.0, mean, sigma )); +// => ~ 0.412 + +console.log(normal.quantile( 0.5, mean, sigma )); +// => 4.0 + +console.log(normal.mgf( 0.5, mean, sigma )); +// => ~ 184425.34 +``` + +```javascript +var normal = require( '@stdlib/stats/base/dists/normal' ); + +var mean = 2; +var sigma = 3; + +console.log(normal.entropy( mean, sigma )); +// => ~ 2.51755 + +console.log(normal.mean( mean, sigma )); +// => 2.0 + +console.log(normal.median( mean, sigma )); +// => 2.0 + +console.log(normal.mode( mean, sigma )); +// => 2.0 + +console.log(normal.variance( mean, sigma )); +// => 9.0 + +console.log(normal.skewness( mean, sigma )); +// => 0.0 + +``` + +```javascript +var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); +var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); + +var myquantile = quantile.factory( 10.0, 2.0 ); + +console.log(myquantile( 0.2 )); +// => ~ 8.317 + +console.log(myquantile( 0.8 )); +// => ~ 11.683 + +var mylogpdf = logpdf.factory( 10.0, 2.0 ); + +console.log(mylogpdf( 10.0 )); +// => ~ -1.612 + +console.log(mylogpdf( 5.0 )); +// => ~ -4.737 +``` + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js new file mode 100644 index 000000000000..c83767a8a51a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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. +*/ + +'use strict'; + +var Normal = require( '@stdlib/stats/base/dists/normal/ctor' ); + +var normalDist = new Normal( 4.0, 9.0 ); + +console.log(normalDist.sigma); +// => 9.0 + +normalDist.sigma = 12.0; + +console.log(normalDist.sigma); +// => 12.0 + +console.log(normalDist.kurtosis); +// => 0.0 + +console.log(normalDist.median); +// => 4.0 + +console.log(normalDist.variance); +// => 144.0 diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js new file mode 100644 index 000000000000..bdf227e820a5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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. +*/ + +'use strict'; + +var normal = require( '@stdlib/stats/base/dists/normal' ); + +var mean = 4; +var sigma = 9; + +console.log(normal.pdf( 2.0, mean, sigma )); +// => ~ 0.043 + +console.log(normal.cdf( 2.0, mean, sigma )); +// => ~ 0.412 + +console.log(normal.quantile( 0.5, mean, sigma )); +// => 4.0 + +console.log(normal.mgf( 0.5, mean, sigma )); +// => ~ 184425.34 diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js new file mode 100644 index 000000000000..5850edf98124 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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. +*/ + +'use strict'; + +var normal = require( '@stdlib/stats/base/dists/normal' ); + +var mean = 2; +var sigma = 3; + +console.log(normal.entropy( mean, sigma )); +// => ~ 2.51755 + +console.log(normal.mean( mean, sigma )); +// => 2.0 + +console.log(normal.median( mean, sigma )); +// => 2.0 + +console.log(normal.mode( mean, sigma )); +// => 2.0 + +console.log(normal.variance( mean, sigma )); +// => 9.0 + +console.log(normal.skewness( mean, sigma )); +// => 0.0 diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js new file mode 100644 index 000000000000..82d99d587ecc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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. +*/ + +'use strict'; + +var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); +var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); + +var myquantile = quantile.factory( 10.0, 2.0 ); + +console.log(myquantile( 0.2 )); +// => ~ 8.317 + +console.log(myquantile( 0.8 )); +// => ~ 11.683 + +var mylogpdf = logpdf.factory( 10.0, 2.0 ); + +console.log(mylogpdf( 10.0 )); +// => ~ -1.612 + +console.log(mylogpdf( 5.0 )); +// => ~ -4.737 From da359ebbfe448894ece9e85fb6e537e669060843 Mon Sep 17 00:00:00 2001 From: Ahmed Atwa Date: Mon, 4 Mar 2024 15:38:51 +0200 Subject: [PATCH 2/3] docs: merge all examples --- .../@stdlib/stats/base/dists/normal/README.md | 29 ++----- .../base/dists/normal/examples/example1.js | 40 ---------- .../base/dists/normal/examples/example2.js | 36 --------- .../base/dists/normal/examples/example3.js | 42 ---------- .../base/dists/normal/examples/example4.js | 38 ---------- .../stats/base/dists/normal/examples/index.js | 76 ++++++++++++++++++- 6 files changed, 82 insertions(+), 179 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js delete mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js delete mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js delete mode 100644 lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/README.md b/lib/node_modules/@stdlib/stats/base/dists/normal/README.md index 2d2f84bfcf74..d812c250be55 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/README.md @@ -109,16 +109,15 @@ var y = dist.pdf( 2.0 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); var normal = require( '@stdlib/stats/base/dists/normal' ); +var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); +var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); +var normalConstructor = require( '@stdlib/stats/base/dists/normal/ctor' ); +var objectKeys = require( '@stdlib/utils/keys' ); console.log( objectKeys( normal ) ); -``` -```javascript -var Normal = require( '@stdlib/stats/base/dists/normal/ctor' ); - -var normalDist = new Normal( 4.0, 9.0 ); +var normalDist = new normalConstructor( 4.0, 9.0 ); console.log(normalDist.sigma); // => 9.0 @@ -136,10 +135,6 @@ console.log(normalDist.median); console.log(normalDist.variance); // => 144.0 -``` - -```javascript -var normal = require( '@stdlib/stats/base/dists/normal' ); var mean = 4; var sigma = 9; @@ -155,13 +150,9 @@ console.log(normal.quantile( 0.5, mean, sigma )); console.log(normal.mgf( 0.5, mean, sigma )); // => ~ 184425.34 -``` -```javascript -var normal = require( '@stdlib/stats/base/dists/normal' ); - -var mean = 2; -var sigma = 3; +mean = 2; +sigma = 3; console.log(normal.entropy( mean, sigma )); // => ~ 2.51755 @@ -181,12 +172,6 @@ console.log(normal.variance( mean, sigma )); console.log(normal.skewness( mean, sigma )); // => 0.0 -``` - -```javascript -var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); -var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); - var myquantile = quantile.factory( 10.0, 2.0 ); console.log(myquantile( 0.2 )); diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js deleted file mode 100644 index c83767a8a51a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example1.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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. -*/ - -'use strict'; - -var Normal = require( '@stdlib/stats/base/dists/normal/ctor' ); - -var normalDist = new Normal( 4.0, 9.0 ); - -console.log(normalDist.sigma); -// => 9.0 - -normalDist.sigma = 12.0; - -console.log(normalDist.sigma); -// => 12.0 - -console.log(normalDist.kurtosis); -// => 0.0 - -console.log(normalDist.median); -// => 4.0 - -console.log(normalDist.variance); -// => 144.0 diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js deleted file mode 100644 index bdf227e820a5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example2.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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. -*/ - -'use strict'; - -var normal = require( '@stdlib/stats/base/dists/normal' ); - -var mean = 4; -var sigma = 9; - -console.log(normal.pdf( 2.0, mean, sigma )); -// => ~ 0.043 - -console.log(normal.cdf( 2.0, mean, sigma )); -// => ~ 0.412 - -console.log(normal.quantile( 0.5, mean, sigma )); -// => 4.0 - -console.log(normal.mgf( 0.5, mean, sigma )); -// => ~ 184425.34 diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js deleted file mode 100644 index 5850edf98124..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example3.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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. -*/ - -'use strict'; - -var normal = require( '@stdlib/stats/base/dists/normal' ); - -var mean = 2; -var sigma = 3; - -console.log(normal.entropy( mean, sigma )); -// => ~ 2.51755 - -console.log(normal.mean( mean, sigma )); -// => 2.0 - -console.log(normal.median( mean, sigma )); -// => 2.0 - -console.log(normal.mode( mean, sigma )); -// => 2.0 - -console.log(normal.variance( mean, sigma )); -// => 9.0 - -console.log(normal.skewness( mean, sigma )); -// => 0.0 diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js deleted file mode 100644 index 82d99d587ecc..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/example4.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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. -*/ - -'use strict'; - -var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); -var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); - -var myquantile = quantile.factory( 10.0, 2.0 ); - -console.log(myquantile( 0.2 )); -// => ~ 8.317 - -console.log(myquantile( 0.8 )); -// => ~ 11.683 - -var mylogpdf = logpdf.factory( 10.0, 2.0 ); - -console.log(mylogpdf( 10.0 )); -// => ~ -1.612 - -console.log(mylogpdf( 5.0 )); -// => ~ -4.737 diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js index b14381659757..18f3037f3f0c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js @@ -18,7 +18,81 @@ 'use strict'; +var normal = require( '@stdlib/stats/base/dists/normal' ); +var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); +var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); +var normalConstructor = require( '@stdlib/stats/base/dists/normal/ctor' ); var objectKeys = require( '@stdlib/utils/keys' ); -var normal = require( './../lib' ); console.log( objectKeys( normal ) ); + +var normalDist = new normalConstructor( 4.0, 9.0 ); + +console.log(normalDist.sigma); +// => 9.0 + +normalDist.sigma = 12.0; + +console.log(normalDist.sigma); +// => 12.0 + +console.log(normalDist.kurtosis); +// => 0.0 + +console.log(normalDist.median); +// => 4.0 + +console.log(normalDist.variance); +// => 144.0 + +var mean = 4; +var sigma = 9; + +console.log(normal.pdf( 2.0, mean, sigma )); +// => ~ 0.043 + +console.log(normal.cdf( 2.0, mean, sigma )); +// => ~ 0.412 + +console.log(normal.quantile( 0.5, mean, sigma )); +// => 4.0 + +console.log(normal.mgf( 0.5, mean, sigma )); +// => ~ 184425.34 + +mean = 2; +sigma = 3; + +console.log(normal.entropy( mean, sigma )); +// => ~ 2.51755 + +console.log(normal.mean( mean, sigma )); +// => 2.0 + +console.log(normal.median( mean, sigma )); +// => 2.0 + +console.log(normal.mode( mean, sigma )); +// => 2.0 + +console.log(normal.variance( mean, sigma )); +// => 9.0 + +console.log(normal.skewness( mean, sigma )); +// => 0.0 + +var myquantile = quantile.factory( 10.0, 2.0 ); + +console.log(myquantile( 0.2 )); +// => ~ 8.317 + +console.log(myquantile( 0.8 )); +// => ~ 11.683 + +var mylogpdf = logpdf.factory( 10.0, 2.0 ); + +console.log(mylogpdf( 10.0 )); +// => ~ -1.612 + +console.log(mylogpdf( 5.0 )); +// => ~ -4.737 From 28efe87102eba352cde69ff73c270423d6b691ab Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 7 Jun 2024 22:40:53 -0400 Subject: [PATCH 3/3] docs: add scenario and comments for namespace examples --- .../@stdlib/stats/base/dists/normal/README.md | 120 ++++++++++------- .../stats/base/dists/normal/examples/index.js | 122 +++++++++++------- 2 files changed, 145 insertions(+), 97 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/README.md b/lib/node_modules/@stdlib/stats/base/dists/normal/README.md index d812c250be55..51ca75c899c8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/README.md @@ -110,83 +110,107 @@ var y = dist.pdf( 2.0 ); ```javascript var normal = require( '@stdlib/stats/base/dists/normal' ); -var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); -var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); -var normalConstructor = require( '@stdlib/stats/base/dists/normal/ctor' ); -var objectKeys = require( '@stdlib/utils/keys' ); -console.log( objectKeys( normal ) ); +/* +A bakery is analyzing cake baking times to ensure consistency and better schedule their baking processes. -var normalDist = new normalConstructor( 4.0, 9.0 ); +The Central Limit Theorem (CLT) states that the average baking times from many batches will follow a normal distribution if there are enough batches (typically n > 30). -console.log(normalDist.sigma); -// => 9.0 +Assuming each record represents the average baking time per batch and the bakery has collected the following data: -normalDist.sigma = 12.0; +- Mean baking time (μ/mu): 20 minutes. +- Standard deviation in baking time (σ/sigma): 3 minutes. -console.log(normalDist.sigma); -// => 12.0 +We can model the average bake times using a normal distribution with μ (mu) = 20.0 minutes and σ = 3.0 minutes. +*/ -console.log(normalDist.kurtosis); -// => 0.0 +var mu = 20.0; +var sigma = 3.0; + +var normalDist = new normal.Normal( mu, sigma ); + +// Output the standard deviation of the baking times: +console.log( normalDist.sigma ); +// => 3.0 -console.log(normalDist.median); +// Adjust distribution parameters +normalDist.sigma = 4.0; + +// Adjusted standard deviation to reflect different variance scenario: +console.log( normalDist.sigma ); // => 4.0 -console.log(normalDist.variance); -// => 144.0 +// Excess kurtosis of a normal distribution (measure of "tailedness"): +console.log( normalDist.kurtosis ); +// => 0.0 -var mean = 4; -var sigma = 9; +// Median baking time: +console.log( normalDist.median ); +// => 20.0 -console.log(normal.pdf( 2.0, mean, sigma )); -// => ~ 0.043 +// Variance of the baking times after adjusting sigma: +console.log( normalDist.variance ); +// => 16.0 -console.log(normal.cdf( 2.0, mean, sigma )); -// => ~ 0.412 +// Probability density function at the mean baking time: +console.log( normal.pdf( 20.0, mu, sigma ) ); +// => ~0.133 -console.log(normal.quantile( 0.5, mean, sigma )); -// => 4.0 +// Cumulative distribution function at the mean (portion of times ≤ 20 minutes): +console.log( normal.cdf( 20.0, mu, sigma ) ); +// => ~0.5 -console.log(normal.mgf( 0.5, mean, sigma )); -// => ~ 184425.34 +// 50th percentile (median) of the baking times: +console.log( normal.quantile( 0.5, mu, sigma ) ); +// => 20.0 -mean = 2; -sigma = 3; +// Moment-generating function value at 0.5 (used in probability theory): +console.log( normal.mgf( 0.5, mu, sigma ) ); +// => ~67846.291 -console.log(normal.entropy( mean, sigma )); -// => ~ 2.51755 +// Entropy of the normal distribution (measure of uncertainty): +console.log( normal.entropy( mu, sigma ) ); +// => ~2.518 -console.log(normal.mean( mean, sigma )); -// => 2.0 +// Mean baking time: +console.log( normal.mean( mu, sigma ) ); +// => 20.0 -console.log(normal.median( mean, sigma )); -// => 2.0 +// Median baking time: +console.log( normal.median( mu, sigma ) ); +// => 20.0 -console.log(normal.mode( mean, sigma )); -// => 2.0 +// Mode of the baking times (most frequent value): +console.log( normal.mode( mu, sigma ) ); +// => 20.0 -console.log(normal.variance( mean, sigma )); +// Variance of the baking times: +console.log( normal.variance( mu, sigma ) ); // => 9.0 -console.log(normal.skewness( mean, sigma )); +// Skewness of the distribution (symmetry measure): +console.log( normal.skewness( mu, sigma ) ); // => 0.0 -var myquantile = quantile.factory( 10.0, 2.0 ); +var myquantile = normal.quantile.factory( 20.0, 3.0 ); -console.log(myquantile( 0.2 )); -// => ~ 8.317 +// 20th percentile (value below which 20% baking times fall): +console.log( myquantile( 0.2 ) ); +// => ~17.475 -console.log(myquantile( 0.8 )); -// => ~ 11.683 +// 80th percentile (value below which 80% baking times fall): +console.log( myquantile( 0.8 ) ); +// => ~22.525 -var mylogpdf = logpdf.factory( 10.0, 2.0 ); +var mylogpdf = normal.logpdf.factory( 20.0, 3.0 ); -console.log(mylogpdf( 10.0 )); -// => ~ -1.612 +// Logarithm of the probability density function at the mean: +console.log( mylogpdf( 20.0 ) ); +// => ~-2.018 -console.log(mylogpdf( 5.0 )); -// => ~ -4.737 +// Logarithm of the probability density function at 15 minutes: +console.log( mylogpdf( 15.0 ) ); +// => ~-3.406 ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js index 18f3037f3f0c..19badd709e21 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/examples/index.js @@ -18,81 +18,105 @@ 'use strict'; -var normal = require( '@stdlib/stats/base/dists/normal' ); -var quantile = require( '@stdlib/stats/base/dists/normal/quantile' ); -var logpdf = require( '@stdlib/stats/base/dists/normal/logpdf' ); -var normalConstructor = require( '@stdlib/stats/base/dists/normal/ctor' ); -var objectKeys = require( '@stdlib/utils/keys' ); +var normal = require( './../lib' ); -console.log( objectKeys( normal ) ); +/* +A bakery is analyzing cake baking times to ensure consistency and better schedule their baking processes. -var normalDist = new normalConstructor( 4.0, 9.0 ); +The Central Limit Theorem (CLT) states that the average baking times from many batches will follow a normal distribution if there are enough batches (typically n > 30). -console.log(normalDist.sigma); -// => 9.0 +Assuming each record represents the average baking time per batch and the bakery has collected the following data: + +- Mean baking time (μ/mu): 20 minutes. +- Standard deviation in baking time (σ/sigma): 3 minutes. -normalDist.sigma = 12.0; +We can model the average bake times using a normal distribution with μ (mu) = 20.0 minutes and σ = 3.0 minutes. +*/ -console.log(normalDist.sigma); -// => 12.0 +var mu = 20.0; +var sigma = 3.0; -console.log(normalDist.kurtosis); -// => 0.0 +var normalDist = new normal.Normal( mu, sigma ); -console.log(normalDist.median); +// Output the standard deviation of the baking times: +console.log( normalDist.sigma ); +// => 3.0 + +// Adjust distribution parameters +normalDist.sigma = 4.0; + +// Adjusted standard deviation to reflect different variance scenario: +console.log( normalDist.sigma ); // => 4.0 -console.log(normalDist.variance); -// => 144.0 +// Excess kurtosis of a normal distribution (measure of "tailedness"): +console.log( normalDist.kurtosis ); +// => 0.0 -var mean = 4; -var sigma = 9; +// Median baking time: +console.log( normalDist.median ); +// => 20.0 -console.log(normal.pdf( 2.0, mean, sigma )); -// => ~ 0.043 +// Variance of the baking times after adjusting sigma: +console.log( normalDist.variance ); +// => 16.0 -console.log(normal.cdf( 2.0, mean, sigma )); -// => ~ 0.412 +// Probability density function at the mean baking time: +console.log( normal.pdf( 20.0, mu, sigma ) ); +// => ~0.133 -console.log(normal.quantile( 0.5, mean, sigma )); -// => 4.0 +// Cumulative distribution function at the mean (portion of times ≤ 20 minutes): +console.log( normal.cdf( 20.0, mu, sigma ) ); +// => ~0.5 -console.log(normal.mgf( 0.5, mean, sigma )); -// => ~ 184425.34 +// 50th percentile (median) of the baking times: +console.log( normal.quantile( 0.5, mu, sigma ) ); +// => 20.0 -mean = 2; -sigma = 3; +// Moment-generating function value at 0.5 (used in probability theory): +console.log( normal.mgf( 0.5, mu, sigma ) ); +// => ~67846.291 -console.log(normal.entropy( mean, sigma )); -// => ~ 2.51755 +// Entropy of the normal distribution (measure of uncertainty): +console.log( normal.entropy( mu, sigma ) ); +// => ~2.518 -console.log(normal.mean( mean, sigma )); -// => 2.0 +// Mean baking time: +console.log( normal.mean( mu, sigma ) ); +// => 20.0 -console.log(normal.median( mean, sigma )); -// => 2.0 +// Median baking time: +console.log( normal.median( mu, sigma ) ); +// => 20.0 -console.log(normal.mode( mean, sigma )); -// => 2.0 +// Mode of the baking times (most frequent value): +console.log( normal.mode( mu, sigma ) ); +// => 20.0 -console.log(normal.variance( mean, sigma )); +// Variance of the baking times: +console.log( normal.variance( mu, sigma ) ); // => 9.0 -console.log(normal.skewness( mean, sigma )); +// Skewness of the distribution (symmetry measure): +console.log( normal.skewness( mu, sigma ) ); // => 0.0 -var myquantile = quantile.factory( 10.0, 2.0 ); +var myquantile = normal.quantile.factory( 20.0, 3.0 ); -console.log(myquantile( 0.2 )); -// => ~ 8.317 +// 20th percentile (value below which 20% baking times fall): +console.log( myquantile( 0.2 ) ); +// => ~17.475 -console.log(myquantile( 0.8 )); -// => ~ 11.683 +// 80th percentile (value below which 80% baking times fall): +console.log( myquantile( 0.8 ) ); +// => ~22.525 -var mylogpdf = logpdf.factory( 10.0, 2.0 ); +var mylogpdf = normal.logpdf.factory( 20.0, 3.0 ); -console.log(mylogpdf( 10.0 )); -// => ~ -1.612 +// Logarithm of the probability density function at the mean: +console.log( mylogpdf( 20.0 ) ); +// => ~-2.018 -console.log(mylogpdf( 5.0 )); -// => ~ -4.737 +// Logarithm of the probability density function at 15 minutes: +console.log( mylogpdf( 15.0 ) ); +// => ~-3.406