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
@@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note,
98
98
var dnanvarianceyc =require( '@stdlib/stats/base/dnanvarianceyc' );
99
99
```
100
100
101
-
#### dnanvarianceyc( N, correction, x, stride )
101
+
#### dnanvarianceyc( N, correction, x, strideX )
102
102
103
103
Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using a one-pass algorithm proposed by Youngs and Cramer.
104
104
@@ -116,18 +116,16 @@ The function has the following parameters:
116
116
-**N**: number of indexed elements.
117
117
-**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 [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] 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 unbiased sample [variance][variance], 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).
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`,
121
+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`,
var floor =require( '@stdlib/math/base/special/floor' );
141
138
142
139
var x0 =newFloat64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
143
140
var x1 =newFloat64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
144
141
145
-
varN=floor( x0.length/2 );
146
-
147
-
var v =dnanvarianceyc( N, 1, x1, 2 );
142
+
var v =dnanvarianceyc( 4, 1, x1, 2 );
148
143
// returns 6.25
149
144
```
150
145
151
-
#### dnanvarianceyc.ndarray( N, correction, x, stride, offset )
146
+
#### dnanvarianceyc.ndarray( N, correction, x, strideX, offsetX )
152
147
153
148
Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics.
var x =newFloat64Array( [ 1.0, -2.0, NaN, 2.0 ] );
153
+
var x =newFloat64Array( [ 1.0, -2.0, 2.0 ] );
159
154
160
155
var v =dnanvarianceyc.ndarray( x.length, 1, x, 1, 0 );
161
156
// returns ~4.33333
162
157
```
163
158
164
159
The function has the following additional parameters:
165
160
166
-
-**offset**: starting index for `x`.
161
+
-**offsetX**: starting index for `x`.
167
162
168
-
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 [variance][variance] for every other value in `x` starting from the second value
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 [variance][variance] for every other element in `x` starting from the second element
var dnanvarianceyc =require( '@stdlib/stats/base/dnanvarianceyc' );
207
200
208
-
var x;
209
-
var i;
210
-
211
-
x =newFloat64Array( 10 );
212
-
for ( i =0; i <x.length; i++ ) {
213
-
x[ i ] =round( (randu()*100.0) -50.0 );
201
+
functionrand() {
202
+
if ( bernoulli( 0.8 ) <1 ) {
203
+
returnNaN;
204
+
}
205
+
returnuniform( -50.0, 50.0 );
214
206
}
215
-
console.log( x );
207
+
208
+
var x =filledarrayBy( 10, 'float64', rand );
216
209
217
210
var v =dnanvarianceyc( x.length, 1, x, 1 );
218
211
console.log( v );
@@ -222,6 +215,125 @@ console.log( v );
222
215
223
216
<!-- /.examples -->
224
217
218
+
<!-- C interface documentation. -->
219
+
220
+
* * *
221
+
222
+
<sectionclass="c">
223
+
224
+
## C APIs
225
+
226
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
227
+
228
+
<sectionclass="intro">
229
+
230
+
</section>
231
+
232
+
<!-- /.intro -->
233
+
234
+
<!-- C usage documentation. -->
235
+
236
+
<sectionclass="usage">
237
+
238
+
### Usage
239
+
240
+
```c
241
+
#include"stdlib/stats/base/dnanvarianceyc.h"
242
+
```
243
+
244
+
#### stdlib_strided_dnanvarianceyc( N, correction, \*X, strideX )
245
+
246
+
Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using a one-pass algorithm proposed by Youngs and Cramer.
247
+
248
+
```c
249
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
250
+
251
+
double v = stdlib_strided_dnanvarianceyc( 4, 1.0, x, 1 );
252
+
// returns ~4.3333
253
+
```
254
+
255
+
The function accepts the following arguments:
256
+
257
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
258
+
- **correction**: `[in] double` 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 [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] 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 unbiased sample [variance][variance], 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).
259
+
- **X**: `[in] double*` input array.
260
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
#### stdlib_strided_dnanvarianceyc_ndarray( N, correction, \*X, strideX, offsetX )
267
+
268
+
Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics.
269
+
270
+
```c
271
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
272
+
273
+
double v = stdlib_strided_dnanvarianceyc_ndarray( 4, 1.0, x, 1, 0 );
274
+
// returns ~4.3333
275
+
```
276
+
277
+
The function accepts the following arguments:
278
+
279
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
280
+
- **correction**: `[in] double` 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 [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] 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 unbiased sample [variance][variance], 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).
281
+
- **X**: `[in] double*` input array.
282
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
283
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
0 commit comments