Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
calculate-correlation
Advanced tools
Changelog
[1.2.3] - 2022-03-01
Readme
A simple node package that calculates the Pearson correlation coefficient of two arrays. No dependencies needed.
As with any other node package:
npm install calculate-correlation
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.
The function also accepts a third optional argument, a config object. More info about it below.
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
console.log(typeof correlation); // logs number
Example with config options:
// 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 config = {
string: true,
decimals: 5,
};
const correlation = calculateCorrelation(x, y, config);
console.log(correlation); // logs -0.44281
console.log(typeof correlation); // logs string
If the input is correct, the default result will be a Number
between 1 and -1, rounded up to 9 decimal positions.
The function accepts an object as the third argument. This object can setup two options:
Option | Type | Default | Description |
---|---|---|---|
string | Boolean | false | Return the result as a String . |
decimals | Number | 9 | The maximum number of decimals to round the result to. |
As of now, the formula used by the package to calculate correlation is the one for samples.
Some kind of possible roadmap:
FAQs
Calculates the correlation coefficient of two arrays. Simple, with no dependencies
The npm package calculate-correlation receives a total of 320 weekly downloads. As such, calculate-correlation popularity was classified as not popular.
We found that calculate-correlation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.