Public
Edited
Oct 25, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
withnoise = Array.from({ length: range }).reduce((acc, v, i, arr) => {
const random = Math.random();
let value = 0;
if (random < outliers) value = 5000;
else if (random < outliers + work) value = 2000;
else if (random < outliers + work + sleep) value = 200;
else value = 0;

if (i != 0 && Math.random() > 0.5) value = acc[i - 1].prob;
acc.push({ prob: value, value: value + Math.random() * 20 });
return acc;
}, [])
Insert cell
Array.from({ length: range }).map(function () {
return [...arguments];
})
Insert cell
Plot.plot({
width,
marks: [
Plot.ruleY([0]),
Plot.lineY(withnoise, { opacity: 0.1, y: "value" }),
Plot.ruleY(
[
{ label: "rms", value: rms },
{ label: "mean", value: mean },
{ label: "root mean", value: rootMean },
{ label: "harmonic mean", value: harmonicMean }
],
{ stroke: "label", y: "value" }
)
],
color: { type: "categorical", legend: true }
})
Insert cell
Plot.plot({
marks: [
Plot.rectY(withnoise, Plot.binX({ y: "count" }, { x: "value" })),
Plot.ruleY([0])
]
})
Insert cell
Plot.plot({
marks: [
Plot.linearRegressionY(withnoise, { y: "value" }),
Plot.lineY(withnoise, { opacity: 0.1, y: "value" })
]
})
Insert cell
rms = Math.sqrt(d3.mean(withnoise, (d) => d.value ** 2))
Insert cell
mean = d3.mean(withnoise, d=> d.value)
Insert cell
rootMean = d3.mean(withnoise, (d) => Math.sqrt(d.value)) ** 2
Insert cell
harmonicMean = withnoise.length / d3.sum(withnoise, (d) => 1 / d.value)
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