You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js
+14-11Lines changed: 14 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -131,7 +131,6 @@ function incrnanmvariance( W, mean ) {
131
131
returnM2/n;
132
132
}
133
133
134
-
135
134
// Update the index for managing the circular buffer:
136
135
i=(i+1)%W;
137
136
@@ -178,7 +177,7 @@ function incrnanmvariance( W, mean ) {
178
177
buf[i]=x;
179
178
returnM2/n;
180
179
}
181
-
180
+
182
181
/**
183
182
* If provided a value, the accumulator function returns an updated unbiased sample variance, ignoring NaN values. If not provided a value, the accumulator function returns the current unbiased sample variance.
184
183
*
@@ -199,7 +198,13 @@ function incrnanmvariance( W, mean ) {
199
198
200
199
// If incoming value is NaN, ignore it:
201
200
if(isnan(x)){
202
-
return(N===0) ? null : (N<W) ? M2/N : M2/W;
201
+
if(N===0){
202
+
returnnull;
203
+
}
204
+
if(N<W){
205
+
returnM2/N;
206
+
}
207
+
returnM2/W;
203
208
}
204
209
205
210
// Update the index for managing the circular buffer:
@@ -219,7 +224,7 @@ function incrnanmvariance( W, mean ) {
219
224
}
220
225
221
226
// Case: outgoing value is NaN, which we need to simply replace without affecting the variance
222
-
elseif(isnan(buf[i])){
227
+
if(isnan(buf[i])){
223
228
buf[i]=x;
224
229
225
230
// Add the squared difference between the new value and mean
@@ -228,15 +233,13 @@ function incrnanmvariance( W, mean ) {
228
233
}
229
234
230
235
// Case: standard update when neither incoming nor outgoing values are NaN
0 commit comments