Published
Edited
Mar 5, 2020
1 fork
Importers
17 stars
Linear regression with confidence bands
Histogram with fitted normal distribution
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more