@@ -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' );
111112var 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:
115115var 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:
123118console .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 ) );
125120console .log ( ' Mode: %d' , chisquare .mode ( k ) );
126121console .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:
135128var x = 3.0 ;
136129console .log ( ' \n Evaluating 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:
142135var p = 0.7 ;
143- console .log ( ' \n Quantile at p = %d: %d' , p, round ( chisquare .quantile ( p, k ), 4 ) );
136+ console .log ( ' \n Quantile at p = %d: %d' , p, roundn ( chisquare .quantile ( p, k ), - 4 ) );
144137
145- // Evaluate moment-generating function
138+ // Evaluate moment-generating function:
146139var 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 ( ' \n Random samples: %s' , samples .join ( ' , ' ) );
140+ console .log ( ' MGF at t = %d: %d' , t, roundn ( chisquare .mgf ( t, k ), - 4 ) );
159141```
160142
161143</section >
0 commit comments