repl.txt (3845B)
1 2 {{alias}}( N, correction, x, stride ) 3 Computes the variance of a strided array using a one-pass trial mean 4 algorithm. 5 6 The `N` and `stride` parameters determine which elements in `x` are accessed 7 at runtime. 8 9 Indexing is relative to the first index. To introduce an offset, use a typed 10 array view. 11 12 If `N <= 0`, the function returns `NaN`. 13 14 Parameters 15 ---------- 16 N: integer 17 Number of indexed elements. 18 19 correction: number 20 Degrees of freedom adjustment. Setting this parameter to a value other 21 than `0` has the effect of adjusting the divisor during the calculation 22 of the variance according to `N - c` where `c` corresponds to the 23 provided degrees of freedom adjustment. When computing the variance of a 24 population, setting this parameter to `0` is the standard choice (i.e., 25 the provided array contains data constituting an entire population). 26 When computing the unbiased sample variance, setting this parameter to 27 `1` is the standard choice (i.e., the provided array contains data 28 sampled from a larger population; this is commonly referred to as 29 Bessel's correction). 30 31 x: Array<number>|TypedArray 32 Input array. 33 34 stride: integer 35 Index increment. 36 37 Returns 38 ------- 39 out: number 40 The variance. 41 42 Examples 43 -------- 44 // Standard Usage: 45 > var x = [ 1.0, -2.0, 2.0 ]; 46 > {{alias}}( x.length, 1, x, 1 ) 47 ~4.3333 48 49 // Using `N` and `stride` parameters: 50 > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; 51 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 52 > var stride = 2; 53 > {{alias}}( N, 1, x, stride ) 54 ~4.3333 55 56 // Using view offsets: 57 > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); 58 > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); 59 > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); 60 > stride = 2; 61 > {{alias}}( N, 1, x1, stride ) 62 ~4.3333 63 64 {{alias}}.ndarray( N, correction, x, stride, offset ) 65 Computes the variance of a strided array using a one-pass trial mean 66 algorithm and alternative indexing semantics. 67 68 While typed array views mandate a view offset based on the underlying 69 buffer, the `offset` parameter supports indexing semantics based on a 70 starting index. 71 72 Parameters 73 ---------- 74 N: integer 75 Number of indexed elements. 76 77 correction: number 78 Degrees of freedom adjustment. Setting this parameter to a value other 79 than `0` has the effect of adjusting the divisor during the calculation 80 of the variance according to `N - c` where `c` corresponds to the 81 provided degrees of freedom adjustment. When computing the variance of a 82 population, setting this parameter to `0` is the standard choice (i.e., 83 the provided array contains data constituting an entire population). 84 When computing the unbiased sample variance, setting this parameter to 85 `1` is the standard choice (i.e., the provided array contains data 86 sampled from a larger population; this is commonly referred to as 87 Bessel's correction). 88 89 x: Array<number>|TypedArray 90 Input array. 91 92 stride: integer 93 Index increment. 94 95 offset: integer 96 Starting index. 97 98 Returns 99 ------- 100 out: number 101 The variance. 102 103 Examples 104 -------- 105 // Standard Usage: 106 > var x = [ 1.0, -2.0, 2.0 ]; 107 > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) 108 ~4.3333 109 110 // Using offset parameter: 111 > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; 112 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 113 > {{alias}}.ndarray( N, 1, x, 2, 1 ) 114 ~4.3333 115 116 See Also 117 -------- 118