Published
Edited
Nov 6, 2020
Importers
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
expected = (kind, want) => ofKind.get(kind) * ofWant.get(want) / data.length
Insert cell
Insert cell
Insert cell
scaledError = (kind, want) => {
let expect = expected(kind, want)
return Math.pow(count.get(kind).get(want) - expect, 2) / expect
}
Insert cell
chiSq =
d3.sum(kinds.map(function(kind) {
return d3.sum(wants.map(function(want) {
return scaledError(kind, want)
}))
}))
Insert cell
Insert cell
Insert cell
Insert cell
chisqrprob(dof, chiSq)
Insert cell
d3 = require('d3@v6', 'd3-array@2')
Insert cell
// From statistics-distributions.js
// https://code.google.com/archive/p/statistics-distributions-js/
// via
// https://gist.github.com/yujiosaka/f94380bcb4b56780355c

chisqrprob = function chisqrprob ($n,$x) {
if (($n <= 0) || ((Math.abs($n) - (Math.abs(Math.floor($n)))) != 0)) {
throw("Invalid n: $n\n"); /* degree of freedom */
}
return _subchisqrprob($n-0, $x-0);
}
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