Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var ln = require( '@stdlib/math/base/special/ln' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var variance = require( '@stdlib/stats/base/dists/bradford/variance' );


// MAIN //
Expand Down Expand Up @@ -58,12 +57,7 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' );
* // returns NaN
*/
function stdev( c ) {
var k;
if ( isnan( c ) || c <= 0.0 ) {
return NaN;
}
k = ln( 1.0 + c );
return sqrt( ( ( ( 2.0+c ) * k ) - ( 2.0*c ) ) / ( 2.0*c*k*k ) );
return sqrt( variance( c ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/ln",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/bradford/variance"
]
},
{
Expand All @@ -56,9 +55,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/ln",
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/bradford/variance",
"@stdlib/constants/float64/eps"
]
},
Expand All @@ -74,9 +72,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/ln",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/bradford/variance"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
*/

#include "stdlib/stats/base/dists/bradford/stdev.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/ln.h"
#include "stdlib/math/base/special/sqrt.h"
#include "stdlib/stats/base/dists/bradford/variance.h"

/**
* Returns the standard deviation of a Bradford distribution.
Expand All @@ -32,10 +31,5 @@
* // returns ~0.288
*/
double stdlib_base_dists_bradford_stdev( const double c ) {
double k;
if ( stdlib_base_is_nan( c ) || c <= 0.0 ) {
return 0.0/0.0; // NaN
}
k = stdlib_base_ln( 1.0 + c );
return stdlib_base_sqrt( ( ( ( 2.0+c ) * k ) - ( 2.0*c ) ) / ( 2.0*c*k*k ) );
return stdlib_base_sqrt( stdlib_base_dists_bradford_variance( c ) );
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var variance = require( '@stdlib/stats/base/dists/chisquare/variance' );


// MAIN //
Expand Down Expand Up @@ -49,10 +49,7 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' );
* // returns NaN
*/
function stdev( k ) {
if ( isnan( k ) || k < 0.0 ) {
return NaN;
}
return sqrt( 2.0 * k );
return sqrt( variance( k ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/chisquare/variance"
]
},
{
Expand All @@ -55,8 +55,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/chisquare/variance",
"@stdlib/constants/float64/eps"
]
},
Expand All @@ -72,8 +72,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/chisquare/variance"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

#include "stdlib/stats/base/dists/chisquare/stdev.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/sqrt.h"
#include "stdlib/stats/base/dists/chisquare/variance.h"

/**
* Returns the standard deviation of a chi-squared distribution.
Expand All @@ -31,8 +31,5 @@
* // returns ~4.243
*/
double stdlib_base_dists_chisquare_stdev( const double k ) {
if ( stdlib_base_is_nan( k ) || k < 0.0 ) {
return 0.0/0.0; //NaN
}
return stdlib_base_sqrt( 2.0 * k );
return stdlib_base_sqrt( stdlib_base_dists_chisquare_variance( k ) );
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

// MODULES //

var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var variance = require( '@stdlib/stats/base/dists/hypergeometric/variance' );


// MAIN //
Expand Down Expand Up @@ -72,18 +71,7 @@ var PINF = require( '@stdlib/constants/float64/pinf' );
* // returns NaN
*/
function stdev( N, K, n ) {
if (
!isNonNegativeInteger( N ) ||
!isNonNegativeInteger( K ) ||
!isNonNegativeInteger( n ) ||
N === PINF ||
K === PINF ||
K > N ||
n > N
) {
return NaN;
}
return sqrt( n * ( K/N ) * ( (N-K)/N ) * ( (N-n)/(N-1) ) );
return sqrt( variance( N, K, n ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/ternary",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/hypergeometric/variance"
]
},
{
Expand All @@ -55,6 +56,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/hypergeometric/variance",
"@stdlib/math/base/special/ceil"
]
},
Expand All @@ -71,6 +73,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/hypergeometric/variance",
"@stdlib/math/base/special/ceil"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "stdlib/stats/base/dists/hypergeometric/stdev.h"
#include "stdlib/math/base/special/sqrt.h"
#include "stdlib/stats/base/dists/hypergeometric/variance.h"
#include <stdint.h>

/**
Expand All @@ -33,13 +34,5 @@
* // returns ~0.829
*/
double stdlib_base_dists_hypergeometric_stdev( const int32_t N, const int32_t K, const int32_t n ) {
double variance;
double p;

if ( N < 0 || K < 0 || n < 0 || K > N || n > N ) {
return 0.0/0.0; // NaN
}
p = (double)K / (double)N;
variance = n * p * ( 1.0-p ) * ( (double)(N-n)/(double)(N-1) );
return stdlib_base_sqrt( variance );
return stdlib_base_sqrt( stdlib_base_dists_hypergeometric_variance( N, K, n ) );
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var beta = require( '@stdlib/math/base/special/beta' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var variance = require( '@stdlib/stats/base/dists/kumaraswamy/variance' );


// MAIN //
Expand Down Expand Up @@ -63,19 +62,7 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' );
* // returns NaN
*/
function stdev( a, b ) {
var m1;
var m2;
if (
isnan( a ) ||
a <= 0.0 ||
isnan( b ) ||
b <= 0.0
) {
return NaN;
}
m1 = b * beta( 1.0 + ( 1.0/a ), b );
m2 = b * beta( 1.0 + ( 2.0/a ), b );
return sqrt( m2 - ( m1*m1 ) );
return sqrt( variance( a, b ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/beta",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/kumaraswamy/variance"
]
},
{
Expand All @@ -56,9 +55,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/beta",
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/kumaraswamy/variance",
"@stdlib/constants/float64/eps"
]
},
Expand All @@ -74,9 +72,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/beta",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/stats/base/dists/kumaraswamy/variance"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
*/

#include "stdlib/stats/base/dists/kumaraswamy/stdev.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/beta.h"
#include "stdlib/math/base/special/sqrt.h"
#include "stdlib/stats/base/dists/kumaraswamy/variance.h"

/**
* Returns the standard deviation of a Kumaraswamy's double bounded distribution.
Expand All @@ -33,18 +32,5 @@
* // returns ~0.298
*/
double stdlib_base_dists_kumaraswamy_stdev( const double a, const double b ) {
double m1;
double m2;
if (
stdlib_base_is_nan( a ) ||
a <= 0.0 ||
stdlib_base_is_nan( b ) ||
b <= 0.0
) {
return 0.0/0.0; // NaN
}
m1 = b * stdlib_base_beta( 1.0 + ( 1.0/a ), b );
m2 = b * stdlib_base_beta( 1.0 + ( 2.0/a ), b );
return stdlib_base_sqrt( m2 - ( m1*m1 ) );
return stdlib_base_sqrt( stdlib_base_dists_kumaraswamy_variance( a, b ) );
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var exp = require( '@stdlib/math/base/special/exp' );
var variance = require( '@stdlib/stats/base/dists/lognormal/variance' );


// MAIN //
Expand Down Expand Up @@ -55,16 +54,7 @@ var exp = require( '@stdlib/math/base/special/exp' );
* // returns NaN
*/
function stdev( mu, sigma ) {
var s2;
if (
isnan( mu ) ||
isnan( sigma ) ||
sigma <= 0.0
) {
return NaN;
}
s2 = sigma*sigma;
return sqrt( ( exp( s2 ) - 1.0 ) * exp( ( 2.0*mu ) + s2 ) );
return sqrt( variance( mu, sigma ) );
}


Expand Down
Loading
Loading