README.md (7940B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # dsemyc 22 23 > Calculate the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. 24 25 <section class="intro"> 26 27 The [standard error of the mean][standard-error] of a finite size sample of size `n` is given by 28 29 <!-- <equation class="equation" label="eq:standard_error_of_the_mean" align="center" raw="\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{n}}" alt="Equation for the standard error of the mean."> --> 30 31 <div class="equation" align="center" data-raw-text="\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{n}}" data-equation="eq:standard_error_of_the_mean"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@e541455edad5251f526b8cc13e60c7d00b4b6767/lib/node_modules/@stdlib/stats/base/dsemyc/docs/img/equation_standard_error_of_the_mean.svg" alt="Equation for the standard error of the mean."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `σ` is the population [standard deviation][standard-deviation]. 39 40 Often in the analysis of data, the true population [standard deviation][standard-deviation] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. In this scenario, one must use a sample [standard deviation][standard-deviation] to compute an estimate for the [standard error of the mean][standard-error] 41 42 <!-- <equation class="equation" label="eq:standard_error_of_the_mean_estimate" align="center" raw="\sigma_{\bar{x}} \approx \frac{s}{\sqrt{n}}" alt="Equation for estimating the standard error of the mean."> --> 43 44 <div class="equation" align="center" data-raw-text="\sigma_{\bar{x}} \approx \frac{s}{\sqrt{n}}" data-equation="eq:standard_error_of_the_mean_estimate"> 45 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@e541455edad5251f526b8cc13e60c7d00b4b6767/lib/node_modules/@stdlib/stats/base/dsemyc/docs/img/equation_standard_error_of_the_mean_estimate.svg" alt="Equation for estimating the standard error of the mean."> 46 <br> 47 </div> 48 49 <!-- </equation> --> 50 51 where `s` is the sample [standard deviation][standard-deviation]. 52 53 </section> 54 55 <!-- /.intro --> 56 57 <section class="usage"> 58 59 ## Usage 60 61 ```javascript 62 var dsemyc = require( '@stdlib/stats/base/dsemyc' ); 63 ``` 64 65 #### dsemyc( N, correction, x, stride ) 66 67 Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array `x` using a one-pass algorithm proposed by Youngs and Cramer. 68 69 ```javascript 70 var Float64Array = require( '@stdlib/array/float64' ); 71 72 var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); 73 var N = x.length; 74 75 var v = dsemyc( N, 1, x, 1 ); 76 // returns ~1.20185 77 ``` 78 79 The function has the following parameters: 80 81 - **N**: number of indexed elements. 82 - **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). 83 - **x**: input [`Float64Array`][@stdlib/array/float64]. 84 - **stride**: index increment for `x`. 85 86 The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [standard error of the mean][standard-error] of every other element in `x`, 87 88 ```javascript 89 var Float64Array = require( '@stdlib/array/float64' ); 90 var floor = require( '@stdlib/math/base/special/floor' ); 91 92 var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); 93 var N = floor( x.length / 2 ); 94 95 var v = dsemyc( N, 1, x, 2 ); 96 // returns 1.25 97 ``` 98 99 Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. 100 101 <!-- eslint-disable stdlib/capitalized-comments --> 102 103 ```javascript 104 var Float64Array = require( '@stdlib/array/float64' ); 105 var floor = require( '@stdlib/math/base/special/floor' ); 106 107 var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); 108 var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element 109 110 var N = floor( x0.length / 2 ); 111 112 var v = dsemyc( N, 1, x1, 2 ); 113 // returns 1.25 114 ``` 115 116 #### dsemyc.ndarray( N, correction, x, stride, offset ) 117 118 Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. 119 120 ```javascript 121 var Float64Array = require( '@stdlib/array/float64' ); 122 123 var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); 124 var N = x.length; 125 126 var v = dsemyc.ndarray( N, 1, x, 1, 0 ); 127 // returns ~1.20185 128 ``` 129 130 The function has the following additional parameters: 131 132 - **offset**: starting index for `x`. 133 134 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 error of the mean][standard-error] for every other value in `x` starting from the second value 135 136 ```javascript 137 var Float64Array = require( '@stdlib/array/float64' ); 138 var floor = require( '@stdlib/math/base/special/floor' ); 139 140 var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); 141 var N = floor( x.length / 2 ); 142 143 var v = dsemyc.ndarray( N, 1, x, 2, 1 ); 144 // returns 1.25 145 ``` 146 147 </section> 148 149 <!-- /.usage --> 150 151 <section class="notes"> 152 153 ## Notes 154 155 - If `N <= 0`, both functions return `NaN`. 156 - If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. 157 158 </section> 159 160 <!-- /.notes --> 161 162 <section class="examples"> 163 164 ## Examples 165 166 <!-- eslint no-undef: "error" --> 167 168 ```javascript 169 var randu = require( '@stdlib/random/base/randu' ); 170 var round = require( '@stdlib/math/base/special/round' ); 171 var Float64Array = require( '@stdlib/array/float64' ); 172 var dsemyc = require( '@stdlib/stats/base/dsemyc' ); 173 174 var x; 175 var i; 176 177 x = new Float64Array( 10 ); 178 for ( i = 0; i < x.length; i++ ) { 179 x[ i ] = round( (randu()*100.0) - 50.0 ); 180 } 181 console.log( x ); 182 183 var v = dsemyc( x.length, 1, x, 1 ); 184 console.log( v ); 185 ``` 186 187 </section> 188 189 <!-- /.examples --> 190 191 * * * 192 193 <section class="references"> 194 195 ## References 196 197 - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826][@youngs:1971a]. 198 199 </section> 200 201 <!-- /.references --> 202 203 <section class="links"> 204 205 [standard-error]: https://en.wikipedia.org/wiki/Standard_error 206 207 [standard-deviation]: https://en.wikipedia.org/wiki/Standard_deviation 208 209 [@stdlib/array/float64]: https://www.npmjs.com/package/@stdlib/array-float64 210 211 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray 212 213 [@youngs:1971a]: https://doi.org/10.1080/00401706.1971.10488826 214 215 </section> 216 217 <!-- /.links -->