Skip to content

Commit 790bfda

Browse files
committed
chore: clean-up examples
1 parent 1c62799 commit 790bfda

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

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

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

110110
```javascript
111+
var roundn = require( '@stdlib/math/base/special/roundn' );
111112
var chisquare = require( '@stdlib/stats/base/dists/chisquare' );
112-
var round = require( '@stdlib/math/base/special/round' );
113113

114-
// Define degrees of freedom
114+
// Define degrees of freedom:
115115
var k = 5.0;
116116

117-
// Create a chi-square distribution object
118-
var dist = new chisquare.ChiSquare( k );
119-
120-
console.log( 'Chi-square distribution with %d degrees of freedom:', k );
121-
122-
// Calculate basic properties
117+
// Calculate distribution properties:
123118
console.log( 'Mean: %d', chisquare.mean( k ) );
124-
console.log( 'Median: %d', round( chisquare.median( k ), 4 ) );
119+
console.log( 'Median: %d', roundn( chisquare.median( k ), -4 ) );
125120
console.log( 'Mode: %d', chisquare.mode( k ) );
126121
console.log( 'Variance: %d', chisquare.variance( k ) );
127-
console.log( 'Standard Deviation: %d', round( chisquare.stdev( k ), 4 ) );
128-
129-
// Calculate distribution shape properties
130-
console.log( 'Skewness: %d', round( chisquare.skewness( k ), 4 ) );
131-
console.log( 'Excess Kurtosis: %d', round( chisquare.kurtosis( k ), 4 ) );
132-
console.log( 'Entropy: %d', round( chisquare.entropy( k ), 4 ) );
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 ) );
133126

134-
// Evaluate probability functions
127+
// Evaluate probability functions:
135128
var x = 3.0;
136129
console.log( '\nEvaluating at x = %d', x );
137-
console.log( 'PDF: %d', round( chisquare.pdf( x, k ), 4 ) );
138-
console.log( 'logPDF: %d', round( chisquare.logpdf( x, k ), 4 ) );
139-
console.log( 'CDF: %d', round( chisquare.cdf( x, k ), 4 ) );
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 ) );
140133

141-
// Calculate quantiles
134+
// Calculate quantiles:
142135
var p = 0.7;
143-
console.log( '\nQuantile at p = %d: %d', p, round( chisquare.quantile( p, k ), 4 ) );
136+
console.log( '\nQuantile at p = %d: %d', p, roundn( chisquare.quantile( p, k ), -4 ) );
144137

145-
// Evaluate moment-generating function
138+
// Evaluate moment-generating function:
146139
var t = 0.1;
147-
console.log( 'MGF at t = %d: %d', t, round( chisquare.mgf( t, k ), 4 ) );
148-
149-
// Generate random variates
150-
var seed = 1234;
151-
var rand = chisquare.factory( k, {
152-
'seed': seed
153-
});
154-
var samples = new Array( 5 );
155-
for ( var i = 0; i < 5; i++ ) {
156-
samples[ i ] = round( rand(), 2 );
157-
}
158-
console.log( '\nRandom samples: %s', samples.join( ', ' ) );
140+
console.log( 'MGF at t = %d: %d', t, roundn( chisquare.mgf( t, k ), -4 ) );
159141
```
160142

161143
</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)