# compute-variance

3.0.0 • Public • Published

# Variance

Computes the variance.

The population variance (biased sample variance) is defined as and the unbiased sample variance is defined as where `x_0, x_1,...,x_{N-1}` are individual data values and `N` is the total number of values in the data set.

## Installation

For use in the browser, use browserify.

## Usage

### variance( x[, opts] )

Computes the variance. `x` may be either an `array`, `typed array`, or `matrix`.

For non-numeric `arrays`, provide an accessor `function` for accessing numeric `array` values.

By default, the function calculates the unbiased sample variance. To calculate the population variance (or a biased sample variance), set the `bias` option to `true`.

If provided a `matrix`, the function accepts the following additional `options`:

• dim: dimension along which to compute the variance. Default: `2` (along the columns).
• dtype: output `matrix` data type. Default: `float64`.

By default, the function computes the variance along the columns (`dim=2`).

To compute the variance along the rows, set the `dim` option to `1`.

By default, the output `matrix` data type is `float64`. To specify a different output data type, set the `dtype` option.

If provided a `matrix` having either dimension equal to `1`, the function treats the `matrix` as a `typed array` and returns a `numeric` value.

If provided an empty `array`, `typed array`, or `matrix`, the function returns `null`.

## Examples

To run the example code from the top-level application directory,

## Tests

### Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

All new feature development should have corresponding unit tests to validate correct functionality.

### Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

Istanbul creates a `./reports/coverage` directory. To access an HTML version of the report,

## Package Sidebar

### Install

`npm i compute-variance`

### Repository

github.com/compute-io/variance

137

3.0.0