Skip to content

Commit 8a286ea

Browse files
committed
[Fixed Issues]
1 parent e658d94 commit 8a286ea

File tree

8 files changed

+32
-48
lines changed

8 files changed

+32
-48
lines changed

lib/node_modules/@stdlib/stats/incr/nanpcorr2/README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ var accumulator = incrnanpcorr2();
9494
var r2 = accumulator( 2.0, 1.0 );
9595
// returns 0.0
9696

97-
r2 = accumulator( 1.0, NaN );
98-
// returns 0.0
97+
r2 = accumulator( 1.0, 90 );
98+
// returns 1.0
9999

100100
r2 = accumulator( NaN, NaN );
101-
// returns ~0.0
101+
// returns ~1.0
102102

103103
r2 = accumulator( 8.0, NaN );
104-
// returns ~0.0
104+
// returns ~1.0
105105

106106
r2 = accumulator();
107-
// returns ~0.0
107+
// returns ~1.0
108108
```
109109

110110
</section>
@@ -135,6 +135,7 @@ var incrnanpcorr2 = require( '@stdlib/stats/incr/nanpcorr2' );
135135
var accumulator;
136136
var x;
137137
var y;
138+
var r2;
138139
var i;
139140

140141
// Initialize an accumulator:
@@ -143,13 +144,10 @@ accumulator = incrnanpcorr2();
143144
// For each simulated datum, update the squared sample correlation coefficient...
144145
console.log( '\nx\ty\tr^2\n' );
145146
for ( i = 0; i < 100; i++ ) {
146-
x = randu() < 0.9 ? randu() * 100.0:NaN;
147-
y = randu() < 0.9 ? randu() * 100.0:NaN;
148-
r2 = accumulator( x, y );
149-
console.log( '%d\t%d\t%d',
150-
isNaN(x) ? 'NaN' : x.toFixed( 4 ),
151-
isNaN(y) ? 'NaN': y.toFixed( 4 ),
152-
r2 === null ? 'null' : r2.toFixed( 4 ) );
147+
x = (randu() < 0.9) ? (randu() * 100.0) : NaN;
148+
y = (randu() < 0.9) ? (randu() * 100.0) : NaN;
149+
r2 = accumulator( x, y );
150+
console.log('%s\t%s\t%s', ( isNaN( x ) ) ? 'NaN' : x.toFixed( 4 ), (isNaN(y)) ? 'NaN' : y.toFixed( 4 ), ( r2 === null ) ? 'null' : r2.toFixed( 4 ));
153151
}
154152
console.log( accumulator() );
155153
```

lib/node_modules/@stdlib/stats/incr/nanpcorr2/docs/repl.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11

22
{{alias}}( [mx, my] )
33
Returns an accumulator function which incrementally computes the squared
4-
sample Pearson product-moment correlation coefficient.
4+
sample Pearson product-moment correlation coefficient ignoring NaN values.
55

66
If provided values, the accumulator function returns an updated accumulated
77
value. If not provided values, the accumulator function returns the current
88
accumulated value.
99

10-
11-
If provided `NaN` or a value which, when used in computations
12-
gets ignored.
1310
Parameters
1411
----------
1512
mx: number (optional)

lib/node_modules/@stdlib/stats/incr/nanpcorr2/docs/types/index.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@
2323
/**
2424
* If provided arguments, returns an updated squared sample correlation coefficient.
2525
*
26-
* ## Notes
27-
*
28-
* - If provided `NaN` it ignores itand return the previous accumulated value.
29-
*
3026
* @param x - value
3127
* @param y - value
3228
* @returns updated squared sample correlation coefficient
3329
*/
3430
type accumulator = ( x?: number, y?: number ) => number | null;
3531

3632
/**
37-
* Returns an accumulator function which incrementally computes a squared sample Pearson product-moment correlation coefficient,ignoring NaN Values.
33+
* Returns an accumulator function which incrementally computes a squared sample Pearson product-moment correlation coefficient, ignoring NaN Values.
3834
*
3935
* @param meanx - mean value
4036
* @param meany - mean value
@@ -53,7 +49,7 @@ declare function incrnanpcorr2( meanx: number, meany: number ): accumulator;
5349
* @example
5450
* var accumulator = incrnanpcorr2();
5551
*
56-
var r2 = accumulator();
52+
* var r2 = accumulator();
5753
* // returns null
5854
*
5955
* r2 = accumulator( 2.0, 1.0 );

lib/node_modules/@stdlib/stats/incr/nanpcorr2/examples/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ accumulator = incrnanpcorr2();
3333
// For each simulated datum, update the squared sample Pearson correlation coefficient...
3434
console.log( '\nx\ty\tr^2\n' );
3535
for ( i = 0; i < 100; i++ ) {
36-
x = randu() < 0.9 ? randu() * 100.0:NaN;
37-
y = randu() < 0.9 ? randu() * 100.0:NaN;
36+
x = ( randu() < 0.9 ) ? ( randu() * 100.0 ) : NaN;
37+
y = ( randu() < 0.9 ) ? ( randu() * 100.0 ) : NaN;
3838
r2 = accumulator( x, y );
39-
console.log( '%d\t%d\t%d',
40-
isNaN(x) ? 'NaN' : x.toFixed( 4 ),
41-
isNaN(y) ? 'NaN': y.toFixed( 4 ),
42-
r2 === null ? 'null' : r2.toFixed( 4 ) );
39+
console.log( '%d\t%d\t%d', ( isNaN( x ) ) ? 'NaN' : x.toFixed( 4 ), ( isNaN( y ) ) ? 'NaN' : y.toFixed( 4 ), ( r2 === null ) ? 'null' : r2.toFixed( 4 ) );
4340
}
4441
console.log( '\nFinal r^2: %d\n', accumulator());

lib/node_modules/@stdlib/stats/incr/nanpcorr2/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
// MODULES //
5151

52-
var incrnanpcorr2 = require( '@stdlib/stats/incr/nanpcorr2/lib/main.js' );
52+
var incrnanpcorr2 = require( './main.js' );
5353

5454

5555
// EXPORTS //

lib/node_modules/@stdlib/stats/incr/nanpcorr2/lib/main.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'use strict';
2020

2121
// MODULES //
22-
var isNaN = require( '@stdlib/math/base/assert/is-nan' );
22+
23+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2324
var incrpcorr2 = require( '@stdlib/stats/incr/pcorr2' );
2425

2526

@@ -60,10 +61,10 @@ var incrpcorr2 = require( '@stdlib/stats/incr/pcorr2' );
6061
*/
6162
function incrnanpcorr2( meanx, meany ) {
6263
var pcorr2;
63-
if(arguments.length === 0) {
64+
if ( arguments.length === 0 ) {
6465
pcorr2 = incrpcorr2();
6566
}
66-
else{
67+
else {
6768
pcorr2 = incrpcorr2(meanx, meany);
6869
}
6970
return accumulator;
@@ -76,14 +77,14 @@ function incrnanpcorr2( meanx, meany ) {
7677
* @returns {(number|null)} squared sample correlation coefficient or null
7778
*/
7879
function accumulator( x, y ) {
79-
if (arguments.length === 0 ) {
80+
if ( arguments.length === 0 ) {
8081
return pcorr2();
8182
}
82-
if(isNaN(x) || isNaN(y)){
83+
if ( isnan( x ) || isnan( y ) ) {
8384
return pcorr2();
8485
}
8586
return pcorr2( x, y );
86-
}
87+
}
8788
}
8889

8990

lib/node_modules/@stdlib/stats/incr/nanpcorr2/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@stdlib/stats/incr/pcorr2",
2+
"name": "@stdlib/stats/incr/nanpcorr2",
33
"version": "0.0.0",
4-
"description": "Compute a squared sample Pearson product-moment correlation coefficient.",
4+
"description": "Compute a squared sample Pearson product-moment correlation coefficient, ignoring NaN values.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",

lib/node_modules/@stdlib/stats/incr/nanpcorr2/test/test.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ tape( 'the accumulated result ignores NaN values', function test( t ) {
279279
y = [ 1.5, 2.0, NaN, 4.0, 5.0, NaN ];
280280

281281
// Only pairs where neither x nor y is NaN should be considered
282+
282283
// Effective data: [ [2.0, 1.5], [4.0, 4.0] ]
283284
expected = 1.0; // Perfect correlation with only these two points
284285

@@ -287,35 +288,29 @@ tape( 'the accumulated result ignores NaN values', function test( t ) {
287288
for ( i = 0; i < x.length; i++ ) {
288289
acc( x[ i ], y[ i ] );
289290
}
290-
291291
actual = acc();
292-
293292
if ( actual === expected ) {
294293
t.strictEqual( actual, expected, 'returns expected result' );
295294
} else {
296295
delta = abs( expected - actual );
297296
tol = 7.0 * EPS * abs( expected );
298297
t.equal( delta <= tol, true, 'expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' );
299298
}
300-
301299
t.end();
302300
});
303301

304302
tape( 'the accumulated result ignores NaN values (known means)', function test( t ) {
305303
var acc;
306-
304+
307305
// Create accumulator with known means
308306
acc = incrnanpcorr2( 3.0, 2.0 );
309-
310-
// Add data with some NaN values
307+
311308
acc( 2.0, 1.0 );
312-
acc( NaN, 3.0 ); // Should ignore
313-
acc( 4.0, NaN ); // Should ignore
309+
acc( NaN, 3.0 );
310+
acc( 4.0, NaN );
314311
acc( 4.0, 3.0 );
315-
312+
316313
// NaN values should be ignored in the calculation
317314
t.false( isnan(acc()), 'does not return NaN' );
318-
319315
t.end();
320316
});
321-

0 commit comments

Comments
 (0)