Compute a corrected sample skewness incrementally.
APACHE-2.0 License
Compute a corrected sample skewness incrementally.
The skewness for a random variable X
is defined as
\mathop{\mathrm{Skewness}}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^3 \biggr]
For a sample of n
values, the sample skewness is
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}}
where m_3
is the sample third central moment and s
is the sample standard deviation.
An alternative definition for the sample skewness which includes an adjustment factor (and is the implemented definition) is
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}}
npm install @stdlib/stats-incr-skewness
Alternatively,
script
tag without installation and bundlers, use the ES Module available on the esm
branch (see README).deno
branch (see README for usage intructions).umd
branch (see README).The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
var incrskewness = require( '@stdlib/stats-incr-skewness' );
Returns an accumulator function
which incrementally computes a corrected sample skewness.
var accumulator = incrskewness();
If provided an input value x
, the accumulator function returns an updated corrected sample skewness. If not provided an input value x
, the accumulator function returns the current corrected sample skewness.
var accumulator = incrskewness();
var skewness = accumulator();
// returns null
skewness = accumulator( 2.0 );
// returns null
skewness = accumulator( -5.0 );
// returns null
skewness = accumulator( -10.0 );
// returns ~0.492
skewness = accumulator();
// returns ~0.492
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.var randu = require( '@stdlib/random-base-randu' );
var incrskewness = require( '@stdlib/stats-incr-skewness' );
var accumulator;
var v;
var i;
// Initialize an accumulator:
accumulator = incrskewness();
// For each simulated datum, update the corrected sample skewness...
for ( i = 0; i < 100; i++ ) {
v = randu() * 100.0;
accumulator( v );
}
console.log( accumulator() );
@stdlib/stats-incr/kurtosis
: compute a corrected sample excess kurtosis incrementally.
@stdlib/stats-incr/mean
: compute an arithmetic mean incrementally.
@stdlib/stats-incr/stdev
: compute a corrected sample standard deviation incrementally.
@stdlib/stats-incr/summary
: compute a statistical summary incrementally.
@stdlib/stats-incr/variance
: compute an unbiased sample variance incrementally.
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.