Published
Edited
Jan 28, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
log10NormalInstance = new Log10NormalHC(logCenter,logStdDev)
Insert cell
Insert cell
// tenpts= rangeN(9).map(x=>data4_2percentiles[x*10-1])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
realMean = {
let a= new Log10NormalHC(logCenter,logStdDev)
return a.mean
}
Insert cell
class Log10NormalHC {
constructor(center=1,log10sigma=1,n=100) {
this.mu = Math.log(10**center); // Math.log is ln, or log with base e
this.sigma = Math.log((10**log10sigma));
this.mean = Math.exp(this.mu+(this.sigma**2)*0.5);
// this.n = n;
// this.min = 1.0;
}
pdf(x) {
const fact=1.0/(x*this.sigma*Math.sqrt(2.0*Math.PI));
return fact*Math.exp(-0.5*((Math.log(x)-this.mu)/this.sigma)**2.0);
}
cdf(x) {
// https://en.wikipedia.org/wiki/Log-normal_distribution for formula
return 0.5 + 0.5 * erf( (Math.log(x) - this.mu) / (2**0.5 * this.sigma) )
}
percentile(p) {
if (p<=0 || p>=1)
return NaN;
// https://en.wikipedia.org/wiki/Log-normal_distribution for formula
return Math.exp(this.mu + this.sigma *Math.sqrt(2)* erfinv(2*p-1));
}
// plot({ xmax = null, xmin=null}={}) {
// var data = [];
// if (xmin==null || xmin<=0)
// xmin=Math.exp(this.mu-4*this.sigma)
// if (xmax==null)
// xmax=Math.exp(this.mu+4*this.sigma)
// let logXmax=Math.log10(xmax);
// let logXmin=Math.log10(xmin);
// const logdx = (logXmax-logXmin)/this.n;
// for (let i=0; i<this.n; i++) {
// const x = 10**(logXmin+logdx*i);
// const y = this.pdf(x)
// data.push( {"x": x, "log10y": Math.log10(y), "y":y} );
// }
// return data;
// }
// sample() { // Using the Box-Muller Transform
// const epsilon = Number.MIN_VALUE;
// const twoPI = 2.0*Math.PI;
// if (this.sigma==0) return this.mu;
// var u1, u2;
// do {
// u1 = Math.random();
// u2 = Math.random();
// } while (u1 <= epsilon);
// var z0 = Math.sqrt(-2.0*Math.log(u1))*Math.cos(twoPI*u2);
// var z1 = Math.sqrt(-2.0*Math.log(u1))*Math.sin(twoPI*u2);
// return Math.max( this.min, Math.exp(this.mu+this.sigma*z0) );
// }
}
Insert cell
import { erf, erfinv, plot as plotBostock} from "@mbostock/error-function"
Insert cell
import {number, slider} from "@severo/inputs-setter"
Insert cell
import { sliderBoxButtons } from "@chonghorizons/slider-with-number-input-box-and-quick-select-buttons"
Insert cell
import {number as numberWithSubmit} from "@jashkenas/inputs"
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
d3 = require("d3@6")

Insert cell
vegalite = require('@observablehq/vega-lite')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more