Socket
Socket
Sign inDemoInstall

calculate-correlation

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    calculate-correlation

Calculates the correlation coefficient of two arrays. Simple, with no dependencies


Version published
Weekly downloads
328
decreased by-5.75%
Maintainers
1
Install size
12.4 kB
Created
Weekly downloads
 

Changelog

Source

[1.0.1] - 2020-04-30

Changed

  • Rounded (precisely) result to 9 decimal positions.

Readme

Source

Calculate Correlation

What is this

A simple node package that calculates the Pearson correlation coefficient of two arrays. No dependencies needed.

Installation

As with any other node package:

npm install calculate-correlation

Usage

The package exports a function.

The function takes two required arguments: two arrays of numbers, with equal length.

And the function returns the correlation coefficient of the two arrays of numbers.

Example

Use it as follows:

// import the fn
const calculateCorrelation = require("calculate-correlation");

// given 4 points: (2,3), (5,3), (4,6) and (1,7)
const x = [2, 5, 4, 1];
const y = [3, 3, 6, 7];

const correlation = calculateCorrelation(x, y);

console.log(correlation); // logs -0.442807443

Be careful

  • Passing less or more than two arguments will return an error.
  • Passing two arrays with non-numerical values in them will return an error.
  • Passign two arrays with different length will also return an error.

If the input is correct, the result will be a Number between 1 and -1, rounded up to 9 decimal positions.

More details

As of now, the formula used by the package to calculate correlation is the one for samples.

Future

Some kind of possible roadmap:

  • Limit result number to n decimal positions.
  • Add a config option to calculate correlation of a population instead of a sample.
  • Add a config option to specify the decimal positions in result.
  • Add a config option to specify if the result is preferred as string or number.
  • Throw different error messages depending on what was the problem with the input.
  • Return other statistic values like average, standard deviation, variance, covariance, etc.

Keywords

FAQs

Last updated on 30 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc