README.md (5792B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 # incrskewness 22 23 > Compute a [corrected sample skewness][sample-skewness] incrementally. 24 25 <section class="intro"> 26 27 The [skewness][sample-skewness] for a random variable `X` is defined as 28 29 <!-- <equation class="equation" label="eq:skewness" align="center" raw="\operatorname{Skewness}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^3 \biggr]" alt="Equation for skewness."> --> 30 31 <div class="equation" align="center" data-raw-text="\operatorname{Skewness}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^3 \biggr]" data-equation="eq:skewness"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@49d8cabda84033d55d7b8069f19ee3dd8b8d1496/lib/node_modules/@stdlib/stats/incr/skewness/docs/img/equation_skewness.svg" alt="Equation for skewness."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 For a sample of `n` values, the [sample skewness][sample-skewness] is 39 40 <!-- <equation class="equation" label="eq:sample_skewness" align="center" raw="b_1 = \frac{m_3}{s^3} = \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^3}{\biggl( \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 \biggr)^{3/2}}" alt="Equation for the sample skewness."> --> 41 42 <div class="equation" align="center" data-raw-text="b_1 = \frac{m_3}{s^3} = \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^3}{\biggl( \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 \biggr)^{3/2}}" data-equation="eq:sample_skewness"> 43 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@49d8cabda84033d55d7b8069f19ee3dd8b8d1496/lib/node_modules/@stdlib/stats/incr/skewness/docs/img/equation_sample_skewness.svg" alt="Equation for the sample skewness."> 44 <br> 45 </div> 46 47 <!-- </equation> --> 48 49 where `m_3` is the sample third central moment and `s` is the sample standard deviation. 50 51 An alternative definition for the [sample skewness][sample-skewness] which includes an adjustment factor (and is the implemented definition) is 52 53 <!-- <equation class="equation" label="eq:adjusted_sample_skewness" align="center" raw="G_1 = \frac{n^2}{(n-1)(n-2)} \frac{m_3}{s^3} = \frac{\sqrt{n(n-1)}}{n-2} \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^3}{\biggl( \frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 \biggr)^{3/2}}" alt="Equation for the adjusted sample skewness."> --> 54 55 <div class="equation" align="center" data-raw-text="G_1 = \frac{n^2}{(n-1)(n-2)} \frac{m_3}{s^3} = \frac{\sqrt{n(n-1)}}{n-2} \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^3}{\biggl( \frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 \biggr)^{3/2}}" data-equation="eq:adjusted_sample_skewness"> 56 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@49d8cabda84033d55d7b8069f19ee3dd8b8d1496/lib/node_modules/@stdlib/stats/incr/skewness/docs/img/equation_adjusted_sample_skewness.svg" alt="Equation for the adjusted sample skewness."> 57 <br> 58 </div> 59 60 <!-- </equation> --> 61 62 </section> 63 64 <!-- /.intro --> 65 66 <section class="usage"> 67 68 ## Usage 69 70 ```javascript 71 var incrskewness = require( '@stdlib/stats/incr/skewness' ); 72 ``` 73 74 #### incrskewness() 75 76 Returns an accumulator `function` which incrementally computes a [corrected sample skewness][sample-skewness]. 77 78 ```javascript 79 var accumulator = incrskewness(); 80 ``` 81 82 #### accumulator( \[x] ) 83 84 If provided an input value `x`, the accumulator function returns an updated [corrected sample skewness][sample-skewness]. If not provided an input value `x`, the accumulator function returns the current [corrected sample skewness][sample-skewness]. 85 86 ```javascript 87 var accumulator = incrskewness(); 88 89 var skewness = accumulator(); 90 // returns null 91 92 skewness = accumulator( 2.0 ); 93 // returns null 94 95 skewness = accumulator( -5.0 ); 96 // returns null 97 98 skewness = accumulator( -10.0 ); 99 // returns ~0.492 100 101 skewness = accumulator(); 102 // returns ~0.492 103 ``` 104 105 </section> 106 107 <!-- /.usage --> 108 109 <section class="notes"> 110 111 ## Notes 112 113 - Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for **all** future invocations. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. 114 115 </section> 116 117 <!-- /.notes --> 118 119 <section class="examples"> 120 121 ## Examples 122 123 <!-- eslint no-undef: "error" --> 124 125 ```javascript 126 var randu = require( '@stdlib/random/base/randu' ); 127 var incrskewness = require( '@stdlib/stats/incr/skewness' ); 128 129 var accumulator; 130 var v; 131 var i; 132 133 // Initialize an accumulator: 134 accumulator = incrskewness(); 135 136 // For each simulated datum, update the corrected sample skewness... 137 for ( i = 0; i < 100; i++ ) { 138 v = randu() * 100.0; 139 accumulator( v ); 140 } 141 console.log( accumulator() ); 142 ``` 143 144 </section> 145 146 <!-- /.examples --> 147 148 * * * 149 150 <section class="references"> 151 152 ## References 153 154 - Joanes, D. N., and C. A. Gill. 1998. "Comparing measures of sample skewness and kurtosis." _Journal of the Royal Statistical Society: Series D (The Statistician)_ 47 (1). Blackwell Publishers Ltd: 183–89. doi:[10.1111/1467-9884.00122][@joanes:1998]. 155 156 </section> 157 158 <!-- /.references --> 159 160 <section class="links"> 161 162 [sample-skewness]: https://en.wikipedia.org/wiki/Skewness 163 164 [@joanes:1998]: http://onlinelibrary.wiley.com/doi/10.1111/1467-9884.00122/ 165 166 </section> 167 168 <!-- /.links -->