Public
Edited
Jan 31, 2024
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pfn = un.map((_, n) => n / 101 / 50)
Insert cell
pfn[49]
Insert cell
_.sum(pfn)
Insert cell
Insert cell
p2r = pfn.map((pn, n) => pn * (Math.floor(n - 1) / 99))
Insert cell
Plot.lineY(p2r).plot({
x: {
label: "n"
},
y: {
label: "P(red|red)"
}
})
Insert cell
Insert cell
_.sum(p2r)
Insert cell
Insert cell
un = d3.range(0, 101)
Insert cell
function fillUrn(n) {
const acc = Array(100).fill("green");

for (let i = 0; i < n; i++) {
acc[i] = "red";
}

return _.shuffle(acc);
}
Insert cell
Insert cell
urn = fillUrn(37)
Insert cell
_.countBy(urn, (d) => d)
Insert cell
urn2 = [...urn]
Insert cell
ball = urn2.pop()
Insert cell
_.countBy(urn2, (d) => d)
Insert cell
Insert cell
mutable secondRedsGivenFirstRed = 0
Insert cell
mutable firstReds = 0
Insert cell
{
for (let i = 0; i < 10000; ++i) {
const n = _.sample(un);
const urn = fillUrn(n);

const firstBall = urn.pop(); // pull a ball out of the urn

if (firstBall === "red") {
mutable firstReds += 1;

const secondBall = urn.pop(); // pull another ball out of the urn

if (secondBall === "red") {
mutable secondRedsGivenFirstRed += 1;
}
}
}
}
Insert cell
P(\text{second red} | \text{first red}) = ${(secondRedsGivenFirstRed / firstReds).toFixed(2)}
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