@stdlib/stats
Version:
Standard library statistical functions.
159 lines (97 loc) • 4.08 kB
Markdown
<!--
@license Apache-2.0
Copyright (c) 2018 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.
-->
# Standard Deviation
> [Uniform][uniform-distribution] distribution [standard deviation][standard-deviation].
<!-- 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 [standard deviation][standard-deviation] for a [uniform][uniform-distribution] random variable is
<!-- <equation class="equation" label="eq:uniform_stdev" align="center" raw="\sigma = \sqrt{\tfrac{1}{12}} \left( b - a \right)" alt="Standard deviation for a uniform distribution."> -->
<div class="equation" align="center" data-raw-text="\sigma = \sqrt{\tfrac{1}{12}} \left( b - a \right)" data-equation="eq:uniform_stdev">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/uniform/stdev/docs/img/equation_uniform_stdev.svg" alt="Standard deviation for a uniform distribution.">
<br>
</div>
<!-- </equation> -->
where `a` is the minimum support and `b` the maximum support of the distribution.
</section>
<!-- /.intro -->
<!-- Package usage documentation. -->
<section class="usage">
## Usage
```javascript
var stdev = require( '@stdlib/stats/base/dists/uniform/stdev' );
```
#### stdev( a, b )
Returns the [standard deviation][standard-deviation] of a [uniform][uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
```javascript
var v = stdev( 0.0, 1.0 );
// returns ~0.289
v = stdev( 4.0, 12.0 );
// returns ~2.309
v = stdev( 2.0, 8.0 );
// returns ~1.732
```
If provided `NaN` as any argument, the function returns `NaN`.
```javascript
var v = stdev( NaN, 2.0 );
// returns NaN
v = stdev( 2.0, NaN );
// returns NaN
```
If provided `a >= b`, the function returns `NaN`.
```javascript
var y = stdev( 3.0, 2.0 );
// returns NaN
y = stdev( 3.0, 3.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 randu = require( '@stdlib/random/base/randu' );
var stdev = require( '@stdlib/stats/base/dists/uniform/stdev' );
var a;
var b;
var v;
var i;
for ( i = 0; i < 10; i++ ) {
a = ( randu()*10.0 );
b = ( randu()*10.0 ) + a;
v = stdev( a, b );
console.log( 'a: %d, b: %d, SD(X;a,b): %d', a.toFixed( 4 ), b.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">
[uniform-distribution]: https://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29
[standard-deviation]: https://en.wikipedia.org/wiki/Standard_deviation
</section>
<!-- /.links -->