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

@forecasting/simple-squiggle

v1.3.1

Published

## About

Downloads

2

Readme

Simple Squiggle

About

"Simple Squiggle" is a simple parser that manipulates multiplications and divisions between numbers and lognormal distributions. It uses an extremely restricted subset of Squiggle's syntax, and unlike it, the underlying code is not easily extensible.

It may be useful for testing correctness of limited features of the full Squiggle, or for sanity-checking the validity of some Squiggle models.

Built with

Getting started

Prerequisites

  • npm
  • nodejs

Installation

For command line usage

git clone https://github.com/quantified-uncertainty/simple-squiggle.git
cd simple-squiggle
## npm install

The last line is not necessary, since I'm saving node_packages in the repository.

For use inside another node program

npm install @forecasting/simple-squiggle

Usage

General usage

Consider a squiggle model which only uses lognormals:

initialPrisonPopulation = 1.8M to 2.5M # Data for 2022 prison population has not yet been published, though this estimate is perhaps too wide.
reductionInPrisonPopulation = 0.25 to 0.75
badnessOfPrisonInQALYs = 0.2 to 5 # 80% as good as being alive to 5 times worse than living is good
accelerationInYears = 5 to 50
probabilityOfSuccess = 0.01 to 0.1 # 1% to 10%.
estimateQALYs = leftTruncate(
    initialPrisonPopulation *
    reductionInPrisonPopulation *
    badnessOfPrisonInQALYs *
    accelerationInYears *
    probabilityOfSuccess
    , 0)
cost = 2B to 20B
costEffectivenessPerQALY = leftTruncate(cost / estimateQALYs, 0)
costEffectivenessPerQALY

It can be simplified to the following simple squiggle model:

( 2000000000 to 20000000000 ) / ( (1800000 to 2500000) * (0.25 to 0.75) * (0.2 to 5) * (5 to 50) * (0.01 to 0.1) )

I provide both an exportable library and a command line interface (cli).

Command line interface

After cloning this repository through github (see installation section), the cli can be run with npm run cli, which produces a prompt:

> npm run cli

Model:

After filling in the prompt

> npm run cli

Model: ( 2000000000 to 20000000000 ) / ( (1800000 to 2500000) * (0.25 to 0.75) * (0.2 to 5) * (5 to 50) * (0.01 to 0.1) )

the output looks as follows:

> npm run cli

Model: ( 2000000000 to 20000000000 ) / ( (1800000 to 2500000) * (0.25 to 0.75) * (0.2 to 5) * (5 to 50) * (0.01 to 0.1) )

        = (lognormal(22.57, 0.70)) / ((lognormal(14.57, 0.10)) * (lognormal(-0.84, 0.33)) * (lognormal(0.00, 0.98)) * (lognormal(2.76, 0.70)) * (lognormal(-3.45, 0.70)))
        -> lognormal(22.57, 0.70) / (lognormal(14.57, 0.10) * lognormal(-0.84, 0.33) * lognormal(0.00, 0.98) * lognormal(2.76, 0.70) * lognormal(-3.45, 0.70))
        -> lognormal(22.57, 0.70) / (lognormal(13.73, 0.35) * lognormal(0.00, 0.98) * lognormal(2.76, 0.70) * lognormal(-3.45, 0.70))
        -> lognormal(22.57, 0.70) / (lognormal(13.73, 1.04) * lognormal(2.76, 0.70) * lognormal(-3.45, 0.70))
        -> lognormal(22.57, 0.70) / (lognormal(16.49, 1.25) * lognormal(-3.45, 0.70))
        -> lognormal(22.57, 0.70) / (lognormal(13.04, 1.43))
        -> lognormal(22.57, 0.70) / lognormal(13.04, 1.43)
        -> lognormal(9.53, 1.60)

=> lognormal(9.530291704996749, 1.596443005980748)
   ( => ~996.6270585961881 to ~190271.4039258926 )

----------------------------------------------------

For ease of representation, the intermediary outputs are printed only to two decimal points. But this is just a display decision; the innards of the program work with the full set of decimals.

You can also run tests with npm run test

Exportable library

I also provide an exportable library. After installing it with npm (see installation section), you can call it with:

import { calculator } from "@forecasting/simple-squiggle";

// Helpers
let printer = (_) => null;
let getSimpleSquiggleOutput = (string) => calculator(string, printer);

// Model
let model = "( 2000000000 to 20000000000 ) / ( (1800000 to 2500000) * (0.25 to 0.75) * (0.2 to 5) * (5 to 50) * (0.01 to 0.1) )"
let result = getSimpleSquiggleOutput(model);
console.log(result); /* {
  squiggleString: 'lognormal(-0.3465735902799725, 1.1485521838283161)',
  lognormalParameters: [ -0.3465735902799725, 1.1485521838283161 ],
  shortGuesstimateString: '0.11 to 4.7',
  array90CI: [ 0.10690936969938292, 4.676858552304103 ]
}
*/

Roadmap

I consider this repository to be feature complete. As such, I may tinker with the code which wraps around the core logic, but I don't really intend to add further functionality.

  • [ ] Make wrapper code less hacky
  • [x] Display final lognormal as a 90% confidence interval as well

License

Distributed under the MIT License