@@ -109,10 +109,59 @@ var y = dist.pdf( 2.0 );
109
109
<!-- eslint no-undef: "error" -->
110
110
111
111
``` javascript
112
- var objectKeys = require ( ' @stdlib/utils/keys' );
112
+ var Float64Array = require ( ' @stdlib/array/float64' );
113
+ var filledarrayBy = require (' @stdlib/array/filled-by' );
114
+ var mean = require ( ' @stdlib/stats/base/mean' );
115
+ var variance = require ( ' @stdlib/stats/base/variance' );
116
+ var stdev = require ( ' @stdlib/stats/base/stdev' );
117
+ var randGumbel = require ( ' @stdlib/random/base/gumbel' ).factory ;
113
118
var gumbel = require ( ' @stdlib/stats/base/dists/gumbel' );
114
119
115
- console .log ( objectKeys ( gumbel ) );
120
+ // Set the parameters of the Gumbel distribution:
121
+ var mu = 30.0 ; // Location parameter (e.g., average annual maximum temperature in °C)
122
+ var beta = 5.0 ; // Scale parameter
123
+
124
+ // Simulate annual maximum daily temperatures over 1000 years:
125
+ var N = 1000 ;
126
+ var rgumbel = randGumbel ( mu, beta );
127
+ var maxTemperatures = filledarrayBy ( N , ' float64' , rgumbel );
128
+
129
+ // Compute theoretical statistics of the Gumbel distribution:
130
+ var theoreticalMean = gumbel .mean ( mu, beta);
131
+ var theoreticalVariance = gumbel .variance ( mu, beta );
132
+ var theoreticalStdev = gumbel .stdev ( mu, beta );
133
+
134
+ // Compute sample statistics of the simulated data:
135
+ var sampleMean = mean ( N , maxTemperatures, 1 );
136
+ var sampleVariance = variance ( N , 1 , maxTemperatures, 1 ); // with Bessel's correction
137
+ var sampleStdev = stdev ( N , 1 , maxTemperatures, 1 ); // with Bessel's correction
138
+
139
+ // Display theoretical and sample statistics:
140
+ console .log ( ' --- Statistical Comparison ---\n ' );
141
+ console .log ( ' Mean:' );
142
+ console .log ( ' Theoretical: %d°C' , theoreticalMean .toFixed (2 ) );
143
+ console .log ( ' Sample: %d°C\n ' , sampleMean .toFixed (2 ) );
144
+ console .log ( ' Variance:' );
145
+ console .log ( ' Theoretical: %d°C²' , theoreticalVariance .toFixed (2 ) );
146
+ console .log ( ' Sample: %d°C²\n ' , sampleVariance .toFixed (2 ) );
147
+ console .log ( ' Standard Deviation:' );
148
+ console .log ( ' Theoretical: %d°C' , theoreticalStdev .toFixed (2 ) );
149
+ console .log ( ' Sample: %d°C\n ' , sampleStdev .toFixed (2 ) );
150
+
151
+ // Define quantile probabilities:
152
+ var p = new Float64Array ( [ 0.25 , 0.5 , 0.75 ] );
153
+ var label = [ ' First Quartile' , ' Median' , ' Third Quartile' ];
154
+ var theoreticalQuantiles = new Float64Array ([
155
+ gumbel .quantile ( p[0 ], mu, beta ),
156
+ gumbel .quantile ( p[1 ], mu, beta ),
157
+ gumbel .quantile ( p[2 ], mu, beta )
158
+ ]);
159
+
160
+ console .log ( ' Quantiles:' );
161
+ var i;
162
+ for ( i = 0 ; i < p .length ; i++ ) {
163
+ console .log ( label[i] + ' : %d°C' , theoreticalQuantiles[i].toFixed (2 ) );
164
+ }
116
165
```
117
166
118
167
</section >
0 commit comments