Public
Edited
Mar 1, 2022
1 star
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
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
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
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
function calculateLikelihood(bias, outcome) {
return bias ** outcome * (1 - bias) ** (1 - outcome);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
biases = new Array(25).fill(1 / 25)
Insert cell
Insert cell
biases[0]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function calculateEvidence(biases, outcome) {
return (
biases
.map((prior, i) => {
// derive the bias (how many circles are blue)
// e.g. given [0.25, 0.25, 0.25, 0.25]
// the bias at i == 2 is 2/3 circles are blue
const bias = i / (biases.length - 1);

// given that bias, how likely was the outcome
const likelihood = calculateLikelihood(bias, outcome);

// multiply the prior probability by the new likelihood
// e.g. 0.25 * 2/3
return prior * likelihood;
})

// add these products together to get the overall probability of a blue circle
.reduce(sum)
);
}
Insert cell
innitialEvidence = calculateEvidence(biases, 1)
Insert cell
Insert cell
function calculatePosterior(prior, bias, outcome, evidence) {
const likelihood = calculateLikelihood(bias, outcome);
return (likelihood * prior) / evidence;
}
Insert cell
calculatePosterior(
1 / 25, // the prior odds of this bias being correct
0 / 24, // the bias itself
1, // the outcome, 1 for Blue
0.5 // the evidence
)
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
shuffleArray([1, 2, 3, 4, 5, 6], 7)
Insert cell
Insert cell
Insert cell
// draft WIP
Insert cell
/*
texmd`The above example is a real (if contrived) example of how Bayesian thinking can help someone form accurate beliefs, but the visualisation may mislead you slightly. It makes it look like the hairdresser already knew the exact distribution of the world and Bayes' theorem is just a matter of selecting the right "demographic filter".

What's important to understand is that we can talk about all conditional probabilities this way - not just humans divided by gender and hair length.

Let's take a brief detour to an even more abstract representation of probability to try and get a sense of this.

Earlier I mentioned that a person who thought driving was safe should reconsider their beliefs more if they hear that one-in-three people crash their cars annually than if one-in-one-billion people crash into a zebra.`
*/
Insert cell
// md`## Bayes factors`
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