Published
Edited
Apr 16, 2021
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
zParts = {
const data = []
for (let i = 0; i < generations.length - 1; ++i) {
const { dz, dz_selection, dz_transmission } = pricesEquationParts(generations[i], generations[i + 1]);
data.push({ gen: i, value: dz, type: "all" });
data.push({ gen: i, value: dz_selection, type: "selection" });
data.push({ gen: i, value: dz_transmission, type: "transmission" });
}
return data;
}
Insert cell
Insert cell
Insert cell
pricesEquationParts = (p_start, p_final) => {
const q0 = calcFractionBlueEyed(p_start);
const q1 = 1 - q0;
const qp0 = calcFractionBlueEyed(p_final);
const qp1 = 1 - qp0;
const dq0 = qp0 - q0;
const dq1 = qp1 - q1;

const z0 = q0 * z_blue; // Mean z_blue value in start population
const z1 = q1 * z_brown; // 0
const zp0 = qp0 * z_blue;
const zp1 = qp1 * z_brown; // 0

const dz0 = zp0 - z0;
const dz1 = zp1 - z1; // 0

const dz_selection = dq0 * z0 + dq1 * z1;
const dz_transmission = qp0 * dz0 + qp1 * dz1;
const dz = dz_selection + dz_transmission;
return { dz, dz_selection, dz_transmission }
}
Insert cell
calcFractionBlueEyed = (pop) => {
let numBlueEyed = pop.reduce((tot, [first, second]) => tot + (first === 0 && second === 0), 0)
return numBlueEyed / N
}
Insert cell
calcFractionBlueAlleles = (pop) => {
let numBrownAlleles = pop.reduce((tot, [first, second]) => tot + first + second, 0)

return (2 * N - numBrownAlleles) / (2 * N)
}
Insert cell
Insert cell
randWithReplacement = () => [Math.floor(random() * N), Math.floor(random() * N)]
Insert cell
Insert cell
random = {
const seed = 0.5; // any number in [0, 1)
return d3.randomUniform.source(d3.randomLcg(seed))(0, 1);
}
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