@stdlib/stats-incr-nanskewness
v0.1.1
Published
Compute a corrected sample skewness incrementally, ignoring NaN values.
Readme
incrnanskewness
Compute a corrected sample skewness incrementally, ignoring
NaNvalues.
The skewness for a random variable X is defined as
For a sample of n values, the sample skewness is
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
Installation
npm install @stdlib/stats-incr-nanskewnessUsage
var incrnanskewness = require( '@stdlib/stats-incr-nanskewness' );incrnanskewness()
Returns an accumulator function which incrementally computes a corrected sample skewness, ignoring NaN values.
var accumulator = incrnanskewness();accumulator( [x] )
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 = incrnanskewness();
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( NaN );
// returns ~0.492
skewness = accumulator();
// returns ~0.492Notes
- Input values are not type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly before passing the value to the accumulator function.
Examples
var uniform = require( '@stdlib/random-base-uniform' );
var bernoulli = require( '@stdlib/random-base-bernoulli' );
var incrnanskewness = require( '@stdlib/stats-incr-nanskewness' );
// Initialize an accumulator:
var accumulator = incrnanskewness();
// For each simulated datum, update the corrected sample skewness...
var i;
for ( i = 0; i < 100; i++ ) {
accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ) );
}
console.log( accumulator() );Notice
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.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
