Published
Edited
Jul 4, 2020
Insert cell
Insert cell
Insert cell
delayProbabilities = { // derive onset to confirmed delay probabilities from a histogram of delays
let sum = 0;
for (let d of delays) sum += d;
return delays.map(d => d / sum);
}
Insert cell
confirmedDaily = confirmedTotal.map((v, i, arr) => v - (arr[i - 1] || 0)) // daily numbers from totals
Insert cell
onset = {
// convolve confirmed daily case counts with onset delay probabilities
const onset = convolve(confirmedDaily, delayProbabilities.slice().reverse());

// adjust for right-censoring
for (let i = 0, p = 0; i < delayProbabilities.length; i++) {
p += delayProbabilities[i];
onset[onset.length - 1 - i] /= p;
}
// round and align with data for confirmed cases
return onset.slice(delays.length - 1).map(Math.round);
}
Insert cell
convolve = (volume, kernel) => { // equivalent of numpy.convolve in the "full" mode
const out = [];
for (let i = 0; i < volume.length; i++) {
for (let j = 0; j < kernel.length; j++) {
out[i + j] = (out[i + j] || 0) + volume[i] * kernel[j];
}
}
return out;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formatDate = d => d.toLocaleDateString('en-US', {month: 'long', day: 'numeric', year: 'numeric'})
Insert cell
uPlot = (await import('https://unpkg.com/uplot@1.0.8/dist/uPlot.esm.js')).default
Insert cell
html`<link rel='stylesheet' href='https://unpkg.com/uplot@1.0.8/dist/uPlot.min.css' />`
Insert cell
html`<style>
.uplot tr { border: none; }
.uplot .legend { line-height: 1.2; }
.uplot .legend .series > * { padding: 0; }
.uplot .legend .series > th { padding-right: 5px; }
.uplot .over { cursor: crosshair; }
</style>`
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