{"id":20805842,"url":"https://github.com/rubenvar/calculate-correlation","last_synced_at":"2025-05-07T04:23:25.630Z","repository":{"id":49641717,"uuid":"259956077","full_name":"rubenvar/calculate-correlation","owner":"rubenvar","description":"A package that calculates correlation between two arrays. Simple, with no dependencies","archived":false,"fork":false,"pushed_at":"2024-06-16T11:33:22.000Z","size":158,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-21T05:19:49.193Z","etag":null,"topics":["arrays","correlation","correlation-coefficient","javascript","math","npm","pearson-correlation","statistics"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/calculate-correlation","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubenvar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-29T14:54:33.000Z","updated_at":"2024-02-02T14:54:24.000Z","dependencies_parsed_at":"2023-01-24T10:31:55.216Z","dependency_job_id":null,"html_url":"https://github.com/rubenvar/calculate-correlation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenvar%2Fcalculate-correlation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenvar%2Fcalculate-correlation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenvar%2Fcalculate-correlation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenvar%2Fcalculate-correlation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubenvar","download_url":"https://codeload.github.com/rubenvar/calculate-correlation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252811230,"owners_count":21807910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrays","correlation","correlation-coefficient","javascript","math","npm","pearson-correlation","statistics"],"created_at":"2024-11-17T19:16:42.429Z","updated_at":"2025-05-07T04:23:25.605Z","avatar_url":"https://github.com/rubenvar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calculate Correlation\n\n## What is this\n\nA simple node package that calculates the [Pearson correlation coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient) of two arrays. No dependencies needed.\n\n## Installation\n\nAs with any other node package:\n\n```bash\nnpm install calculate-correlation\n```\n\n## Usage\n\nThe package exports a function.\n\nThe function takes **two required arguments**: two arrays of numbers, with equal length.\n\nAnd the function returns the correlation coefficient of the two arrays of numbers.\n\nThe function also accepts a third optional argument, a config object. More info about it below.\n\n### Examples\n\nUse it as follows:\n\n```js\n// import the fn\nconst calculateCorrelation = require(\"calculate-correlation\");\n\n// given 4 points: (2,3), (5,3), (4,6) and (1,7)\nconst x = [2, 5, 4, 1];\nconst y = [3, 3, 6, 7];\n\nconst correlation = calculateCorrelation(x, y);\n\nconsole.log(correlation); // logs -0.442807443\nconsole.log(typeof correlation); // logs number\n```\n\nExample with config options:\n\n```js\n// import the fn\nconst calculateCorrelation = require(\"calculate-correlation\");\n\n// given 4 points: (2,3), (5,3), (4,6) and (1,7)\nconst x = [2, 5, 4, 1];\nconst y = [3, 3, 6, 7];\nconst config = {\n  string: true,\n  decimals: 5,\n};\n\nconst correlation = calculateCorrelation(x, y, config);\n\nconsole.log(correlation); // logs -0.44281\nconsole.log(typeof correlation); // logs string\n```\n\n### Be careful\n\n- Passing less than 2 or more than three arguments will return an error.\n- Passing two arrays with non-numerical values in them will return an error.\n- Passign two arrays with different length will also return an error.\n\nIf the input is correct, the default result will be a `Number` between 1 and -1, rounded up to 9 decimal positions.\n\n### Config options\n\nThe function accepts an object as the third argument. This object can setup two options:\n\n| Option   | Type    | Default | Description                                            |\n| -------- | ------- | ------- | ------------------------------------------------------ |\n| string   | Boolean | false   | Return the result as a `String`.                       |\n| decimals | Number  | 9       | The maximum number of decimals to round the result to. |\n\n### More details\n\nAs of now, the formula used by the package to calculate correlation is the one for **samples**.\n\n## Future\n\nSome kind of possible roadmap:\n\n- [x] Limit result number to _n_ decimal positions.\n- [x] Add a config option to specify the decimal positions in result.\n- [x] Add a config option to specify if the result is preferred as string or number.\n- [ ] Add a config option to calculate correlation of a **population** instead of a sample.\n- [ ] Throw different error messages depending on what was the problem with the input.\n- [ ] Return other statistic values like _average_, _standard deviation_, _variance_, _covariance_, etc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubenvar%2Fcalculate-correlation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubenvar%2Fcalculate-correlation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubenvar%2Fcalculate-correlation/lists"}