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

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