README.md (6006B)
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 # incrkurtosis 22 23 > Compute a [corrected sample excess kurtosis][sample-excess-kurtosis] incrementally. 24 25 <section class="intro"> 26 27 The [kurtosis][sample-excess-kurtosis] for a random variable `X` is defined as 28 29 <!-- <equation class="equation" label="eq:kurtosis" align="center" raw="\operatorname{Kurtosis}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^4 \biggr]" alt="Equation for the kurtosis."> --> 30 31 <div class="equation" align="center" data-raw-text="\operatorname{Kurtosis}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^4 \biggr]" data-equation="eq:kurtosis"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@49d8cabda84033d55d7b8069f19ee3dd8b8d1496/lib/node_modules/@stdlib/stats/incr/kurtosis/docs/img/equation_kurtosis.svg" alt="Equation for the kurtosis."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 Using a univariate normal distribution as the standard of comparison, the [excess kurtosis][sample-excess-kurtosis] is the kurtosis minus `3`. 39 40 For a sample of `n` values, the [sample excess kurtosis][sample-excess-kurtosis] is 41 42 <!-- <equation class="equation" label="eq:sample_excess_kurtosis" align="center" raw="g_2 = \frac{m_4}{m_2^2} - 3 = \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^4}{\biggl(\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^2\biggr)^2}" alt="Equation for the sample excess kurtosis."> --> 43 44 <div class="equation" align="center" data-raw-text="g_2 = \frac{m_4}{m_2^2} - 3 = \frac{\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^4}{\biggl(\frac{1}{n} \sum_{i=0}^{n-1} (x_i - \bar{x})^2\biggr)^2}" data-equation="eq:sample_excess_kurtosis"> 45 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@49d8cabda84033d55d7b8069f19ee3dd8b8d1496/lib/node_modules/@stdlib/stats/incr/kurtosis/docs/img/equation_sample_excess_kurtosis.svg" alt="Equation for the sample excess kurtosis."> 46 <br> 47 </div> 48 49 <!-- </equation> --> 50 51 where `m_4` is the sample fourth central moment and `m_2` is the sample second central moment. 52 53 The previous equation is, however, a biased estimator of the population excess kurtosis. An alternative estimator which is unbiased under normality is 54 55 <!-- <equation class="equation" label="eq:corrected_sample_excess_kurtosis" align="center" raw="G_2 = \frac{(n+1)n}{(n-1)(n-2)(n-3)} \frac{\sum_{i=0}^{n-1} (x_i - \bar{x})^4}{\biggl(\sum_{i=0}^{n-1} (x_i - \bar{x})^2\biggr)^2} - 3 \frac{(n-1)^2}{(n-2)(n-3)}" alt="Equation for the corrected sample excess kurtosis."> --> 56 57 <div class="equation" align="center" data-raw-text="G_2 = \frac{(n+1)n}{(n-1)(n-2)(n-3)} \frac{\sum_{i=0}^{n-1} (x_i - \bar{x})^4}{\biggl(\sum_{i=0}^{n-1} (x_i - \bar{x})^2\biggr)^2} - 3 \frac{(n-1)^2}{(n-2)(n-3)}" data-equation="eq:corrected_sample_excess_kurtosis"> 58 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@49d8cabda84033d55d7b8069f19ee3dd8b8d1496/lib/node_modules/@stdlib/stats/incr/kurtosis/docs/img/equation_corrected_sample_excess_kurtosis.svg" alt="Equation for the corrected sample excess kurtosis."> 59 <br> 60 </div> 61 62 <!-- </equation> --> 63 64 </section> 65 66 <!-- /.intro --> 67 68 <section class="usage"> 69 70 ## Usage 71 72 ```javascript 73 var incrkurtosis = require( '@stdlib/stats/incr/kurtosis' ); 74 ``` 75 76 #### incrkurtosis() 77 78 Returns an accumulator `function` which incrementally computes a [corrected sample excess kurtosis][sample-excess-kurtosis]. 79 80 ```javascript 81 var accumulator = incrkurtosis(); 82 ``` 83 84 #### accumulator( \[x] ) 85 86 If provided an input value `x`, the accumulator function returns an updated [corrected sample excess kurtosis][sample-excess-kurtosis]. If not provided an input value `x`, the accumulator function returns the current [corrected sample excess kurtosis][sample-excess-kurtosis]. 87 88 ```javascript 89 var accumulator = incrkurtosis(); 90 91 var kurtosis = accumulator( 2.0 ); 92 // returns null 93 94 kurtosis = accumulator( 2.0 ); 95 // returns null 96 97 kurtosis = accumulator( -4.0 ); 98 // returns null 99 100 kurtosis = accumulator( -4.0 ); 101 // returns -6.0 102 ``` 103 104 </section> 105 106 <!-- /.usage --> 107 108 <section class="notes"> 109 110 ## Notes 111 112 - 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. 113 114 </section> 115 116 <!-- /.notes --> 117 118 <section class="examples"> 119 120 ## Examples 121 122 <!-- eslint no-undef: "error" --> 123 124 ```javascript 125 var randu = require( '@stdlib/random/base/randu' ); 126 var incrkurtosis = require( '@stdlib/stats/incr/kurtosis' ); 127 128 var accumulator; 129 var v; 130 var i; 131 132 // Initialize an accumulator: 133 accumulator = incrkurtosis(); 134 135 // For each simulated datum, update the corrected sample excess kurtosis... 136 for ( i = 0; i < 100; i++ ) { 137 v = randu() * 100.0; 138 accumulator( v ); 139 } 140 console.log( accumulator() ); 141 ``` 142 143 </section> 144 145 <!-- /.examples --> 146 147 * * * 148 149 <section class="references"> 150 151 ## References 152 153 - 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]. 154 155 </section> 156 157 <!-- /.references --> 158 159 <section class="links"> 160 161 [sample-excess-kurtosis]: https://en.wikipedia.org/wiki/Kurtosis 162 163 [@joanes:1998]: http://onlinelibrary.wiley.com/doi/10.1111/1467-9884.00122/ 164 165 </section> 166 167 <!-- /.links -->