Skip to content
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
148 changes: 148 additions & 0 deletions lib/node_modules/@stdlib/stats/base/ndarray/dsem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# dsem

> Calculate the [standard error of the mean][standard-error] of a one-dimensional double-precision floating-point ndarray.

<section class="intro">

The [standard error of the mean][standard-error] of a finite size sample of size `n` is given by

<!-- <equation class="equation" label="eq:standard_error_of_the_mean" align="center" raw="\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{n}}" alt="Equation for the standard error of the mean."> -->

```math
\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{n}}
```

<!-- <div class="equation" align="center" data-raw-text="\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{n}}" data-equation="eq:standard_error_of_the_mean">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@227a94a6f2e49efe65e814f2da7bc9b9c2bec9b9/lib/node_modules/@stdlib/stats/strided/dsem/docs/img/equation_standard_error_of_the_mean.svg" alt="Equation for the standard error of the mean.">
<br>
</div> -->

<!-- </equation> -->

where `σ` is the population [standard deviation][standard-deviation].

Often in the analysis of data, the true population [standard deviation][standard-deviation] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. In this scenario, one must use a sample [standard deviation][standard-deviation] to compute an estimate for the [standard error of the mean][standard-error]

<!-- <equation class="equation" label="eq:standard_error_of_the_mean_estimate" align="center" raw="\sigma_{\bar{x}} \approx \frac{s}{\sqrt{n}}" alt="Equation for estimating the standard error of the mean."> -->

```math
\sigma_{\bar{x}} \approx \frac{s}{\sqrt{n}}
```

<!-- <div class="equation" align="center" data-raw-text="\sigma_{\bar{x}} \approx \frac{s}{\sqrt{n}}" data-equation="eq:standard_error_of_the_mean_estimate">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@227a94a6f2e49efe65e814f2da7bc9b9c2bec9b9/lib/node_modules/@stdlib/stats/strided/dsem/docs/img/equation_standard_error_of_the_mean_estimate.svg" alt="Equation for estimating the standard error of the mean.">
<br>
</div> -->

<!-- </equation> -->

where `s` is the sample [standard deviation][standard-deviation].

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var dsem = require( '@stdlib/stats/base/ndarray/dsem' );
```

#### dsem( arrays )

Computes the [standard error of the mean][standard-error] of a one-dimensional double-precision floating-point ndarray.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray = require( '@stdlib/ndarray/ctor' );

var opts = {
'dtype': 'float64'
};

var xbuf = new Float64Array( [ 1.0, -2.0, 2.0 ] );
var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' );

var correction = scalar2ndarray( 1.0, opts );

var v = dsem( [ x, correction ] );
// returns ~1.20185
```

The function accepts the following arguments:

- **arrays**: array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying a degrees of freedom adjustment.

</section>

<!-- /.usage -->

<section class="examples">

## Examples

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var dsem = require( '@stdlib/stats/base/ndarray/dsem' );

var opts = {
'dtype': 'float64'
};

var xbuf = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var x = new ndarray( opts.dtype, xbuf, [ 4 ], [ 2 ], 1, 'row-major' );

var correction = scalar2ndarray( 1.0, opts );

var v = dsem( [ x, correction ] );
// returns 1.25
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. -->

<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">

[standard-error]: https://en.wikipedia.org/wiki/Standard_error

[standard-deviation]: https://en.wikipedia.org/wiki/Standard_deviation

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dsem = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var correction;
var xbuf;
var x;

xbuf = uniform( len, -10.0, 10.0, options );
x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' );
correction = scalar2ndarray( 1.0, options );

return benchmark;

function benchmark( b ) {
var v;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = dsem( [ x, correction ] );
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s::len=%d', pkg, len ), f );
}
}

main();
41 changes: 41 additions & 0 deletions lib/node_modules/@stdlib/stats/base/ndarray/dsem/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

{{alias}}( arrays )
Computes the standard error of the mean of a one-dimensional
double-precision floating-point ndarray.

If provided an empty one-dimensional ndarray, the function returns `NaN`.

Parameters
----------
arrays: ArrayLikeObject<ndarray>
Array-like object containing a one-dimensional input ndarray and a
zero-dimensional ndarray specifying a degrees of freedom adjustment.

Returns
-------
out: number
The standard error of the mean.

Examples
--------
// Create input ndarray:
> var Float64Array = require( '@stdlib/array/float64' );
> var xbuf = new Float64Array( [ 1.0, -2.0, 2.0 ] );
> var dt = 'float64';
> var sh = [ xbuf.length ];
> var st = [ 1 ];
> var oo = 0;
> var ord = 'row-major';
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord );

// Create correction ndarray:
> var opts = { 'dtype': dt };
> var correction = {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts );

// Compute the standard error of the mean:
> {{alias}}( [ x, correction ] )
~1.20185

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 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

/// <reference types="@stdlib/types"/>

import { typedndarray } from '@stdlib/types/ndarray';

/**
* Computes the standard error of the mean of a one-dimensional double-precision floating-point ndarray.
*
* @param arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying a degrees of freedom adjustment
* @returns standard error of the mean
*
* @example
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
* var Float64Array = require( '@stdlib/array/float64' );
*
* var opts = {
* 'dtype': 'float64'
* };
*
* var xbuf = new Float64Array( [ 1.0, -2.0, 2.0 ] );
* var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
* var correction = scalar2ndarray( 1.0, opts );
*
* var v = dsem( [ x, correction ] );
* // returns ~1.20185
*/
declare function dsem<T extends typedndarray<number> = typedndarray<number>>( arrays: [ T, T ] ): number;


// EXPORTS //

export = dsem;
Loading
Loading