Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The jStat npm package is a JavaScript statistical library that provides a wide range of statistical functions and utilities. It is designed to perform various statistical operations such as probability distributions, descriptive statistics, hypothesis testing, and linear regression.
Descriptive Statistics
This feature allows you to calculate basic descriptive statistics such as mean, median, and variance for a given dataset.
const jStat = require('jstat');
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const mean = jStat.mean(data);
const median = jStat.median(data);
const variance = jStat.variance(data);
console.log(`Mean: ${mean}, Median: ${median}, Variance: ${variance}`);
Probability Distributions
This feature provides functions to work with various probability distributions, including normal, binomial, and Poisson distributions. You can calculate the probability density function (PDF) and cumulative distribution function (CDF) for these distributions.
const jStat = require('jstat');
const normalDist = jStat.normal(0, 1);
const pdf = normalDist.pdf(0);
const cdf = normalDist.cdf(0);
console.log(`PDF at 0: ${pdf}, CDF at 0: ${cdf}`);
Hypothesis Testing
This feature allows you to perform various hypothesis tests, such as t-tests, to determine if there are significant differences between datasets.
const jStat = require('jstat');
const sample1 = [1, 2, 3, 4, 5];
const sample2 = [2, 3, 4, 5, 6];
const tTest = jStat.ttest(sample1, sample2, 2);
console.log(`T-test result: ${tTest}`);
Linear Regression
This feature provides tools for performing linear regression analysis, allowing you to model the relationship between dependent and independent variables.
const jStat = require('jstat');
const x = [1, 2, 3, 4, 5];
const y = [2, 3, 5, 7, 11];
const slope = jStat.models.ols(y, x).beta[1];
const intercept = jStat.models.ols(y, x).beta[0];
console.log(`Slope: ${slope}, Intercept: ${intercept}`);
The simple-statistics package provides a wide range of statistical functions similar to jStat, including descriptive statistics, probability distributions, and regression analysis. It is known for its simplicity and ease of use.
The mathjs package is a comprehensive mathematics library that includes statistical functions among many other mathematical utilities. It offers a broader range of mathematical operations compared to jStat, making it suitable for more general mathematical computations.
The mljs package is a machine learning library for JavaScript that includes statistical functions as part of its toolkit. It provides more advanced machine learning algorithms and data processing capabilities compared to jStat.
jStat provides native javascript implementations of statistical functions. Full details are available in the docs. jStat provides more functions than most libraries, including the weibull, cauchy, poisson, hypergeometric, and beta distributions. For most distributions, jStat provides the pdf, cdf, inverse, mean, mode, variance, and a sample function, allowing for more complex calculations.
NOTICE: The previous case sensitive jStat
module will no longer be
updated. Instead use the all lowercase jstat
when doing an npm install
or
similar.
jStat can be used in the browser. The jStat
object will be added to the
window. For example:
<script src="components/jstat.js"></script> <!-- include jStat, from the CDN or otherwise -->
<script>
...
var jstat = this.jStat(dataset); // jStat will be added to the window
...
data[i]['cum'] = jstat.normal(jstat.mean(), jstat.stdev()).cdf(data[i].x);
...
</script>
The library is hosted on jsDelivr using the following url:
//cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js
Note that 'latest'
can be replaced with any released verion of jStat.
Currently jStat is exposed as j$
and jStat
inside an object, rather than
exported directly. This may confuse some module loaders, however should be
easily remedied with the correct configuration.
To install via npm:
npm install --save jstat
When loading under Node be sure to reference the child object.
var { jStat } = require('jstat').
For RequireJS not only exports
but also init
function must be specified.
requirejs.config({
paths: {
'jstat': 'path/to/jstat/dist/jstat.min'
},
shim: {
jstat: {
exports: ['j$', 'jStat'],
init: function () {
return {
j$: j$,
jStat: jStat
};
}
}
}
});
In order to build jStat, you need to have GNU make 3.8 or later, Node.js 0.2 or later, and git 1.7 or later. (Earlier versions might work OK, but are not tested.)
Windows users have two options:
Mac OS users should install Xcode (comes on your Mac OS install DVD, or downloadable from
Apple's Xcode site) and
http://mxcl.github.com/homebrew/. Once Homebrew is installed, run brew install git
to install git,
and brew install node
to install Node.js.
Linux/BSD users should use their appropriate package managers to install make, git, and node, or build from source if you swing that way.
First, clone a copy of the jStat git repo by running git clone git://github.com/jstat/jstat.git
.
To download all necessary libraries run npm install
.
Then, to get a complete, minified version of jStat and all documentation,
simply cd
to the jstat
directory and type make
. If you don't have Node
installed and/or want to make a basic, uncompressed, unlinted version of jstat,
use make jstat
instead of make
.
The built version of jStat will be put in the dist/
subdirectory.
Generate just the documentation by running make doc
. Documentation will be
placed in dist/docs
by default.
To remove all built files, run make clean
.
Execute all tests by running make test
.
Or if you wish to run a specific test, cd
to test/<subdir>
and run node <some_test>-test.js
.
Both the minified and unminified source are located in the dist/
directory.
For those who don't want to build it themselves.
jStat is now going to follow most of the v8 JavaScript guidelines. There will be plenty of source that uses the old style, but we're going to work away from that.
Also, we'll be going through and reimplementing a good portion of the code to run faster. Hopefully it won't take too long to get the project on one basic standard.
When submitting pull requests, no need to check in dist/*.js
. They'll be
recompiled for distribution anyway.
We always like discussion of how to improve jStat. Join us at our mailing list and let us know what you'd like to see. Also come ask questions in the #jstat channel on irc.freenode.net.
FAQs
Statistical Library for JavaScript
The npm package jstat receives a total of 167,326 weekly downloads. As such, jstat popularity was classified as popular.
We found that jstat 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.