# compute-covariance

> Computes the covariance between one or more numeric arrays.

Latest version **1.0.1** (published 2014-11-29) · 0 weekly downloads

## Install

```sh
npm install compute-covariance
pnpm add compute-covariance
yarn add compute-covariance
bun add compute-covariance
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-11-29 |
| First published | 2014-11-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Athan Reines |
| Maintainers | kgryte |
| Keywords | compute.io, compute, computation, mathematics, math, statistics, stats, variance, covariance, sample, covariance, covariance matrix, cov, var, dispersion, correlation, covary, timeseries, array |

## Links

- npm: https://www.npmjs.com/package/compute-covariance
- Repository: https://github.com/compute-io/covariance
- Issues: https://github.com/compute-io/covariance/issues
- npm.io page: https://npm.io/package/compute-covariance

## Dependencies (1)

- [validate.io-object](https://npm.io/package/validate.io-object.md) ^1.0.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2014-11-29
- 1.0.0 — 2014-11-29
- 0.0.0 — 2014-11-29

## README

Covariance
===
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]

> Computes the [covariance](http://en.wikipedia.org/wiki/Covariance) between one or more numeric arrays.


## Installation

``` bash
$ npm install compute-covariance
```

For use in the browser, use [browserify](https://github.com/substack/node-browserify).


## Usage

To use the module,

``` javascript
var cov = require( 'compute-covariance' );
```

#### cov( arr1[, arr2,...,opts] )

Computes the [covariance](http://en.wikipedia.org/wiki/Covariance) between one or more numeric arrays.

``` javascript
var x = [ 1, 2, 3, 4, 5 ],
	y = [ 5, 4, 3, 2, 1 ];

var mat = cov( x, y );
// returns [[2.5,-2.5],[-2.5,2.5]]
```

Note: for univariate input, the returned [covariance matrix](http://en.wikipedia.org/wiki/Covariance_matrix) contains a single element equal to the [variance](https://github.com/compute-io/variance).

If the number of arrays is dynamic, you may want the flexibility to compute the covariance of an arbitrary `array` collection. To this end, `cov` also accepts an `array` of `arrays`.

``` javascript
var mat = cov( [x,y] );
// returns [[2.5,-2.5],[-2.5,2.5]]
```

By default, each element of the covariance matrix is an *unbiased* covariance estimate. Hence, the covariance matrix is the __sample covariance matrix__. For those cases where you want a biased estimate (i.e., population statistics), set the `bias` option to `true`.

``` javascript
var mat = cov( x, y, {'bias': true});
// returns [[2,-2],[-2,2]]
```


## Examples

``` javascript
var cov = require( 'compute-covariance' );

// Simulate some data...
var N = 100,
	x = new Array( N ),
	y = new Array( N ),
	z = new Array( N );

for ( var i = 0; i < N; i++ ) {
	x[ i ] = Math.round( Math.random()*100 );
	y[ i ] = Math.round( Math.random()*100 );
	z[ i ] = 100 - x[ i ];
}
var mat = cov( x, y, z );
console.log( mat );
```

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

``` bash
$ node ./examples/index.js
```


## Tests

### Unit

Unit tests use the [Mocha](http://mochajs.org) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:

``` bash
$ make test
```

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


### Test Coverage

This repository uses [Istanbul](https://github.com/gotwarlost/istanbul) as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

``` bash
$ make test-cov
```

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

``` bash
$ make view-cov
```


## License

[MIT license](http://opensource.org/licenses/MIT). 


---
## Copyright

Copyright &copy; 2014. Athan Reines.


[npm-image]: http://img.shields.io/npm/v/compute-covariance.svg
[npm-url]: https://npmjs.org/package/compute-covariance

[travis-image]: http://img.shields.io/travis/compute-io/covariance/master.svg
[travis-url]: https://travis-ci.org/compute-io/covariance

[coveralls-image]: https://img.shields.io/coveralls/compute-io/covariance/master.svg
[coveralls-url]: https://coveralls.io/r/compute-io/covariance?branch=master

[dependencies-image]: http://img.shields.io/david/compute-io/covariance.svg
[dependencies-url]: https://david-dm.org/compute-io/covariance

[dev-dependencies-image]: http://img.shields.io/david/dev/compute-io/covariance.svg
[dev-dependencies-url]: https://david-dm.org/dev/compute-io/covariance

[github-issues-image]: http://img.shields.io/github/issues/compute-io/covariance.svg
[github-issues-url]: https://github.com/compute-io/covariance/issues

---
_Source: https://npm.io/package/compute-covariance · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
