npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ranjs

v1.24.5

Published

Library for generating various random variables.

Downloads

15,734

Readme

CircleCI Coverage Status npm Inline docs License JavaScript Style Guide CodeScene Code Health

ranjs

Statistical library for generating various seeded random variates, calculating likelihood functions and testing hypotheses (and much more).

The library includes:

  1. Statistical metrics and tests: a variety of central tendency, dispersion and shape statistics as well as statistical tests.

  2. Probability distributions: more than 130 continuous and discrete distributions (and counting), each tested rigorously for statistical correctness over a variety of parameters. Every distribution comes with the following methods:

    2.1 fast and robust sampler.
    2.2 probability density/mass function.
    2.3 cumulative distribution function.
    2.4 quantile function.
    2.5 survival, hazard and cumulative hazard functions.
    2.6 likelihood and AIC/BIC methods.
    2.7 test method that uses Kolmogorov-Smirnov test for continuous or chi2 tests for discrete distributions.

    Also, every distribution can be individually seeded.

install

browser

Just include the minified version and add

<script type="text/javascript" src="ran.min.js"></script>

The module will be exported under ranjs.

node

npm install ranjs

usage

distributions

const ran = require('ranjs')

// Create a new generator for Skellam distribution with mu1 = 1 and mu2 = 3
const skellam = new ran.dist.Skellam(1, 3)

// Generate 10K variates
let values = skellam.sample(1e4)

// Test if samples indeed follow the specified distribution
console.log(skellam.test(values))
// => { statistics: 14.025360669436635, passed: true }

// Evaluate PMF/CDF ...
for (let k = -10; k <= 10; k++) {
    console.log(k, skellam.pdf(k), skellam.cdf(k))
}
// => -4 0.10963424740027695 0.21542206959904264
//    -3 0.1662284357019246 0.38165050508716936
//    -2 0.20277318483535026 0.5844236896611729
//    ...

// ... or higher level statistical functions
for (let k = -4; k <= 4; k++) {
    console.log(k, skellam.hazard(k), skellam.cHazard(k))
}
// => -4 0.13973659359019766 0.24260937407418487
//    -3 0.26882602325948046 0.4807014556249526
//    -2 0.487932492278074 0.8780890224913454
//    ...


// Create another distribution and check their AIC
const skellam2 = new ran.dist.Skellam(1.2, 7.5)
console.log(`Skellam(1, 3):     ${skellam.aic(values)}`)
// => Skellam(1, 3):     41937.67252974663

console.log(`Skellam(1.2, 7.5): ${skellam2.aic(values)}`)
// => Skellam(1.2, 7.5): 66508.74299363888

demo

A demo observable notebook is available here to play around with the library.

API and documentation

For the full API and documentation, see: https://synesenom.github.io/ran/