@@ -107,15 +107,62 @@ y = dist.quantile( 1.9 );
107
107
108
108
## Examples
109
109
110
- <!-- TODO: better examples -->
111
-
112
110
<!-- eslint no-undef: "error" -->
113
111
114
112
``` javascript
115
- var objectKeys = require ( ' @stdlib/utils/keys ' );
113
+ var discreteUniform = require ( ' @stdlib/random/base/discrete-uniform ' );
116
114
var triangular = require ( ' @stdlib/stats/base/dists/triangular' );
117
115
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 ( ' \n Expected 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 ( ' \n Probability 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 ( ' \n Relative 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 ( ' \n Skewness 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 ( ' \n Entropy of the distribution: %d nats' , entropy );
165
+ console .log ( ' Higher entropy indicates more uncertainty in completion times.' );
119
166
```
120
167
121
168
</section >
0 commit comments