Skip to content

Commit 71af75e

Browse files
docs: improve examples stats/base/dists/triangular namespace
PR-URL: #1952 Closes: #1646 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent bff7edc commit 71af75e

File tree

2 files changed

+102
-6
lines changed

2 files changed

+102
-6
lines changed

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

+51-4
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,62 @@ y = dist.quantile( 1.9 );
107107

108108
## Examples
109109

110-
<!-- TODO: better examples -->
111-
112110
<!-- eslint no-undef: "error" -->
113111

114112
```javascript
115-
var objectKeys = require( '@stdlib/utils/keys' );
113+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
116114
var triangular = require( '@stdlib/stats/base/dists/triangular' );
117115

118-
console.log( objectKeys( triangular ) );
116+
// Scenario: Modeling completion time for a software development task
117+
118+
// Define the distribution parameters (in hours):
119+
var a = 1.5; // Minimum time (best-case scenario)
120+
var b = 4.5; // Maximum time (worst-case scenario)
121+
var c = discreteUniform( 2, 4 ); // Most likely time (mode)
122+
console.log( 'a: %d, b: %d, c: %d', a, b, c );
123+
124+
// Expected (mean) completion time:
125+
var mean = triangular.mean( a, b, c );
126+
console.log( '\nExpected completion time: %d hours', mean );
127+
128+
// Median completion time:
129+
var median = triangular.median( a, b, c );
130+
console.log( 'Median completion time: %d hours', median );
131+
132+
// Variance in completion time:
133+
var variance = triangular.variance( a, b, c );
134+
console.log( 'Variance in completion time: %d hours^2', variance );
135+
136+
// Probability of completing the task within 3 hours:
137+
var x = 3.0;
138+
var prob = triangular.cdf( x, a, b, c );
139+
console.log( '\nProbability of completing within %d hours: %d', x, prob );
140+
141+
// 90th percentile of completion time:
142+
var p = 0.9;
143+
var percentile = triangular.quantile( p, a, b, c );
144+
console.log( '90% of tasks will be completed within %d hours', percentile );
145+
146+
// Relative likelihood of completing the task in exactly 2.5 hours:
147+
x = 2.5;
148+
var likelihood = triangular.pdf( x, a, b, c );
149+
console.log( '\nRelative likelihood of completing in exactly %d hours: %d', x, likelihood );
150+
151+
// Skewness to understand the distribution's shape:
152+
var skewness = triangular.skewness( a, b, c );
153+
console.log( '\nSkewness of completion times: %d', skewness );
154+
if ( skewness > 0 ) {
155+
console.log( 'The distribution is right-skewed, suggesting occasional longer completion times.' );
156+
} else if ( skewness < 0 ) {
157+
console.log( 'The distribution is left-skewed, suggesting occasional shorter completion times.' );
158+
} else {
159+
console.log( 'The distribution is symmetric.' );
160+
}
161+
162+
// Entropy as a measure of uncertainty in the estimate:
163+
var entropy = triangular.entropy( a, b, c );
164+
console.log( '\nEntropy of the distribution: %d nats', entropy );
165+
console.log( 'Higher entropy indicates more uncertainty in completion times.' );
119166
```
120167

121168
</section>

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

+51-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,56 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
21+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
2222
var triangular = require( './../lib' );
2323

24-
console.log( objectKeys( triangular ) );
24+
// Scenario: Modeling completion time for a software development task
25+
26+
// Define the distribution parameters (in hours):
27+
var a = 1.5; // Minimum time (best-case scenario)
28+
var b = 4.5; // Maximum time (worst-case scenario)
29+
var c = discreteUniform( 2, 4 ); // Most likely time (mode)
30+
console.log( 'a: %d, b: %d, c: %d', a, b, c );
31+
32+
// Expected (mean) completion time:
33+
var mean = triangular.mean( a, b, c );
34+
console.log( '\nExpected completion time: %d hours', mean );
35+
36+
// Median completion time:
37+
var median = triangular.median( a, b, c );
38+
console.log( 'Median completion time: %d hours', median );
39+
40+
// Variance in completion time:
41+
var variance = triangular.variance( a, b, c );
42+
console.log( 'Variance in completion time: %d hours^2', variance );
43+
44+
// Probability of completing the task within 3 hours:
45+
var x = 3.0;
46+
var prob = triangular.cdf( x, a, b, c );
47+
console.log( '\nProbability of completing within %d hours: %d', x, prob );
48+
49+
// 90th percentile of completion time:
50+
var p = 0.9;
51+
var percentile = triangular.quantile( p, a, b, c );
52+
console.log( '90% of tasks will be completed within %d hours', percentile );
53+
54+
// Relative likelihood of completing the task in exactly 2.5 hours:
55+
x = 2.5;
56+
var likelihood = triangular.pdf( x, a, b, c );
57+
console.log( '\nRelative likelihood of completing in exactly %d hours: %d', x, likelihood );
58+
59+
// Skewness to understand the distribution's shape:
60+
var skewness = triangular.skewness( a, b, c );
61+
console.log( '\nSkewness of completion times: %d', skewness );
62+
if ( skewness > 0 ) {
63+
console.log( 'The distribution is right-skewed, suggesting occasional longer completion times.' );
64+
} else if ( skewness < 0 ) {
65+
console.log( 'The distribution is left-skewed, suggesting occasional shorter completion times.' );
66+
} else {
67+
console.log( 'The distribution is symmetric.' );
68+
}
69+
70+
// Entropy as a measure of uncertainty in the estimate:
71+
var entropy = triangular.entropy( a, b, c );
72+
console.log( '\nEntropy of the distribution: %d nats', entropy );
73+
console.log( 'Higher entropy indicates more uncertainty in completion times.' );

0 commit comments

Comments
 (0)