skewness.js (1509B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var isnan = require( '@stdlib/math/base/assert/is-nan' ); 24 var pow = require( '@stdlib/math/base/special/pow' ); 25 var SQRT_PI = require( '@stdlib/constants/float64/sqrt-pi' ); 26 var PI = require( '@stdlib/constants/float64/pi' ); 27 28 29 // VARIABLES // 30 31 var SKEWNESS = 2.0 * SQRT_PI * ( PI-3.0 ) / pow( 4.0-PI, 1.5 ); 32 33 34 // MAIN // 35 36 /** 37 * Returns the skewness of a Rayleigh distribution. 38 * 39 * @param {NonNegativeNumber} sigma - scale parameter 40 * @returns {NonNegativeNumber} skewness 41 * 42 * @example 43 * var v = skewness( 9.0 ); 44 * // returns ~0.631 45 * 46 * @example 47 * var v = skewness( 2.0 ); 48 * // returns ~0.631 49 * 50 * @example 51 * var v = skewness( -0.2 ); 52 * // returns NaN 53 * 54 * @example 55 * var v = skewness( NaN ); 56 * // returns NaN 57 */ 58 function skewness( sigma ) { 59 if ( isnan( sigma ) || sigma < 0.0 ) { 60 return NaN; 61 } 62 return SKEWNESS; 63 } 64 65 66 // EXPORTS // 67 68 module.exports = skewness;