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