Skip to content

feat: add stats/base/dists/bradford/skewness #6401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
138 changes: 138 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dists/bradford/skewness/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<!--

@license Apache-2.0

Copyright (c) 2025 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Skewness

> [Bradford][bradford-distribution] distribution [skewness][skewness].

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

The [skewness][skewness] for a [Bradford][bradford-distribution] random variable with shape parameter.`c` is

<!-- <equation class="equation" label="eq:bradford_skewness" align="center" raw="\operatorname{skew}\left( c \right) = \frac{\sqrt{2}\,\Bigl(12c^2 - 9c\,\log(1+c)(c+2) +2\,(\log(1+c))^2\,(c(c+3)+3)\Bigr)}{\sqrt{c\,\Bigl(c\,(\log(1+c)-2)+2\log(1+c)\Bigr)}\Bigl(3c\,(\log(1+c)-2)+6\log(1+c)\Bigr)}" alt="Skewness for a bradford distribution."> -->

```math
\mathop{\mathrm{skew}}\left( c \right) = \frac{\sqrt{2}\,\Bigl(12c^2 - 9c\,\log(1+c)(c+2) + 2\,(\log(1+c))^2\,(c(c+3)+3)\Bigr)}{\sqrt{c\,\Bigl(c\,(\log(1+c)-2)+2\log(1+c)\Bigr)}\Bigl(3c\,(\log(1+c)-2)+6\log(1+c)\Bigr)}
```

<!-- </equation> -->

where `c` is the shape parameter.

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var skewness = require( '@stdlib/stats/base/dists/bradford/skewness' );
```

#### skewness( c )

Returns the [skewness][skewness] of a [Bradford][bradford-distribution] distribution with degrees of freedom `c`.

```javascript
var v = skewness( 9.0 );
// returns ~0.772

v = skewness( 0.5 );
// returns ~0.140
```

If provided `c <= 0`, the function returns `NaN`.

```javascript
var v = skewness( -1.0 );
// returns NaN
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var skewness = require( '@stdlib/stats/base/dists/bradford/skewness' );
var uniform = require( '@stdlib/random/array/uniform' );

var c = uniform( 10, 0.1, 10.0 );

var v;
var i;
for ( i = 0; i < 10; i++ ) {
v = skewness( c[ i ] );
console.log( 'c: %d, Skew(X;c): %d', c[ i ].toFixed( 4 ), v.toFixed( 4 ) );
}
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law

[skewness]: https://en.wikipedia.org/wiki/Skewness

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;
var skewness = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var c;
var y;
var i;

len = 100;
c = uniform( 100, EPS, 20.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = skewness( c[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{{alias}}( c )
Returns the skewness of a Bradford distribution.

If provided `NaN` as any argument, the function returns `NaN`.

If provided `c <= 0`, the function returns `NaN`.

Parameters
----------
c: number
Shape Parameter.

Returns
-------
out: number
Skewness.

Examples
--------
> var v = {{alias}}( 11.0 )
~0.829
> v = {{alias}}( 1.5 )
~0.316

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/**
* Returns the skewness of a Bradford distribution.
*
* ## Notes
*
* - If provided `c <= 0`, the function returns `NaN`.
*
* @param c - shape parameter
* @returns skewness
*
* @example
* var v = skewness( 9.0 );
* // returns ~0.772
*
* @example
* var v = skewness( 1.0 );
* // returns ~0.239
*
* @example
* var v = skewness( -0.2 );
* // returns NaN
*
* @example
* var v = skewness( NaN );
* // returns NaN
*/
declare function skewness( c: number ): number;


// EXPORTS //

export = skewness;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import skewness = require( './index' );


// TESTS //

// The function returns a number...
{
skewness( 9.0 ); // $ExpectType number
}

// The compiler throws an error if the function is provided a value other than a number...
{
skewness( true ); // $ExpectError
skewness( false ); // $ExpectError
skewness( null ); // $ExpectError
skewness( undefined ); // $ExpectError
skewness( '5' ); // $ExpectError
skewness( [] ); // $ExpectError
skewness( {} ); // $ExpectError
skewness( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided insufficient arguments...
{
skewness(); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var uniform = require( '@stdlib/random/array/uniform' );
var skewness = require( './../lib' );

var c = uniform( 10, 0.1, 10.0 );

var v;
var i;
for ( i = 0; i < 10; i++ ) {
v = skewness( c[ i ] );
console.log( 'c: %d, Skew(X;c): %d', c[ i ].toFixed( 4 ), v.toFixed( 4 ) );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* Bradford distribution skewness.
*
* @module @stdlib/stats/base/dists/bradford/skewness
*
* @example
* var skewness = require( '@stdlib/stats/base/dists/bradford/skewness' );
*
* var v = skewness( 11.0 );
* // returns ~0.829
*
* v = skewness( 1.5 );
* // returns ~0.316
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading
Loading