Statistics toolkit for JavaScript

Overview

statkit

A statistics toolkit for javascript.

Usage

Install using npm:

npm install statkit

Fit a linear regression model using MCMC:

var sk = require("statkit.js");

// log-likelihood for the model y ~ N(m*x + b, 1/t)
function lnlike(theta, x, y) {
  var m = theta[0], b = theta[1], t = theta[2];
  var s = 0.0;
  for (var i = 0; i < x.length; i++) {
    var r = y[i] - (m * x[i] + b);
    s += r*r*t - Math.log(t);
  }
  return -0.5*s;
}

// uniform log-prior for m, b, t
function lnprior(theta) {
  var m = theta[0], b = theta[1], t = theta[2];
  if (0.0 < m && m < 1.0 && 0.0 < b && b < 10.0 && 0.0 < t && t < 100.0) {
    return 0.0;
  }
  return -Infinity;
}

// posterior log-probability function
function lnpost(theta, x, y) {
  var lp = lnprior(theta);
  if (!isFinite(lp)) {
    return -Infinity;
  }
  return lp + lnlike(theta, x, y);
}

var x = [10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5];
var y = [8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68];

var res = sk.metropolis(function(theta) { return lnpost(theta, x, y); },
  [0.5, 3.0, 1.0], 1000000, 0.1, 50000, 100);

console.log('acceptance rate:', res.accepted)
console.log('posteriors (16/50/84 percentiles):')
console.log('m', sk.quantile(res.chain[0], 0.16),
  sk.median(res.chain[0]), sk.quantile(res.chain[0], 0.84))
console.log('b', sk.quantile(res.chain[1], 0.16),
  sk.median(res.chain[1]), sk.quantile(res.chain[1], 0.84))
console.log('t', sk.quantile(res.chain[2], 0.16),
  sk.median(res.chain[2]), sk.quantile(res.chain[2], 0.84))

Calculate a confidence interval for a correlation using the bootstrap method:

var sk = require("statkit");

var lsat = [576, 635, 558, 578, 666, 580, 555,
            661, 651, 605, 653, 575, 545, 572, 594];
var gpa = [3.39, 3.30, 2.81, 3.03, 3.44, 3.07, 3.00,
           3.43, 3.36, 3.13, 3.12, 2.74, 2.76, 2.88, 2.96];

var corr = sk.corr(gpa, lsat);
var ci = sk.bootci(100000, sk.corr, gpa, lsat);

console.log("corr = ", corr, "ci = ", ci);

Perform a linear regression on the first data set in Anscombe's quartet:

var sk = require("statkit");

var x = [10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5];
var y = [8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68];

var A = new Array(x.length*2);
for (var i = 0; i < x.length; ++i) {
  A[2*i] = 1;
  A[2*i + 1] = x[i];
}
var b = sk.lstsq(x.length, 2, A, y);

console.log("intercept = ", b[0], "slope = ", b[1]);

Functions

Credits

(c) 2014 Erik Rigtorp [email protected]. MIT License

You might also like...

Utilities for meta-level interactions with the Prisma toolkit in Node.js.

@prisma-spectrum/reflector Utilities for meta-level interactions with the Prisma toolkit in Node.js. ⚠️ Warning: This is not a formal Prisma product l

Dec 16, 2022

A toolkit to rapidly scaffold out a new tauri-apps project using the framework of their choice.

A toolkit to rapidly scaffold out a new tauri-apps project using the framework of their choice.

create-tauri-app Component Version create-tauri-app About Tauri Tauri is a polyglot and generic system that is very composable and allows engineers to

Jan 4, 2023

Next js boilerplate with redux toolkit, redux persist and axios

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Apr 25, 2022

Command-line toolkit for parsing, compiling, transpiling, optimizing, linking, dataizing, and running EOLANG programs

First, you install npm and Java SE. Then, you install eolang package: $ npm install eolang Then, you write a simple EO program in hello.eo file in th

Nov 17, 2022

Toolkit for development, test and deploy smart-contracts on Waves Enterprise ecosystem.

JS Contract SDK Toolkit for development, test and deploy smart-contracts on Waves Enterprise ecosystem. Quickstart The fastest way to get started with

Dec 15, 2022

Toolkit for building scalable web applications with TypeScript, React, Redux and Apollo-Client

Toolkit for building scalable web applications with TypeScript, React, Redux and Apollo-Client

TsToolbox Toolkit for building scalable web applications with TypeScript, React, Redux and Apollo-Client (inspired by ReKit) ⚠ ⚠ ⚠ Work in Progress ⚠

Apr 14, 2022

The iconic SVG, font, and CSS toolkit

Version 6 Font Awesome is the Internet's icon library and toolkit, used by millions of designers, developers, and content creators. Documentation Lear

Jan 3, 2023

starter kit for interacting with zora api, protocol, and creator toolkit

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Oct 20, 2022

Toolkit for authoring Nuxt Themes.

@nuxt-themes/config Toolkit for authoring Nuxt Themes. Features ✨ Lets you create a theme from any Nuxt project 📦 Handles theme.config.ts file 🎨 Off

Dec 6, 2022
Owner
Erik Rigtorp
Erik Rigtorp
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
simple statistics for node & browser javascript

Simple Statistics A JavaScript implementation of descriptive, regression, and inference statistics. Implemented in literate JavaScript with no depende

simple statistics 2.8k Jan 7, 2023
A tool to get plugin statistics of Obsidian plugin ecosystem.

Obsidian Plugin Stats A tool to get plugin statistics of Obsidian plugin ecosystem. Usage You can use this tool to see the plugins that has hit commun

Ganessh Kumar 27 Dec 25, 2022
My personal profile with dynamic github statistics, coding infos, music status with the spotify API.

Oh, Hello there ?? My name's Mouhcine, A recent bachelor Graduate Security Researcher/Student from ???? . Currently Working on other projects. ?? Soci

Mouhcine 18 Oct 29, 2022
An app to test out your typing speed, save your progress and view statistics against them.

Introduction An app to test out your typing speed, save your progress and view statistics against them. Demo Check out the quick demo here. Getting St

Nithin Kumar B 2 Sep 7, 2022
Statistics plugin for RemNote that will give you some helpful numbers, charts and heatmap for your knowledge base.

RemNote statistics plugin Features This plugin will give you the following statistics: Retention rate Number of cards due in future Type of buttons yo

Henrik 3 Sep 9, 2022
📊🌍 Super small, light, privacy-focused, self-hostable web statistics provider

femtostats Update: It turns out Fathom Lite does everything I wanted to do except custom events for free, so I'm going to stop working on this for now

Ian Langworth ☠ 12 Nov 17, 2022
Amelia is an open-source creative-coding toolkit for modern JavaScript

amelia Amelia is an open-source creative-coding toolkit for modern JavaScript. Amelia is a collection of APIs meant to make it easy to create sketches

null 12 Jun 10, 2022
A Web UI toolkit for creating rapid prototypes, experiments and proof of concept projects.

MinimalComps2 A Web UI tookkit for creating rapid prototypes, experiments and proof of concept projects. The site: https://www.minimalcomps2.com/ Full

Keith Peters 32 Apr 18, 2022