{"id":42373285,"url":"https://github.com/nikolas-virionis/linear-regression-model","last_synced_at":"2026-01-27T19:58:26.303Z","repository":{"id":44988701,"uuid":"431293224","full_name":"nikolas-virionis/linear-regression-model","owner":"nikolas-virionis","description":"An npm package to make it easier to deal with a handful of values, and try to model them in one of the most used mathematical models, with an R/Numpy-like accuracy algorithm","archived":false,"fork":false,"pushed_at":"2022-07-16T20:21:47.000Z","size":54,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T06:03:45.041Z","etag":null,"topics":["coefficient-of-determination","correlation","dataset","insight","linear","linear-models","linear-regression","pearson-correlation","r-squared","regression"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikolas-virionis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-24T00:09:39.000Z","updated_at":"2022-08-23T01:23:37.000Z","dependencies_parsed_at":"2022-07-19T18:03:38.980Z","dependency_job_id":null,"html_url":"https://github.com/nikolas-virionis/linear-regression-model","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/nikolas-virionis/linear-regression-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolas-virionis%2Flinear-regression-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolas-virionis%2Flinear-regression-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolas-virionis%2Flinear-regression-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolas-virionis%2Flinear-regression-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikolas-virionis","download_url":"https://codeload.github.com/nikolas-virionis/linear-regression-model/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolas-virionis%2Flinear-regression-model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28820349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T18:44:20.126Z","status":"ssl_error","status_checked_at":"2026-01-27T18:44:09.161Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["coefficient-of-determination","correlation","dataset","insight","linear","linear-models","linear-regression","pearson-correlation","r-squared","regression"],"created_at":"2026-01-27T19:58:25.679Z","updated_at":"2026-01-27T19:58:26.298Z","avatar_url":"https://github.com/nikolas-virionis.png","language":"JavaScript","readme":"# linear-regression-model\nAn npm package to make it easier to deal with a handful of values, and try to model them in one of the most used mathematical models, with an R-like accuracy algorithm\u003cbr\u003e\n![npm](https://img.shields.io/npm/v/linear-regression-model)\n![GitHub repo size](https://img.shields.io/github/repo-size/nikolas-virionis/linear-regression-model)\n![GitHub last commit](https://img.shields.io/github/last-commit/nikolas-virionis/linear-regression-model?style=plastic)\n![npm](https://img.shields.io/npm/dy/linear-regression-model?style=plastic)\u003cbr\u003e\n![npm logo](./npmlogo.png)\n\n- [Setup](#setup)\n- [Methods](#methods)\n- [Contribution Rules](#contributing)\n\n## Setup\n\n### Requirements:\n  - Node.js installed\u003cbr\u003e\n The ideal version, to run the package, is LTS(16.13 by the time it is being published),\u003cbr\u003e however,\n older versions shouldn't have any issues, as the package does not use any \u003cbr\u003e other npm packages, or\n fancy, new methods, not supported by older versions\n\n  - Installing the module\u003cbr\u003e\n~~~powershell\nnpm install linear-regression-model\n\n~~~\n  - Importing the module\u003cbr\u003e\n\nFirst, there is the Linear Regression model between two different datasets, in relation to each other\u003cbr\u003e\nWhich will look like something similar to this:\n ~~~ javascript\n import {LinearModel} from 'linear-regression-model'\n // or\n const {LinearModel} = require(\"linear-regression-model\");\n // if it is preferred not to use destructuring, or constants use\n // var LinearModel = require(\"linear-regression-model-model\").LinearModel;\n ~~~\nOr if the use case for this is pending more to the behavior of one single dataset\u003cbr\u003e\novertime, this will be more fitting:\n ~~~ javascript\n import {LinearModelOverTime} from 'linear-regression-model'\n // or\n const {LinearModelOverTime} = require(\"linear-regression-model\");\n // if it is preferred not to use destructuring, or constants use\n // var LinearModel = require(\"linear-regression-model\").LinearModelOverTime;\n ~~~\nAnd to use the Correlation class, it will be some like this:\n~~~ javascript\n import {Correlation} from 'linear-regression-model'\n // or\n const {Correlation} = require(\"linear-regression-model\");\n // if it is preferred not to use destructuring, or constants use\n // var Correlation = require(\"linear-regression-model\").Correlation;\n ~~~\nAlthough if your use case is the overtime behaviour, i would advise the use\u003cbr\u003e\nof the [method](#correlation) in the LinearModelOverTime class\u003cbr\u003e\nBut if you are using the LinearModel class, it is really up to you\n## Instantiate the classes\n ~~~ javascript\n const lm = new LinearModel([1, 2, 3, 2, 3, 4], [3, 4, 5, 4, 5, 6]);\n // mandatory to pass two, same sized, all number, arrays, being the\n // orientation (x, y), being x the independent variable and y the\n // dependent: y changes according to how x changes, basically\n ~~~\n or\n ~~~ javascript\n const lm = new LinearModelOverTime([1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6]);\n // mandatory to pass one, all number, array, being the orientation y, the\n //dependent variable: y changes according to how x changes, the later is\n // generated automatically for a better representation of the behavior overtime\n ~~~\n or\n ~~~ javascript\n  const corr = new Correlation([1, 2, 3, 2, 3, 4], [3, 4, 5, 4, 5, 6]);\n // mandatory to pass two, same sized, all number, arrays, being the\n // orientation (x, y), being x the independent variable and y the\n // dependent: y changes according to how x changes, basically\n ~~~\n Let it be clear, it is necessary to pass all number arrays, with more than 1 value,\u003cbr\u003e\n in order for the algorithm to work properly, it will try to convert all the elements\u003cbr\u003e\n to numbers, but if that is not possible, the code will crash.\n \u003cbr\u003e\n \u003cbr\u003e\n\n\n## Methods\nBoth the classes have similar methods, the biggest difference between the classes being\u003cbr\u003e\nif the X axis dataset is informed or generated, therefore, the method will be showed using\nthe LinearModel class, the use for the LinearModelOverTime class is the exact same though\n\n- Just to make it clear, it is necessary to pass the parameters as said in [instatiating the class](#instantiate-the-classes), above\n## LinearModel and LinearModelOverTime\n- getDataset\n~~~ javascript\n lm.getDataset()\n // returns the dataset Informed in the Y axis\n~~~\n\n- getXAxisValues\n~~~ javascript\n lm.getXAxisValues()\n // returns the dataset in the X axis, informed previously or not\n~~~\n- (static) radsToDegs\n~~~ javascript\n LinearModel.radsToDegs(rad)\n // converts an angle in radians to degrees\n // returns the angle in degrees\n~~~\n- (static) getMean\n~~~ javascript\n LinearModel.getMean(dataset)\n // Utility method to calculate the mean of a dataset\n~~~\n- (static) getMode\n~~~ javascript\n LinearModel.getMode(dataset)\n // Utility method to calculate the mode of a dataset\n~~~\n- (static) getMedian\n~~~ javascript\n LinearModel.getMedian(dataset)\n // Utility method to calculate the median of a dataset\n~~~\n- getDatasetLength\n~~~ javascript\n lm.getDatasetLength()\n // returns the dataset length\n~~~\n- getSumOfDatasetValues\n~~~ javascript\n lm.getSumOfDatasetValues()\n // returns the sum of all the elements in the dataset on y azis\n~~~\n- getSumOfXValues\n~~~ javascript\n lm.getSumOfXValues()\n // returns the sum of all the elements in the dataset on x azis\n~~~\n- getSlope\n~~~ javascript\n lm.getSlope()\n // returns the slope of the equation: the \"m\" on the y = mx + n function\n // which is the tangent of the inclination angle\n~~~\n- getAngleInRadians\n~~~ javascript\n lm.getAngleInRadians()\n // returns the inclination angle in radians, like 3/4 meaning  3/4 rad\n~~~\n- getAngleInDegrees\n~~~ javascript\n lm.getAngleInDegrees()\n // returns the inclination angle in degrees, like 43°,\n // for example 3/4 rad ~~ 43°\n~~~\n- getDatasetBehavior\n~~~ javascript\n lm.getDatasetBehavior()\n // returns the overall macro behaviour of the dataset\n~~~\n- getDatasetBehavioralIntensity\n~~~ javascript\n lm.getDatasetBehavioralIntensity()\n // returns the intensity of the behaviour previously measured\n~~~\n- getLinearCoefficient\n~~~ javascript\n lm.getDatasetBehavioralIntensity()\n // returns the intensity of the behaviour previously measured\n~~~\n- getLinearCoefficient\n~~~ javascript\n lm.getLinearCoefficient()\n // returns the linear coefficient of the equation: the \"n\"\n //on the y = mx + n function\n~~~\n- getCoefficients\n~~~ javascript\n lm.getCoefficients()\n // returns both the linear coefficient and the slope\n //of the equation: the \"m\" and the \"n\" on y = mx + n\n~~~\n- getLinearEquation\n~~~ javascript\n lm.getLinearEquation()\n // returns both the function as a string to be displayed\n // and an actual js function to make predictions, for example\n // function(x): returns Y, using the same method as the dataset\n~~~\n- getR2\n~~~ javascript\n lm.getR2()\n // returns the coefficient of determination(R²) to find\n // the accuracy of the linear regression just calculated\n~~~\n### Correlation\n- getCorrelation\n~~~ javascript\n lm.getCorrelation()\n // returns the correlation between the datasets\n~~~\n- getCorrelationInterpretation\n~~~ javascript\n lm.getCorrelationInterpretation()\n // returns the interpretation of the correlation index\n // between the datasets\n~~~\n\n## Correlation (class)\n- (static) getMean\n~~~ javascript\n Correlation.getMean(dataset)\n // returns the mean of the dataset\n~~~\n- (static) getDifferenceFromMeanAndElements\n~~~ javascript\n Correlation.getDifferenceFromMeanAndElements(dataset)\n // returns the difference between the mean and the elements\n // of the dataset, so can be used to calculate variance\n // or standard deviation, for example\n~~~\n- getCorrelation\n~~~ javascript\n corr.getCorrelation()\n // returns the correlation between the datasets\n~~~\n- getCorrelationWay\n~~~ javascript\n corr.getCorrelationWay()\n // returns the way/sign the two datasets are correlated\n // to each other\n~~~\n- getCorrelationIntensity\n~~~ javascript\n corr.getCorrelationIntensity()\n // returns the intensity of the correlation between the datasets\n~~~\n- getCorrelationInterpretation\n~~~ javascript\n corr.getCorrelationInterpretation()\n // returns the interpretation of the correlation index\n // between the datasets\n~~~\n\n# Contributing\nWell, since this is a really simple package, contributing is always welcome, just as much as creating issues experienced with the package\n\nIn order to better organize this contributions, it would be ideal that all PRs follow the template:\n\n## PR Template\n WHAT: \u003cbr\u003e\n A brief description of the improvements\n \n WHY: \u003cbr\u003e\nA explanation on why those changes were needed, necessary, or at least, why is was on the best interest of the package users\n\nCHANGES: \u003cbr\u003e\nList of changes made, can be the name of the commits made, or a simple changes list\n\n## Commits\nIdeally the commits should make use of the convention of [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) \u003cbr\u003e\nSomething i recommend is the usage of either the [Commitizen](https://github.com/commitizen/cz-cli) terminal extension or the [Commit Message Editor](https://marketplace.visualstudio.com/items?itemName=adam-bender.commit-message-editor) VSCode Extension\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolas-virionis%2Flinear-regression-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikolas-virionis%2Flinear-regression-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolas-virionis%2Flinear-regression-model/lists"}