From 28bdda3affa89470bbdf531cb3bbc233c85d3d17 Mon Sep 17 00:00:00 2001 From: Kohantika Nath <145763549+kohantikanath@users.noreply.github.com> Date: Mon, 18 Nov 2024 02:31:36 +0530 Subject: [PATCH] docs: improve examples of `stats/base/dists/chisquare` namespace PR-URL: https://github.com/stdlib-js/stdlib/pull/2678 Closes: https://github.com/stdlib-js/stdlib/issues/1619 Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../stats/base/dists/chisquare/README.md | 30 +++++++++++++++++-- .../base/dists/chisquare/examples/index.js | 30 +++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md b/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md index f4c6a0505a4..7d4d99dadb6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md @@ -108,10 +108,36 @@ var mu = dist.mean; ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); +var roundn = require( '@stdlib/math/base/special/roundn' ); var chisquare = require( '@stdlib/stats/base/dists/chisquare' ); -console.log( objectKeys( chisquare ) ); +// Define degrees of freedom: +var k = 5.0; + +// Calculate distribution properties: +console.log( 'Mean: %d', chisquare.mean( k ) ); +console.log( 'Median: %d', roundn( chisquare.median( k ), -4 ) ); +console.log( 'Mode: %d', chisquare.mode( k ) ); +console.log( 'Variance: %d', chisquare.variance( k ) ); +console.log( 'Standard Deviation: %d', roundn( chisquare.stdev( k ), -4 ) ); +console.log( 'Skewness: %d', roundn( chisquare.skewness( k ), -4 ) ); +console.log( 'Excess Kurtosis: %d', roundn( chisquare.kurtosis( k ), -4 ) ); +console.log( 'Entropy: %d', roundn( chisquare.entropy( k ), -4 ) ); + +// Evaluate probability functions: +var x = 3.0; +console.log( '\nEvaluating at x = %d', x ); +console.log( 'PDF: %d', roundn( chisquare.pdf( x, k ), -4 ) ); +console.log( 'logPDF: %d', roundn( chisquare.logpdf( x, k ), -4 ) ); +console.log( 'CDF: %d', roundn( chisquare.cdf( x, k ), -4 ) ); + +// Calculate quantiles: +var p = 0.7; +console.log( '\nQuantile at p = %d: %d', p, roundn( chisquare.quantile( p, k ), -4 ) ); + +// Evaluate moment-generating function: +var t = 0.1; +console.log( 'MGF at t = %d: %d', t, roundn( chisquare.mgf( t, k ), -4 ) ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js index 93d672bacc8..95e4bf94718 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js @@ -18,7 +18,33 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var roundn = require( '@stdlib/math/base/special/roundn' ); var chisquare = require( './../lib' ); -console.log( objectKeys( chisquare ) ); +// Define degrees of freedom: +var k = 5.0; + +// Calculate distribution properties: +console.log( 'Mean: %d', chisquare.mean( k ) ); +console.log( 'Median: %d', roundn( chisquare.median( k ), -4 ) ); +console.log( 'Mode: %d', chisquare.mode( k ) ); +console.log( 'Variance: %d', chisquare.variance( k ) ); +console.log( 'Standard Deviation: %d', roundn( chisquare.stdev( k ), -4 ) ); +console.log( 'Skewness: %d', roundn( chisquare.skewness( k ), -4 ) ); +console.log( 'Excess Kurtosis: %d', roundn( chisquare.kurtosis( k ), -4 ) ); +console.log( 'Entropy: %d', roundn( chisquare.entropy( k ), -4 ) ); + +// Evaluate probability functions: +var x = 3.0; +console.log( '\nEvaluating at x = %d', x ); +console.log( 'PDF: %d', roundn( chisquare.pdf( x, k ), -4 ) ); +console.log( 'logPDF: %d', roundn( chisquare.logpdf( x, k ), -4 ) ); +console.log( 'CDF: %d', roundn( chisquare.cdf( x, k ), -4 ) ); + +// Calculate quantiles: +var p = 0.7; +console.log( '\nQuantile at p = %d: %d', p, roundn( chisquare.quantile( p, k ), -4 ) ); + +// Evaluate moment-generating function: +var t = 0.1; +console.log( 'MGF at t = %d: %d', t, roundn( chisquare.mgf( t, k ), -4 ) );