README.md (4014B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2019 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 # iterstdev 22 23 > Compute the [corrected sample standard deviation][sample-stdev] over all [iterated][mdn-iterator-protocol] values. 24 25 <section class="intro"> 26 27 The [corrected sample standard deviation][sample-stdev] is defined as 28 29 <!-- <equation class="equation" label="eq:corrected_sample_standard_deviation" align="center" raw="s = \sqrt{\frac{1}{n-1} \sum_{i=0}^{n-1} ( x_i - \bar{x} )^2}" alt="Equation for the corrected sample standard deviation."> --> 30 31 <div class="equation" align="center" data-raw-text="s = \sqrt{\frac{1}{n-1} \sum_{i=0}^{n-1} ( x_i - \bar{x} )^2}" data-equation="eq:corrected_sample_standard_deviation"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@03e3798c09b1c8873fbc09a227eb8c7e88d0b985/lib/node_modules/@stdlib/stats/iter/stdev/docs/img/equation_corrected_sample_standard_deviation.svg" alt="Equation for the corrected sample standard deviation."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 </section> 39 40 <!-- /.intro --> 41 42 <!-- Package usage documentation. --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var iterstdev = require( '@stdlib/stats/iter/stdev' ); 50 ``` 51 52 #### iterstdev( iterator\[, mean] ) 53 54 Computes the [corrected sample standard deviation][sample-stdev] over all [iterated][mdn-iterator-protocol] values. 55 56 ```javascript 57 var array2iterator = require( '@stdlib/array/to-iterator' ); 58 59 var arr = array2iterator( [ 2.0, 1.0, 3.0 ] ); 60 61 var s = iterstdev( arr ); 62 // returns 1.0 63 ``` 64 65 If the mean is already known, provide a `mean` argument. 66 67 ```javascript 68 var array2iterator = require( '@stdlib/array/to-iterator' ); 69 70 var arr = array2iterator( [ 2.0, 1.0, 3.0 ] ); 71 72 var s = iterstdev( arr, 2.0 ); 73 // returns ~0.82 74 ``` 75 76 </section> 77 78 <!-- /.usage --> 79 80 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 81 82 <section class="notes"> 83 84 ## Notes 85 86 - If an iterated value is non-numeric (including `NaN`), the returned [`iterator`][mdn-iterator-protocol] returns `NaN`. If non-numeric iterated values are possible, you are advised to provide an [`iterator`][mdn-iterator-protocol] which type checks and handles non-numeric values accordingly. 87 88 </section> 89 90 <!-- /.notes --> 91 92 <!-- Package usage examples. --> 93 94 <section class="examples"> 95 96 ## Examples 97 98 <!-- eslint no-undef: "error" --> 99 100 ```javascript 101 var runif = require( '@stdlib/random/iter/uniform' ); 102 var iterstdev = require( '@stdlib/stats/iter/stdev' ); 103 104 // Create an iterator for generating uniformly distributed pseudorandom numbers: 105 var rand = runif( -10.0, 10.0, { 106 'seed': 1234, 107 'iter': 100 108 }); 109 110 // Compute the corrected sample standard deviation: 111 var s = iterstdev( rand ); 112 // returns <number> 113 114 console.log( 'stdev: %d.', s ); 115 ``` 116 117 </section> 118 119 <!-- /.examples --> 120 121 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 122 123 <section class="references"> 124 125 </section> 126 127 <!-- /.references --> 128 129 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 130 131 <section class="links"> 132 133 [sample-stdev]: https://en.wikipedia.org/wiki/Standard_deviation 134 135 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol 136 137 </section> 138 139 <!-- /.links -->