Skip to content

Commit 28bdda3

Browse files
docs: improve examples of stats/base/dists/chisquare namespace
PR-URL: #2678 Closes: #1619 Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 1983295 commit 28bdda3

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,36 @@ var mu = dist.mean;
108108
<!-- eslint no-undef: "error" -->
109109

110110
```javascript
111-
var objectKeys = require( '@stdlib/utils/keys' );
111+
var roundn = require( '@stdlib/math/base/special/roundn' );
112112
var chisquare = require( '@stdlib/stats/base/dists/chisquare' );
113113

114-
console.log( objectKeys( chisquare ) );
114+
// Define degrees of freedom:
115+
var k = 5.0;
116+
117+
// Calculate distribution properties:
118+
console.log( 'Mean: %d', chisquare.mean( k ) );
119+
console.log( 'Median: %d', roundn( chisquare.median( k ), -4 ) );
120+
console.log( 'Mode: %d', chisquare.mode( k ) );
121+
console.log( 'Variance: %d', chisquare.variance( k ) );
122+
console.log( 'Standard Deviation: %d', roundn( chisquare.stdev( k ), -4 ) );
123+
console.log( 'Skewness: %d', roundn( chisquare.skewness( k ), -4 ) );
124+
console.log( 'Excess Kurtosis: %d', roundn( chisquare.kurtosis( k ), -4 ) );
125+
console.log( 'Entropy: %d', roundn( chisquare.entropy( k ), -4 ) );
126+
127+
// Evaluate probability functions:
128+
var x = 3.0;
129+
console.log( '\nEvaluating at x = %d', x );
130+
console.log( 'PDF: %d', roundn( chisquare.pdf( x, k ), -4 ) );
131+
console.log( 'logPDF: %d', roundn( chisquare.logpdf( x, k ), -4 ) );
132+
console.log( 'CDF: %d', roundn( chisquare.cdf( x, k ), -4 ) );
133+
134+
// Calculate quantiles:
135+
var p = 0.7;
136+
console.log( '\nQuantile at p = %d: %d', p, roundn( chisquare.quantile( p, k ), -4 ) );
137+
138+
// Evaluate moment-generating function:
139+
var t = 0.1;
140+
console.log( 'MGF at t = %d: %d', t, roundn( chisquare.mgf( t, k ), -4 ) );
115141
```
116142

117143
</section>

lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,33 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
21+
var roundn = require( '@stdlib/math/base/special/roundn' );
2222
var chisquare = require( './../lib' );
2323

24-
console.log( objectKeys( chisquare ) );
24+
// Define degrees of freedom:
25+
var k = 5.0;
26+
27+
// Calculate distribution properties:
28+
console.log( 'Mean: %d', chisquare.mean( k ) );
29+
console.log( 'Median: %d', roundn( chisquare.median( k ), -4 ) );
30+
console.log( 'Mode: %d', chisquare.mode( k ) );
31+
console.log( 'Variance: %d', chisquare.variance( k ) );
32+
console.log( 'Standard Deviation: %d', roundn( chisquare.stdev( k ), -4 ) );
33+
console.log( 'Skewness: %d', roundn( chisquare.skewness( k ), -4 ) );
34+
console.log( 'Excess Kurtosis: %d', roundn( chisquare.kurtosis( k ), -4 ) );
35+
console.log( 'Entropy: %d', roundn( chisquare.entropy( k ), -4 ) );
36+
37+
// Evaluate probability functions:
38+
var x = 3.0;
39+
console.log( '\nEvaluating at x = %d', x );
40+
console.log( 'PDF: %d', roundn( chisquare.pdf( x, k ), -4 ) );
41+
console.log( 'logPDF: %d', roundn( chisquare.logpdf( x, k ), -4 ) );
42+
console.log( 'CDF: %d', roundn( chisquare.cdf( x, k ), -4 ) );
43+
44+
// Calculate quantiles:
45+
var p = 0.7;
46+
console.log( '\nQuantile at p = %d: %d', p, roundn( chisquare.quantile( p, k ), -4 ) );
47+
48+
// Evaluate moment-generating function:
49+
var t = 0.1;
50+
console.log( 'MGF at t = %d: %d', t, roundn( chisquare.mgf( t, k ), -4 ) );

0 commit comments

Comments
 (0)