Skip to content

Commit 8caa497

Browse files
committed
chore: clean-up, fix examples, and update tests
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 583bc84 commit 8caa497

File tree

6 files changed

+72
-67
lines changed

6 files changed

+72
-67
lines changed

lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ Evaluates the [quantile function][quantile-function] for a [studentized range][s
4242

4343
```javascript
4444
var y = quantile( 0.5, 3.0, 2.0 );
45-
// returns ~0.0644
45+
// returns ~1.908
4646

4747
y = quantile( 0.9, 17.0, 2.0 );
48-
// returns ~0.913
48+
// returns ~11.237
4949

5050
y = quantile( 0.5, 3.0, 2.0, 2 );
51-
// returns ~0.01
51+
// returns ~2.549
5252
```
5353

5454
If provided a probability `p` outside the interval `[0,1]`, the function returns `NaN`.
@@ -86,13 +86,13 @@ y = quantile( 0.4, 3.0, 1.5 );
8686
Returns a function for evaluating the [quantile function][quantile-function] of an [studentized range][studentized-range] distribution with sample size `r` and `v` degrees of freedom. Optionally, the number of groups whose maximum range is considered can be specified via the `nranges` parameter.
8787

8888
```javascript
89-
var myquantile = quantile.factory( 4.0 );
89+
var myquantile = quantile.factory( 4.0, 3.0 );
9090

9191
var y = myquantile( 0.2 );
92-
// returns ~-0.941
92+
// returns ~1.2977
9393

9494
y = myquantile( 0.9 );
95-
// returns ~1.533
95+
// returns ~5.199
9696
```
9797

9898
</section>

lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/lib/factory.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var qtrngo = require( './qtrngo.js' );
3131

3232
// VARIABLES //
3333

34-
var PCUT = 1e-8;
34+
var PCUT = 1.0e-8;
3535
var JMAX = 28;
3636

3737

@@ -57,19 +57,13 @@ var JMAX = 28;
5757
* // returns Infinity
5858
*/
5959
function factory( r, v, nranges ) {
60-
if (
61-
isnan( r ) ||
62-
isnan( v ) ||
63-
r < 2.0 ||
64-
v < 2.0
65-
) {
60+
if ( isnan( r ) || isnan( v ) || r < 2.0 || v < 2.0 ) {
6661
return constantFunction( NaN );
6762
}
68-
if ( nranges === void 0 ) {
63+
if ( arguments.length < 3 ) {
6964
nranges = 1;
70-
}
71-
else if ( !isPositiveInteger( nranges ) ) {
72-
return NaN;
65+
} else if ( !isPositiveInteger( nranges ) ) {
66+
return constantFunction( NaN );
7367
}
7468
return quantile;
7569

@@ -117,7 +111,7 @@ function factory( r, v, nranges ) {
117111
}
118112
}
119113
aux = q1;
120-
if ( abs( p1 - p ) < PCUT ) {
114+
if ( abs( p1-p ) < PCUT ) {
121115
return NaN;
122116
}
123117
q2 = q1 + 0.5;
@@ -142,10 +136,10 @@ function factory( r, v, nranges ) {
142136
e1 = p1 - p;
143137
e2 = p2 - p;
144138
if ( e2 - e1 !== 0 ) {
145-
aux = ( ( e2 * q1 ) - ( e1 * q2 ) ) / ( e2 - e1 );
139+
aux = ( ( e2*q1 ) - ( e1*q2 ) ) / ( e2-e1 );
146140
}
147141
if ( abs( e1 ) < abs( e2 ) ) {
148-
if ( abs( p1 - p ) < PCUT * 5.0 ) {
142+
if ( abs( p1-p ) < ( PCUT*5.0 ) ) {
149143
j = JMAX + 2;
150144
}
151145
q1 = aux;

lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/lib/main.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var qtrngo = require( './qtrngo.js' );
3030

3131
// VARIABLES //
3232

33-
var PCUT = 1e-8;
33+
var PCUT = 1.0e-8;
3434
var JMAX = 28;
3535

3636

@@ -71,12 +71,7 @@ function qrange( p, r, v, nranges ) {
7171
var p2;
7272
var j;
7373

74-
if (
75-
isnan( r ) ||
76-
isnan( v ) ||
77-
r < 2.0 ||
78-
v < 2.0
79-
) {
74+
if ( isnan( r ) || isnan( v ) || r < 2.0 || v < 2.0 ) {
8075
return NaN;
8176
}
8277
if ( isnan( p ) || p < 0.0 || p > 1.0 ) {
@@ -88,10 +83,9 @@ function qrange( p, r, v, nranges ) {
8883
if ( p === 1.0 ) {
8984
return PINF;
9085
}
91-
if ( nranges === void 0 ) {
86+
if ( arguments.length < 4 ) {
9287
nranges = 1;
93-
}
94-
else if ( !isPositiveInteger( nranges ) ) {
88+
} else if ( !isPositiveInteger( nranges ) ) {
9589
return NaN;
9690
}
9791
q1 = qtrngo( p, v, r );
@@ -108,7 +102,7 @@ function qrange( p, r, v, nranges ) {
108102
}
109103
}
110104
aux = q1;
111-
if ( abs( p1 - p ) < PCUT ) {
105+
if ( abs( p1-p ) < PCUT ) {
112106
return NaN;
113107
}
114108
q2 = q1 + 0.5;
@@ -133,10 +127,10 @@ function qrange( p, r, v, nranges ) {
133127
e1 = p1 - p;
134128
e2 = p2 - p;
135129
if ( e2 - e1 !== 0 ) {
136-
aux = ( ( e2 * q1 ) - ( e1 * q2 ) ) / ( e2 - e1 );
130+
aux = ( ( e2*q1 ) - ( e1*q2 ) ) / ( e2-e1 );
137131
}
138132
if ( abs( e1 ) < abs( e2 ) ) {
139-
if ( abs( p1 - p ) < PCUT * 5.0 ) {
133+
if ( abs( p1-p ) < ( PCUT*5.0 ) ) {
140134
j = JMAX + 2;
141135
}
142136
q1 = aux;

lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/lib/qtrngo.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ var c5 = 1.4142;
4747
*/
4848
function qtrngo( p, v, r ) {
4949
var q;
50+
var t;
5051

51-
var t = apnorminv( 0.5 + ( 0.5 * p ) );
52+
t = apnorminv( 0.5 + ( 0.5*p ) );
5253
if ( v < VMAX ) {
53-
t += ( ( t * t * t ) + t) / v / 4.0;
54+
t += ( ( t*t*t ) + t ) / v / 4.0;
5455
}
55-
q = c1 - ( c2 * t );
56+
q = c1 - ( c2*t );
5657
if ( v < VMAX ) {
57-
q -= ( c3 / v ) + ( c4 * t / v );
58+
q -= ( c3/v ) + ( ( c4*t ) / v );
5859
}
59-
return t * ( ( q * ln(r - 1.0) ) + c5 );
60+
return t * ( ( q * ln( r-1.0 ) ) + c5 );
6061
}
6162

6263

lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/test/test.factory.js

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,64 +42,75 @@ tape( 'main export is a function', function test( t ) {
4242
});
4343

4444
tape( 'the function returns a function', function test( t ) {
45-
var cdf = factory( 2.0, 2.0 );
46-
t.strictEqual( typeof cdf, 'function', 'returns expected value' );
45+
var quantile = factory( 2.0, 2.0 );
46+
t.strictEqual( typeof quantile, 'function', 'returns expected value' );
4747
t.end();
4848
});
4949

50-
tape( 'if provided `NaN` for any parameter, the created function returns `NaN`', function test( t ) {
51-
var cdf;
50+
tape( 'if provided `NaN` for any parameter, the function returns a function which returns `NaN`', function test( t ) {
51+
var quantile;
5252
var y;
5353

54-
cdf = factory( 2.5, 3.0 );
55-
y = cdf( NaN );
54+
quantile = factory( 2.5, 3.0 );
55+
y = quantile( NaN );
5656
t.strictEqual( isnan( y ), true, 'returns expected value' );
5757

58-
cdf = factory( NaN, 3.0 );
59-
y = cdf( 2.5 );
58+
quantile = factory( NaN, 3.0 );
59+
y = quantile( 2.5 );
6060
t.strictEqual( isnan( y ), true, 'returns expected value' );
6161

62-
cdf = factory( 3.0, NaN );
63-
y = cdf( 2.5 );
62+
quantile = factory( 3.0, NaN );
63+
y = quantile( 2.5 );
6464
t.strictEqual( isnan( y ), true, 'returns expected value' );
6565

66-
cdf = factory( NaN, NaN );
67-
y = cdf( 2.5 );
66+
quantile = factory( NaN, NaN );
67+
y = quantile( 2.5 );
6868
t.strictEqual( isnan( y ), true, 'returns expected value' );
6969

70-
cdf = factory( NaN, NaN );
71-
y = cdf( NaN );
70+
quantile = factory( NaN, NaN );
71+
y = quantile( NaN );
7272
t.strictEqual( isnan( y ), true, 'returns expected value' );
7373

7474
t.end();
7575
});
7676

77-
tape( 'if provided `r < 2` or `v < 2`, the created function returns `NaN`', function test( t ) {
78-
var cdf;
77+
tape( 'if provided `r < 2` or `v < 2`, the function returns a function which returns `NaN`', function test( t ) {
78+
var quantile;
7979
var y;
8080

81-
cdf = factory( 1.5, 2.0 );
82-
y = cdf( 2.5 );
81+
quantile = factory( 1.5, 2.0 );
82+
y = quantile( 2.5 );
83+
t.strictEqual( isnan( y ), true, 'returns expected value' );
84+
85+
quantile = factory( 2.0, 1.5 );
86+
y = quantile( 2.5 );
8387
t.strictEqual( isnan( y ), true, 'returns expected value' );
8488

85-
cdf = factory( 2.0, 1.5 );
86-
y = cdf( 2.5 );
89+
quantile = factory( 1.5, 1.5 );
90+
y = quantile( 2.5 );
8791
t.strictEqual( isnan( y ), true, 'returns expected value' );
8892

89-
cdf = factory( 1.5, 1.5 );
90-
y = cdf( 2.5 );
93+
t.end();
94+
});
95+
96+
tape( 'if provided not provided a positive integer for the number of ranges, the function returns a function which returns `NaN`', function test( t ) {
97+
var quantile;
98+
var y;
99+
100+
quantile = factory( 2.5, 3.0, -1 );
101+
y = quantile( 0.5 );
91102
t.strictEqual( isnan( y ), true, 'returns expected value' );
92103

93104
t.end();
94105
});
95106

96107
tape( 'if provided valid parameters, the function returns a function which returns `+infinity` when provided `1`', function test( t ) {
97-
var cdf;
108+
var quantile;
98109
var y;
99110

100-
cdf = factory( 3.0, 2.0 );
101-
y = cdf( 1.0 );
102-
t.strictEqual( y, PINF, 'returns +infinitt' );
111+
quantile = factory( 3.0, 2.0 );
112+
y = quantile( 1.0 );
113+
t.strictEqual( y, PINF, 'returns expected value' );
103114

104115
t.end();
105116
});
@@ -129,7 +140,7 @@ tape( 'if provided valid parameters, the function returns a function which retur
129140
t.end();
130141
});
131142

132-
tape( 'the created function evaluates the quantile function (matching Python\'s implementation to the 3rd decimal place)', function test( t ) {
143+
tape( 'the function returns a function which evaluates the quantile function (matching Python\'s implementation to the 3rd decimal place)', function test( t ) {
133144
var expected;
134145
var quantile;
135146
var r;
@@ -150,7 +161,7 @@ tape( 'the created function evaluates the quantile function (matching Python\'s
150161
t.end();
151162
});
152163

153-
tape( 'the created function evaluates the quantile function (matching R\'s implementation to the 3rd decimal place)', function test( t ) {
164+
tape( 'the function returns a function which evaluates the quantile function (matching R\'s implementation to the 3rd decimal place)', function test( t ) {
154165
var expected;
155166
var quantile;
156167
var r;

lib/node_modules/@stdlib/stats/base/dists/studentized-range/quantile/test/test.quantile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ tape( 'main export is a function', function test( t ) {
4141
});
4242

4343
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
44-
var y = quantile( NaN, 3.0, 3.0 );
44+
var y;
45+
46+
y = quantile( NaN, 3.0, 3.0 );
4547
t.strictEqual( isnan( y ), true, 'returns expected value' );
48+
4649
y = quantile( 0.7, NaN, 3.0 );
4750
t.strictEqual( isnan( y ), true, 'returns expected value' );
51+
4852
y = quantile( 0.7, 3.0, NaN );
4953
t.strictEqual( isnan( y ), true, 'returns expected value' );
54+
5055
t.end();
5156
});
5257

0 commit comments

Comments
 (0)