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/base/nanstdevtk/README.md
+25-30Lines changed: 25 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -98,9 +98,9 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note,
98
98
var nanstdevtk =require( '@stdlib/stats/base/nanstdevtk' );
99
99
```
100
100
101
-
#### nanstdevtk( N, correction, x, stride )
101
+
#### nanstdevtk( N, correction, x, strideX )
102
102
103
-
Computes the [standard deviation][standard-deviation] of a strided array `x`ignoring `NaN` values and using a one-pass textbook algorithm.
103
+
Computes the [standard deviation][standard-deviation] of a strided array ignoring `NaN` values and using a one-pass textbook algorithm.
104
104
105
105
```javascript
106
106
var x = [ 1.0, -2.0, NaN, 2.0 ];
@@ -114,38 +114,32 @@ The function has the following parameters:
114
114
-**N**: number of indexed elements.
115
115
-**correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample [standard deviation][standard-deviation], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
116
116
-**x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
117
-
-**stride**: index increment for `x`.
117
+
-**strideX**: stride length for `x`.
118
118
119
119
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [standard deviation][standard-deviation] of every other element in `x`,
120
120
121
121
```javascript
122
-
var floor =require( '@stdlib/math/base/special/floor' );
123
-
124
122
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ];
125
-
varN=floor( x.length/2 );
126
123
127
-
var v =nanstdevtk( N, 1, x, 2 );
124
+
var v =nanstdevtk( 5, 1, x, 2 );
128
125
// returns 2.5
129
126
```
130
127
131
128
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
var floor =require( '@stdlib/math/base/special/floor' );
138
134
139
-
var x0 =newFloat64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
135
+
var x0 =newFloat64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
140
136
var x1 =newFloat64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
141
137
142
-
varN=floor( x0.length/2 );
143
-
144
-
var v =nanstdevtk( N, 1, x1, 2 );
138
+
var v =nanstdevtk( 5, 1, x1, 2 );
145
139
// returns 2.5
146
140
```
147
141
148
-
#### nanstdevtk.ndarray( N, correction, x, stride, offset )
142
+
#### nanstdevtk.ndarray( N, correction, x, strideX, offsetX )
149
143
150
144
Computes the [standard deviation][standard-deviation] of a strided array ignoring `NaN` values and using a one-pass textbook algorithm and alternative indexing semantics.
151
145
@@ -158,17 +152,14 @@ var v = nanstdevtk.ndarray( x.length, 1, x, 1, 0 );
158
152
159
153
The function has the following additional parameters:
160
154
161
-
-**offset**: starting index for `x`.
155
+
-**offsetX**: starting index for `x`.
162
156
163
-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [standard deviation][standard-deviation] for every other value in `x` starting from the second value
157
+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [standard deviation][standard-deviation] for every other element in `x` starting from the second element
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
169
-
varN=floor( x.length/2 );
170
-
171
-
var v =nanstdevtk.ndarray( N, 1, x, 2, 1 );
162
+
var v =nanstdevtk.ndarray( 5, 1, x, 2, 1 );
172
163
// returns 2.5
173
164
```
174
165
@@ -183,6 +174,7 @@ var v = nanstdevtk.ndarray( N, 1, x, 2, 1 );
183
174
- If `N <= 0`, both functions return `NaN`.
184
175
- If `n - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements), both functions return `NaN`.
185
176
- Some caution should be exercised when using the one-pass textbook algorithm. Literature overwhelmingly discourages the algorithm's use for two reasons: 1) the lack of safeguards against underflow and overflow and 2) the risk of catastrophic cancellation when subtracting the two sums if the sums are large and the variance small. These concerns have merit; however, the one-pass textbook algorithm should not be dismissed outright. For data distributions with a moderately large standard deviation to mean ratio (i.e., **coefficient of variation**), the one-pass textbook algorithm may be acceptable, especially when performance is paramount and some precision loss is acceptable (including a risk of computing a negative variance due to floating-point rounding errors!). In short, no single "best" algorithm for computing the standard deviation exists. The "best" algorithm depends on the underlying data distribution, your performance requirements, and your minimum precision requirements. When evaluating which algorithm to use, consider the relative pros and cons, and choose the algorithm which best serves your needs.
177
+
- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).
186
178
- Depending on the environment, the typed versions ([`dnanstdevtk`][@stdlib/stats/strided/dnanstdevtk], [`snanstdevtk`][@stdlib/stats/base/snanstdevtk], etc.) are likely to be significantly more performant.
187
179
188
180
</section>
@@ -196,18 +188,19 @@ var v = nanstdevtk.ndarray( N, 1, x, 2, 1 );
0 commit comments