Published
Edited
Aug 20, 2019
Importers
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function randomWeibull(alpha, lambda, location = 0.0) {
// reference: https://en.wikipedia.org/wiki/Weibull_distribution
// some guarding against null and force positive values
alpha = alpha == null ? 0 : +alpha;
lambda = lambda == null ? 0 : +lambda;
return function() {
return location + (lambda * Math.pow(-Math.log(Math.random()), (1.0/alpha)));
};
}

Insert cell
Insert cell
// the scale parameter must equal the 63rd percentile value
quantile(Array.from({length: 3000}, randomWeibull(1.5,1.0)), 0.63).toFixed(1) == 1.0
Insert cell
// the scale parameter must equal the 63rd percentile value - test seems unreliable, perhaps test with a range rather than exact shape. Thinking 1.9 to 2.1, but perhaps overkill.
quantile(Array.from({length: 3000}, randomWeibull(1.5,2.0)), 0.63).toFixed(2) > 1.9 && quantile(Array.from({length: 3000}, randomWeibull(1.5,2.0)), 0.63).toFixed(2) < 2.1
Insert cell
// the shape parameter = 1 must equal an Exponential distribution of scale = 1.0
quantile(Array.from({length: 3000}, d3.randomExponential(1.0)), 0.5).toFixed(1) == quantile(Array.from({length: 3000}, randomWeibull(1.0,1.0)), 0.5).toFixed(1)
Insert cell
// test some known percentiles
0.7 == quantile(Array.from({length: 3000}, randomWeibull(1.0,1.0)), 0.5).toFixed(1) // actual expected: 0.69351
Insert cell
// test some known percentiles
1.7 == quantile(Array.from({length: 3000}, randomWeibull(2.0,2.0)), 0.5).toFixed(1) // actual expected: 0.1.6651
Insert cell
md `## Appendix`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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