Published
Edited
Mar 5, 2020
1 fork
Importers
17 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
bins = d3.histogram()
.domain(x.domain())
.thresholds(d3.range(...x.domain(), bin_width))(sample)
Insert cell
Insert cell
function dnorm_standard(x) {
return 1 / Math.sqrt(2 * Math.PI) * Math.exp(-0.5 * Math.pow(x, 2));
}
Insert cell
Insert cell
function dnorm(x, mean = 0, sd = 1) {
return 1 / sd * dnorm_standard((x - mean) / sd)
}
Insert cell
Insert cell
function mean(values) {
return values.reduce((sum, value) => sum += value) / values.length;
}
Insert cell
Insert cell
function ssd(sample) {
// total sum of squares
const sst = sample
.map(x => Math.pow(x - sample_mean, 2))
.reduce((sum, value) => sum += value);
return Math.sqrt(1 / (sample.length - 1) * sst);
}
Insert cell
Insert cell
normal_curve = {
const points = [];
for (let value of d3.range(...x.domain(), bin_width / 10)) {
points.push([value, dnorm(value, sample_mean, sample_sd) * bin_width * sample_size])
}
return points;
}
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
Insert cell
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