Skip to content

Commit bd64130

Browse files
committed
Docs:improve README examples of stats/base/dists/chisquare namespace
1 parent 69899f7 commit bd64130

File tree

1 file changed

+47
-3
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/chisquare

1 file changed

+47
-3
lines changed

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

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

110110
```javascript
111-
var objectKeys = require( '@stdlib/utils/keys' );
112111
var chisquare = require( '@stdlib/stats/base/dists/chisquare' );
113-
114-
console.log( objectKeys( chisquare ) );
112+
var round = require( '@stdlib/math/base/special/round' );
113+
114+
// Define degrees of freedom
115+
var k = 5.0;
116+
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
123+
console.log( 'Mean: %d', chisquare.mean( k ) );
124+
console.log( 'Median: %d', round( chisquare.median( k ), 4 ) );
125+
console.log( 'Mode: %d', chisquare.mode( k ) );
126+
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 ) );
133+
134+
// Evaluate probability functions
135+
var x = 3.0;
136+
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 ) );
140+
141+
// Calculate quantiles
142+
var p = 0.7;
143+
console.log( '\nQuantile at p = %d: %d', p, round( chisquare.quantile( p, k ), 4 ) );
144+
145+
// Evaluate moment-generating function
146+
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( ', ' ) );
115159
```
116160

117161
</section>

0 commit comments

Comments
 (0)