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
var incrnanskewness = require( '@stdlib/stats/incr/nanskewness' );Returns an accumulator function which incrementally computes a corrected sample skewness, ignoring NaN values.
var accumulator = incrnanskewness();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.492- 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.
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() );